diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-07 14:07:44 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-07 14:07:44 (GMT) |
commit | c4c23b83d9ce6635b06fb570c30500c5da014111 (patch) | |
tree | 1fd1c0c9984d9a1e0dc4ae88ef28d1c3ef05053c /src/script/api | |
parent | a97b88c9552f417bb119077ea366f4682a5a878f (diff) | |
download | Qt-c4c23b83d9ce6635b06fb570c30500c5da014111.zip Qt-c4c23b83d9ce6635b06fb570c30500c5da014111.tar.gz Qt-c4c23b83d9ce6635b06fb570c30500c5da014111.tar.bz2 |
work on QScriptEngine::uncaughtException()
It's possible that JSC evaluate() returns a completion of type
Throw without hadException() being true, so we need to store the
exception value explicitly.
Diffstat (limited to 'src/script/api')
-rw-r--r-- | src/script/api/qscriptengine.cpp | 17 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 1 | ||||
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 12 |
3 files changed, 22 insertions, 8 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 9470c00..3d72990 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -632,6 +632,9 @@ void GlobalObject::mark() { JSC::JSGlobalObject::mark(); + if (engine->uncaughtException) + engine->uncaughtException.mark(); + if (engine->qobjectPrototype) engine->qobjectPrototype->mark(); if (engine->qmetaobjectPrototype) @@ -1888,13 +1891,16 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file JSC::ExecState* exec = d->globalObject->globalExec(); exec->clearException(); + d->uncaughtException = JSC::JSValue(); JSC::Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), JSC::makeSource(jscProgram, jscFileName, lineNumber)); if ((comp.complType() == JSC::Normal) || (comp.complType() == JSC::ReturnValue)) { + Q_ASSERT(!exec->hadException()); return d->scriptValueFromJSCValue(comp.value()); } if (comp.complType() == JSC::Throw) { + d->uncaughtException = comp.value(); return d->scriptValueFromJSCValue(comp.value()); } @@ -1982,8 +1988,7 @@ void QScriptEngine::popContext() bool QScriptEngine::hasUncaughtException() const { Q_D(const QScriptEngine); - JSC::ExecState* exec = d->globalObject->globalExec(); - return exec->hadException(); + return !!d->uncaughtException; } /*! @@ -2000,8 +2005,7 @@ bool QScriptEngine::hasUncaughtException() const QScriptValue QScriptEngine::uncaughtException() const { Q_D(const QScriptEngine); - JSC::ExecState* exec = d->globalObject->globalExec(); - return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(exec->exception()); + return const_cast<QScriptEnginePrivate*>(d)->scriptValueFromJSCValue(d->uncaughtException); } /*! @@ -2016,7 +2020,7 @@ int QScriptEngine::uncaughtExceptionLineNumber() const { if (!hasUncaughtException()) return -1; - return uncaughtException().property(QLatin1String("lineNumber")).toInt32(); + return uncaughtException().property(QLatin1String("line")).toInt32(); } /*! @@ -2045,9 +2049,10 @@ QStringList QScriptEngine::uncaughtExceptionBacktrace() const */ void QScriptEngine::clearExceptions() { - Q_D(const QScriptEngine); + Q_D(QScriptEngine); JSC::ExecState* exec = d->globalObject->globalExec(); exec->clearException(); + d->uncaughtException = JSC::JSValue(); } /*! diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index 8b5133b..666aeff 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -141,6 +141,7 @@ public: JSC::JSGlobalObject *globalObject; QScriptContext *currentContext; + JSC::JSValue uncaughtException; QScript::QObjectPrototype *qobjectPrototype; WTF::RefPtr<JSC::Structure> qobjectWrapperObjectStructure; diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index cd29810..bcbc3f7 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -1887,6 +1887,8 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, } else if (callType == JSC::CallTypeHost) { result = callData.native.function(exec, JSC::asObject(callee), jscThisObject, jscArgs); } + if (exec->hadException()) + eng_p->uncaughtException = exec->exception(); return eng_p->scriptValueFromJSCValue(result); } @@ -1964,8 +1966,10 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, } else if (callType == JSC::CallTypeHost) { result = callData.native.function(exec, JSC::asObject(callee), jscThisObject, applyArgs); } - if (exec->hadException()) + if (exec->hadException()) { + eng_p->uncaughtException = exec->exception(); result = exec->exception(); + } return eng_p->scriptValueFromJSCValue(result); } @@ -2014,6 +2018,8 @@ QScriptValue QScriptValue::construct(const QScriptValueList &args) } else if (constructType == JSC::ConstructTypeHost) { result = constructData.native.function(exec, JSC::asObject(callee), jscArgs); } + if (exec->hadException()) + eng_p->uncaughtException = exec->exception(); return eng_p->scriptValueFromJSCValue(result); } @@ -2069,8 +2075,10 @@ QScriptValue QScriptValue::construct(const QScriptValue &arguments) } else if (constructType == JSC::ConstructTypeHost) { result = constructData.native.function(exec, JSC::asObject(callee), applyArgs); } - if (exec->hadException()) + if (exec->hadException()) { + eng_p->uncaughtException = exec->exception(); result = exec->exception(); + } return eng_p->scriptValueFromJSCValue(result); } |