summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2010-05-26 13:11:34 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2010-05-27 08:23:31 (GMT)
commit1f40fe507e6b6c74144cbb998cc91f88f9e33168 (patch)
tree1f244535e9b3dfc5702ec8bf97f03ce64ddf4ce9
parentfb5d338236976690312660bc017a8fe1e199326f (diff)
downloadQt-1f40fe507e6b6c74144cbb998cc91f88f9e33168.zip
Qt-1f40fe507e6b6c74144cbb998cc91f88f9e33168.tar.gz
Qt-1f40fe507e6b6c74144cbb998cc91f88f9e33168.tar.bz2
Ensure that activation object has been created before popping scope of native context
One shouldn't have to call activationObject() or scopeChain() before calling popScope(); the scope chain should always have 2 items (activation and global object) before we start popping anything from the internal chain. Task-number: QTBUG-11020 Reviewed-by: Olivier Goffart
-rw-r--r--src/script/api/qscriptcontext.cpp1
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp45
2 files changed, 46 insertions, 0 deletions
diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp
index 639af80..3f08e74 100644
--- a/src/script/api/qscriptcontext.cpp
+++ b/src/script/api/qscriptcontext.cpp
@@ -742,6 +742,7 @@ void QScriptContext::pushScope(const QScriptValue &object)
*/
QScriptValue QScriptContext::popScope()
{
+ activationObject(); //ensure the creation of the normal scope for native context
JSC::CallFrame *frame = QScriptEnginePrivate::frameForContext(this);
JSC::ScopeChainNode *scope = frame->scopeChain();
Q_ASSERT(scope != 0);
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index 100e195..617c183 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -84,6 +84,7 @@ private slots:
void jsActivationObject();
void qobjectAsActivationObject();
void parentContextCallee_QT2270();
+ void popNativeContextScope();
};
tst_QScriptContext::tst_QScriptContext()
@@ -539,6 +540,50 @@ void tst_QScriptContext::pushAndPopContext()
}
}
+void tst_QScriptContext::popNativeContextScope()
+{
+ QScriptEngine eng;
+ QScriptContext *ctx = eng.pushContext();
+ QVERIFY(ctx->popScope().isObject()); // the activation object
+
+ QCOMPARE(ctx->scopeChain().size(), 1);
+ QVERIFY(ctx->scopeChain().at(0).strictlyEquals(eng.globalObject()));
+ // This was different in 4.5: scope and activation were decoupled
+ QVERIFY(ctx->activationObject().strictlyEquals(eng.globalObject()));
+
+ QVERIFY(!eng.evaluate("var foo = 123; function bar() {}").isError());
+ QVERIFY(eng.globalObject().property("foo").isNumber());
+ QVERIFY(eng.globalObject().property("bar").isFunction());
+
+ QScriptValue customScope = eng.newObject();
+ ctx->pushScope(customScope);
+ QCOMPARE(ctx->scopeChain().size(), 2);
+ QVERIFY(ctx->scopeChain().at(0).strictlyEquals(customScope));
+ QVERIFY(ctx->scopeChain().at(1).strictlyEquals(eng.globalObject()));
+ QVERIFY(ctx->activationObject().strictlyEquals(eng.globalObject()));
+ ctx->setActivationObject(customScope);
+ QVERIFY(ctx->activationObject().strictlyEquals(customScope));
+ QCOMPARE(ctx->scopeChain().size(), 2);
+ QVERIFY(ctx->scopeChain().at(0).strictlyEquals(customScope));
+ QEXPECT_FAIL("", "QTBUG-11012", Continue);
+ QVERIFY(ctx->scopeChain().at(1).strictlyEquals(eng.globalObject()));
+
+ QVERIFY(!eng.evaluate("baz = 456; var foo = 789; function barbar() {}").isError());
+ QEXPECT_FAIL("", "QTBUG-11012", Continue);
+ QVERIFY(eng.globalObject().property("baz").isNumber());
+ QVERIFY(customScope.property("foo").isNumber());
+ QVERIFY(customScope.property("barbar").isFunction());
+
+ QVERIFY(ctx->popScope().strictlyEquals(customScope));
+ QCOMPARE(ctx->scopeChain().size(), 1);
+ QEXPECT_FAIL("", "QTBUG-11012", Continue);
+ QVERIFY(ctx->scopeChain().at(0).strictlyEquals(eng.globalObject()));
+
+ // Need to push another object, otherwise we crash in popContext() (QTBUG-11012)
+ ctx->pushScope(customScope);
+ eng.popContext();
+}
+
void tst_QScriptContext::lineNumber()
{
QScriptEngine eng;