diff options
author | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-27 15:16:34 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-27 15:20:40 (GMT) |
commit | a7d03f13fe84e704e243610af73f7b0a8ab5a340 (patch) | |
tree | f5a6ff26f446226af6afcbbf061eabc46ec40988 | |
parent | f41b7967b279609d9d4e1a872c92e753f9aefad3 (diff) | |
download | Qt-a7d03f13fe84e704e243610af73f7b0a8ab5a340.zip Qt-a7d03f13fe84e704e243610af73f7b0a8ab5a340.tar.gz Qt-a7d03f13fe84e704e243610af73f7b0a8ab5a340.tar.bz2 |
Fix tst_QScriptValue::call
We have to set the CallFrame correctly in QScriptEngine::evaluate() in
order to ger the 'arguments' object and all the local stuff working.
The code Assert if dynamicGlobalObject is not set, so set it to the
global object.
Reviewed-by: Kent Hansen
-rw-r--r-- | src/script/api/qscriptengine.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qscriptengine/tst_qscriptengine.cpp | 5 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 3230394..7387078 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -2064,10 +2064,13 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file JSC::UString jscProgram = QScript::qtStringToJSCUString(program); JSC::UString jscFileName = QScript::qtStringToJSCUString(fileName); - JSC::ExecState* exec = d->globalObject->globalExec(); // ### use d->currentFrame + JSC::ExecState* exec = d->currentFrame; exec->clearException(); + if (!exec->globalData().dynamicGlobalObject) + exec->globalData().dynamicGlobalObject = d->globalObject; d->uncaughtException = JSC::JSValue(); - JSC::Completion comp = JSC::evaluate(exec, exec->lexicalGlobalObject()->globalScopeChain(), + JSC::ScopeChain scopeChain = JSC::ScopeChain(exec->scopeChain()); + JSC::Completion comp = JSC::evaluate(exec, scopeChain, JSC::makeSource(jscProgram, jscFileName, lineNumber)); if ((comp.complType() == JSC::Normal) || (comp.complType() == JSC::ReturnValue)) { Q_ASSERT(!exec->hadException()); diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp index ce38575..126a7e0 100644 --- a/tests/auto/qscriptengine/tst_qscriptengine.cpp +++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp @@ -163,7 +163,6 @@ void tst_QScriptEngine::currentContext() QVERIFY(globalCtx->thisObject().strictlyEquals(eng.globalObject())); QEXPECT_FAIL("", "", Continue); QVERIFY(globalCtx->activationObject().strictlyEquals(eng.globalObject())); - QEXPECT_FAIL("", "", Continue); QVERIFY(globalCtx->argumentsObject().isObject()); } @@ -1262,10 +1261,13 @@ void tst_QScriptEngine::evaluate() static QScriptValue eval_nested(QScriptContext *ctx, QScriptEngine *eng) { QScriptValue result = eng->newObject(); + eng->evaluate("var bar = 'local';"); result.setProperty("thisObjectIdBefore", ctx->thisObject().property("id")); QScriptValue evaluatedThisObject = eng->evaluate("this"); result.setProperty("thisObjectIdAfter", ctx->thisObject().property("id")); result.setProperty("evaluatedThisObjectId", evaluatedThisObject.property("id")); + result.setProperty("local_bar", eng->evaluate("bar")); + return result; } @@ -1274,6 +1276,7 @@ void tst_QScriptEngine::nestedEvaluate() QScriptEngine eng; eng.globalObject().setProperty("fun", eng.newFunction(eval_nested)); QScriptValue result = eng.evaluate("o = { id:'foo'}; o.fun = fun; o.fun()"); + QCOMPARE(result.property("local_bar").toString(), QString("local")); QCOMPARE(result.property("thisObjectIdBefore").toString(), QString("foo")); QCOMPARE(result.property("thisObjectIdAfter").toString(), QString("foo")); QCOMPARE(result.property("evaluatedThisObjectId").toString(), QString("foo")); |