summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptengine_p.h
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 /src/script/api/qscriptengine_p.h
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 'src/script/api/qscriptengine_p.h')
-rw-r--r--src/script/api/qscriptengine_p.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h
index 4db77c0..c0f5e13 100644
--- a/src/script/api/qscriptengine_p.h
+++ b/src/script/api/qscriptengine_p.h
@@ -110,8 +110,13 @@ public:
QScriptContext *contextForFrame(JSC::ExecState *frame);
void releaseContextForFrame(JSC::ExecState *frame);
- JSC::JSGlobalObject *globalObject() const;
+ JSC::JSGlobalObject *originalGlobalObject() const;
+ JSC::JSObject *getOriginalGlobalObjectProxy();
+ JSC::JSObject *customGlobalObject() const;
+ JSC::JSObject *globalObject() const;
+ void setGlobalObject(JSC::JSObject *object);
JSC::ExecState *globalExec() const;
+ JSC::JSValue toUsableValue(JSC::JSValue value);
void mark();
bool isCollecting() const;
@@ -162,7 +167,7 @@ public:
#endif
JSC::JSGlobalData *globalData;
- JSC::JSObject *customGlobalObject;
+ JSC::JSObject *originalGlobalObjectProxy;
JSC::ExecState *currentFrame;
QHash<JSC::ExecState*, QScriptContext*> contextForFrameHash;