Q_OBJECT
public:
Object() {
connect(&timer, SIGNAL(timeout()), this, SLOT(abort()));
engine.setProcessEventsInterval(1000);
fun = engine.evaluate("(function() { while(true); })");
}
void startEval() {
timer.start(1000);
qDebug() << "is callable?" << fun.isFunction();
QScriptContext *context = engine.pushContext();
QScriptValue v = context->activationObject();
v.setProperty("fun", fun);
engine.evaluate("fun()");
engine.popContext();
}
private slots:
void abort() {
bool ev = engine.isEvaluating();
qDebug() << "isEvaluating?" << ev;
qDebug() << "Aborting evaluation";
engine.abortEvaluation();
}
private:
// ...
QScriptValue fun;
//...
};
class Object : public QObject {
Q_OBJECT
public:
Object() {
connect(&timer, SIGNAL(timeout()), this, SLOT(abort()));
engine.setProcessEventsInterval(1000);
fun = engine.evaluate("(function() { while(true); })");
}
void startEval() {
timer.start(1000);
qDebug() << "is callable?" << fun.isFunction();
QScriptContext *context = engine.pushContext();
QScriptValue v = context->activationObject();
v.setProperty("fun", fun);
engine.evaluate("fun()");
engine.popContext();
}
private slots:
void abort() {
bool ev = engine.isEvaluating();
qDebug() << "isEvaluating?" << ev;
qDebug() << "Aborting evaluation";
engine.abortEvaluation();
}
private:
// ...
QScriptValue fun;
//...
};
To copy to clipboard, switch view to plain text mode
This calls the function and aborts it after one second. QScriptValue::call() itself doesn't seem abortable as it is executed using different JavaScriptCore method than evaluate(). If you want more flexibility you can probably make your function the activation object itself, set needed arguments and trigger the context (somehow).
Bookmarks