summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/script/api/qscriptengine.cpp22
-rw-r--r--src/script/api/qscriptengine_p.h1
-rw-r--r--tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp24
3 files changed, 45 insertions, 2 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 261efce..5ef07b9 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -788,9 +788,26 @@ static QScriptValue __setupPackage__(QScriptContext *ctx, QScriptEngine *eng)
}
#endif
+// Helper class for stacking a script engine's inEval attribute.
+class InEval
+{
+public:
+ inline InEval(QScriptEnginePrivate *e)
+ : engine(e), was(e->inEval)
+ {
+ e->inEval = true;
+ }
+ inline ~InEval()
+ { engine->inEval = was; }
+private:
+ QScriptEnginePrivate *engine;
+ bool was;
+};
+
} // namespace QScript
-QScriptEnginePrivate::QScriptEnginePrivate() : idGenerator(1)
+QScriptEnginePrivate::QScriptEnginePrivate()
+ : inEval(false), idGenerator(1)
{
qMetaTypeId<QScriptValue>();
@@ -2154,6 +2171,7 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file
Q_D(QScriptEngine);
JSC::JSLock lock(false); // ### hmmm
+ QScript::InEval inEval(d);
currentContext()->activationObject(); //force the creation of a context for native function;
JSC::UString jscProgram = program;
@@ -3501,7 +3519,7 @@ int QScriptEngine::processEventsInterval() const
bool QScriptEngine::isEvaluating() const
{
Q_D(const QScriptEngine);
- return (d->currentFrame != d->globalExec());
+ return (d->currentFrame != d->globalExec()) || d->inEval;
}
/*!
diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h
index 3a5c79d..bc1dc92 100644
--- a/src/script/api/qscriptengine_p.h
+++ b/src/script/api/qscriptengine_p.h
@@ -243,6 +243,7 @@ public:
QHash<int, QScriptTypeInfo*> m_typeInfos;
int processEventsInterval;
QScriptValue abortResult;
+ bool inEval;
QSet<QString> importedExtensions;
QSet<QString> extensionsBeingImported;
diff --git a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
index 0637297..7bfac62 100644
--- a/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
+++ b/tests/auto/qscriptengineagent/tst_qscriptengineagent.cpp
@@ -103,6 +103,7 @@ private slots:
void syntaxError();
void extension_invoctaion();
void extension();
+ void isEvaluatingInExtension();
private:
double m_testProperty;
@@ -2126,5 +2127,28 @@ void tst_QScriptEngineAgent::extension()
delete spy;
}
+class TestIsEvaluatingAgent : public QScriptEngineAgent
+{
+public:
+ TestIsEvaluatingAgent(QScriptEngine *engine)
+ : QScriptEngineAgent(engine), wasEvaluating(false)
+ { engine->setAgent(this); }
+ bool supportsExtension(Extension ext) const
+ { return ext == DebuggerInvocationRequest; }
+ QVariant extension(Extension, const QVariant &)
+ { wasEvaluating = engine()->isEvaluating(); return QVariant(); }
+
+ bool wasEvaluating;
+};
+
+void tst_QScriptEngineAgent::isEvaluatingInExtension()
+{
+ QScriptEngine eng;
+ TestIsEvaluatingAgent *spy = new TestIsEvaluatingAgent(&eng);
+ QVERIFY(!spy->wasEvaluating);
+ eng.evaluate("debugger");
+ QVERIFY(spy->wasEvaluating);
+}
+
QTEST_MAIN(tst_QScriptEngineAgent)
#include "tst_qscriptengineagent.moc"