summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-10-28 10:27:49 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-10-28 11:27:52 (GMT)
commit746f4b50e9c13c720162f3bcc8795b7ef772fbba (patch)
treee2f1bf826d24d97f5879e9c29d66c3ceafe07b8b /src/script
parent7537554040827dbaae327d27c77319e6b7e7c618 (diff)
downloadQt-746f4b50e9c13c720162f3bcc8795b7ef772fbba.zip
Qt-746f4b50e9c13c720162f3bcc8795b7ef772fbba.tar.gz
Qt-746f4b50e9c13c720162f3bcc8795b7ef772fbba.tar.bz2
QScriptValue::construct(): Don't crash if function throws non-Object
If an exception occurs, we should ignore the result of JSC::construct() and return the exception value, even if the exception is not an object. This makes the behavior match the documentation: "Calling construct() can cause an exception to occur in the script engine; in that case, construct() returns the value that was thrown". Task-number: QTBUG-14801 Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/qscriptvalue.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp
index f6390bb..f494106 100644
--- a/src/script/api/qscriptvalue.cpp
+++ b/src/script/api/qscriptvalue.cpp
@@ -1736,10 +1736,12 @@ QScriptValue QScriptValue::construct(const QScriptValueList &args)
JSC::JSValue savedException;
QScriptEnginePrivate::saveException(exec, &savedException);
- JSC::JSObject *result = JSC::construct(exec, callee, constructType, constructData, jscArgs);
+ JSC::JSValue result;
+ JSC::JSObject *newObject = JSC::construct(exec, callee, constructType, constructData, jscArgs);
if (exec->hadException()) {
- result = JSC::asObject(exec->exception());
+ result = exec->exception();
} else {
+ result = newObject;
QScriptEnginePrivate::restoreException(exec, savedException);
}
return d->engine->scriptValueFromJSCValue(result);
@@ -1796,11 +1798,12 @@ QScriptValue QScriptValue::construct(const QScriptValue &arguments)
JSC::JSValue savedException;
QScriptEnginePrivate::saveException(exec, &savedException);
- JSC::JSObject *result = JSC::construct(exec, callee, constructType, constructData, applyArgs);
+ JSC::JSValue result;
+ JSC::JSObject *newObject = JSC::construct(exec, callee, constructType, constructData, applyArgs);
if (exec->hadException()) {
- if (exec->exception().isObject())
- result = JSC::asObject(exec->exception());
+ result = exec->exception();
} else {
+ result = newObject;
QScriptEnginePrivate::restoreException(exec, savedException);
}
return d->engine->scriptValueFromJSCValue(result);