diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-08-19 12:55:16 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-08-19 12:55:16 (GMT) |
commit | 5bca43cca3ac90429e3f9263d0d7ea8c9eb164d4 (patch) | |
tree | 73c64b7cf83a5777d28dc9305390cd579f2c05ed /src/script/api/qscriptengine.cpp | |
parent | 8a9c91c77be0482e5f94f6976a4b5f59a64c4188 (diff) | |
download | Qt-5bca43cca3ac90429e3f9263d0d7ea8c9eb164d4.zip Qt-5bca43cca3ac90429e3f9263d0d7ea8c9eb164d4.tar.gz Qt-5bca43cca3ac90429e3f9263d0d7ea8c9eb164d4.tar.bz2 |
make QScriptEngine::isEvaluating() work for top-level evaluation
Since QScriptEngine::evaluate() doesn't create a new stack frame
anymore, we need to use a dedicated variable to keep track of
whether the engine is currently evaluating or not.
Diffstat (limited to 'src/script/api/qscriptengine.cpp')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 22 |
1 files changed, 20 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; } /*! |