summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qscriptcontext/tst_qscriptcontext.cpp')
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp45
1 files changed, 45 insertions, 0 deletions
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;