summaryrefslogtreecommitdiffstats
path: root/tests/auto/qscriptengine
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-07-27 17:42:26 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-07-27 18:01:19 (GMT)
commit8923339fa086cbf6adc404fb18dcda6c1206985d (patch)
tree13ad42fc95c63e9f49a971a42fab7ddb1c6af61c /tests/auto/qscriptengine
parent117802b5ca71478d01bb79f88aa3596729b0a590 (diff)
downloadQt-8923339fa086cbf6adc404fb18dcda6c1206985d.zip
Qt-8923339fa086cbf6adc404fb18dcda6c1206985d.tar.gz
Qt-8923339fa086cbf6adc404fb18dcda6c1206985d.tar.bz2
make QScriptEngine::setGlobalObject() work to some extent
JSC requires that the global object is actually a JSGlobalObject instance, whereas QScriptEngine::setGlobalObject() allows any object to be set as the global object. The way we solve this is by proxying from an internal global object to the custom (user-set) object. We need to take care that the internal global object is never actually exposed through our API; a brilliantly named helper function, toUsableValue(), makes that happen. Evaluating "var a = 10" with a custom global object doesn't work yet; the variable always ends up in the internal Global Object. For variable assignments, JSC appears to bypass the normal JSObject::put() and instead use JSGlobalObject::copyGlobals{From,To}(), which means I can't intercept and proxy the assignments. This commit enough to get the Context2D example working. There's another bug with iteration of the built-in Global Object's properties (non-enumerable properties are always skipped by the JSC C++ API, whereas with QScriptValueIterator they should not be), but that's a totally separate issue.
Diffstat (limited to 'tests/auto/qscriptengine')
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp4
1 files changed, 0 insertions, 4 deletions
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index fed5a4c..d657749 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -896,11 +896,9 @@ void tst_QScriptEngine::getSetGlobalObject()
QScriptValue obj = eng.newObject();
eng.setGlobalObject(obj);
QVERIFY(eng.globalObject().strictlyEquals(obj));
- QEXPECT_FAIL("", "this-object for global context", Continue);
QVERIFY(eng.currentContext()->thisObject().strictlyEquals(obj));
QEXPECT_FAIL("", "this-object for global context", Continue);
QVERIFY(eng.currentContext()->activationObject().strictlyEquals(obj));
- QEXPECT_FAIL("", "", Continue);
QVERIFY(eng.evaluate("this").strictlyEquals(obj));
QCOMPARE(eng.globalObject().toString(), QString::fromLatin1("[object Object]"));
@@ -909,14 +907,12 @@ void tst_QScriptEngine::getSetGlobalObject()
obj = eng.newObject();
eng.setGlobalObject(obj);
QVERIFY(eng.globalObject().strictlyEquals(obj));
- QEXPECT_FAIL("", "", Continue);
QVERIFY(eng.currentContext()->thisObject().strictlyEquals(obj));
QEXPECT_FAIL("", "", Continue);
QVERIFY(eng.currentContext()->activationObject().strictlyEquals(obj));
eng.collectGarbage();
QVERIFY(eng.globalObject().strictlyEquals(obj));
- QEXPECT_FAIL("", "", Continue);
QVERIFY(eng.currentContext()->thisObject().strictlyEquals(obj));
QEXPECT_FAIL("", "", Continue);
QVERIFY(eng.currentContext()->activationObject().strictlyEquals(obj));