diff options
-rw-r--r-- | src/script/api/qscriptvalue.cpp | 42 | ||||
-rw-r--r-- | tests/auto/qscriptvalue/tst_qscriptvalue.cpp | 14 |
2 files changed, 40 insertions, 16 deletions
diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 922b068..a9c07a7 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -1928,7 +1928,12 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, const QScriptValueList &args) { Q_D(const QScriptValue); - if (!isFunction()) + if (!d || !d->isJSC()) + return QScriptValue(); + JSC::JSValue callee = d->jscValue; + JSC::CallData callData; + JSC::CallType callType = callee.getCallData(callData); + if (callType == JSC::CallTypeNone) return QScriptValue(); if (thisObject.engine() && (thisObject.engine() != engine())) { @@ -1960,9 +1965,6 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, } JSC::ArgList jscArgs(argsVector.data(), argsVector.size()); - JSC::JSValue callee = d->jscValue; - JSC::CallData callData; - JSC::CallType callType = callee.getCallData(callData); JSC::JSValue savedException; QScriptValuePrivate::saveException(exec, &savedException); JSC::JSValue result = JSC::call(exec, callee, callType, callData, jscThisObject, jscArgs); @@ -2001,7 +2003,12 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, const QScriptValue &arguments) { Q_D(QScriptValue); - if (!isFunction()) + if (!d || !d->isJSC()) + return QScriptValue(); + JSC::JSValue callee = d->jscValue; + JSC::CallData callData; + JSC::CallType callType = callee.getCallData(callData); + if (callType == JSC::CallTypeNone) return QScriptValue(); if (thisObject.engine() && (thisObject.engine() != engine())) { @@ -2038,9 +2045,6 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, } } - JSC::JSValue callee = d->jscValue; - JSC::CallData callData; - JSC::CallType callType = callee.getCallData(callData); JSC::JSValue savedException; QScriptValuePrivate::saveException(exec, &savedException); JSC::JSValue result = JSC::call(exec, callee, callType, callData, jscThisObject, applyArgs); @@ -2073,8 +2077,14 @@ QScriptValue QScriptValue::call(const QScriptValue &thisObject, QScriptValue QScriptValue::construct(const QScriptValueList &args) { Q_D(const QScriptValue); - if (!isFunction()) + if (!d || !d->isJSC()) return QScriptValue(); + JSC::JSValue callee = d->jscValue; + JSC::ConstructData constructData; + JSC::ConstructType constructType = callee.getConstructData(constructData); + if (constructType == JSC::ConstructTypeNone) + return QScriptValue(); + JSC::ExecState *exec = d->engine->currentFrame; QVarLengthArray<JSC::JSValue, 8> argsVector(args.size()); @@ -2087,9 +2097,6 @@ QScriptValue QScriptValue::construct(const QScriptValueList &args) JSC::ArgList jscArgs(argsVector.data(), argsVector.size()); - JSC::JSValue callee = d->jscValue; - JSC::ConstructData constructData; - JSC::ConstructType constructType = callee.getConstructData(constructData); JSC::JSValue savedException; QScriptValuePrivate::saveException(exec, &savedException); JSC::JSObject *result = JSC::construct(exec, callee, constructType, constructData, jscArgs); @@ -2119,8 +2126,14 @@ QScriptValue QScriptValue::construct(const QScriptValueList &args) QScriptValue QScriptValue::construct(const QScriptValue &arguments) { Q_D(QScriptValue); - if (!isFunction()) + if (!d || !d->isJSC()) return QScriptValue(); + JSC::JSValue callee = d->jscValue; + JSC::ConstructData constructData; + JSC::ConstructType constructType = callee.getConstructData(constructData); + if (constructType == JSC::ConstructTypeNone) + return QScriptValue(); + JSC::ExecState *exec = d->engine->currentFrame; JSC::JSValue array = d->engine->scriptValueToJSCValue(arguments); @@ -2143,9 +2156,6 @@ QScriptValue QScriptValue::construct(const QScriptValue &arguments) } } - JSC::JSValue callee = d->jscValue; - JSC::ConstructData constructData; - JSC::ConstructType constructType = callee.getConstructData(constructData); JSC::JSValue savedException; QScriptValuePrivate::saveException(exec, &savedException); JSC::JSObject *result = JSC::construct(exec, callee, constructType, constructData, applyArgs); diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp index 16a9e87..3f231f2 100644 --- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp +++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp @@ -2504,6 +2504,13 @@ void tst_QScriptValue::call() QScriptValue ret5 = fun.call(QScriptValue(), QScriptValue(&eng, 123.0)); QCOMPARE(ret5.isError(), true); } + + // calling things that are not functions + QVERIFY(!QScriptValue(false).call().isValid()); + QVERIFY(!QScriptValue(123).call().isValid()); + QVERIFY(!QScriptValue(QString::fromLatin1("ciao")).call().isValid()); + QVERIFY(!QScriptValue(QScriptValue::UndefinedValue).call().isValid()); + QVERIFY(!QScriptValue(QScriptValue::NullValue).call().isValid()); } static QScriptValue ctorReturningUndefined(QScriptContext *ctx, QScriptEngine *) @@ -2629,6 +2636,13 @@ void tst_QScriptValue::construct() QScriptValue ret5 = fun.construct(QScriptValue(&eng, 123.0)); QCOMPARE(ret5.isError(), true); } + + // construct on things that are not functions + QVERIFY(!QScriptValue(false).construct().isValid()); + QVERIFY(!QScriptValue(123).construct().isValid()); + QVERIFY(!QScriptValue(QString::fromLatin1("ciao")).construct().isValid()); + QVERIFY(!QScriptValue(QScriptValue::UndefinedValue).construct().isValid()); + QVERIFY(!QScriptValue(QScriptValue::NullValue).construct().isValid()); } void tst_QScriptValue::lessThan() |