summaryrefslogtreecommitdiffstats
path: root/src/script/api/qscriptcontext.cpp
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-08-14 12:05:25 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-08-14 12:05:25 (GMT)
commite0a86dc604b87921652b844a5f85889bb6291ed9 (patch)
treeedc084c4e047dfc1724d76adc8bb65ae9ca0be19 /src/script/api/qscriptcontext.cpp
parent61c303e8bab04312c17ad2ee03e9ba3f29a0184b (diff)
downloadQt-e0a86dc604b87921652b844a5f85889bb6291ed9.zip
Qt-e0a86dc604b87921652b844a5f85889bb6291ed9.tar.gz
Qt-e0a86dc604b87921652b844a5f85889bb6291ed9.tar.bz2
make it possible for any script object to serve as activation object
This was possible in the old back-end. In JSC, activation objects have to be instances of JSC::JSVariableObject. So the way we solve it is by having our QScriptActivationObject be able to act as a proxy to any other JSObject.
Diffstat (limited to 'src/script/api/qscriptcontext.cpp')
-rw-r--r--src/script/api/qscriptcontext.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp
index 1b69ac1..4a78f7c 100644
--- a/src/script/api/qscriptcontext.cpp
+++ b/src/script/api/qscriptcontext.cpp
@@ -461,6 +461,13 @@ QScriptValue QScriptContext::activationObject() const
result = new (frame)JSC::JSActivation(frame, body);
}*/
}
+
+ if (result && result->isObject(&QScript::QScriptActivationObject::info)
+ && (static_cast<QScript::QScriptActivationObject*>(result)->delegate() != 0)) {
+ // Return the object that property access is being delegated to
+ result = static_cast<QScript::QScriptActivationObject*>(result)->delegate();
+ }
+
return QScript::scriptEngineFromExec(frame)->scriptValueFromJSCValue(result);
}
@@ -485,15 +492,16 @@ void QScriptContext::setActivationObject(const QScriptValue &activation)
JSC::JSObject *object = JSC::asObject(engine->scriptValueToJSCValue(activation));
if (object == engine->originalGlobalObjectProxy)
object = engine->originalGlobalObject();
- if (!object->isVariableObject()) {
- qWarning("QScriptContext::setActivationObject() failed: not an activation object");
- return;
- }
uint flags = QScriptEnginePrivate::contextFlags(frame);
if ((flags & QScriptEnginePrivate::NativeContext) && !(flags & QScriptEnginePrivate::HasScopeContext)) {
//For native functions, we create a scope node
- frame->setScopeChain(frame->scopeChain()->copy()->push(object));
+ JSC::JSObject *scope = object;
+ if (!scope->isVariableObject()) {
+ // Create a QScriptActivationObject that acts as a proxy
+ scope = new (frame) QScript::QScriptActivationObject(frame, scope);
+ }
+ frame->setScopeChain(frame->scopeChain()->copy()->push(scope));
QScriptEnginePrivate::setContextFlags(frame, flags | QScriptEnginePrivate::HasScopeContext);
return;
}
@@ -502,7 +510,16 @@ void QScriptContext::setActivationObject(const QScriptValue &activation)
JSC::ScopeChainNode *node = frame->scopeChain();
while (node != 0) {
if (node->object && node->object->isVariableObject()) {
- node->object = object;
+ if (!object->isVariableObject()) {
+ if (node->object->isObject(&QScript::QScriptActivationObject::info)) {
+ static_cast<QScript::QScriptActivationObject*>(node->object)->setDelegate(object);
+ } else {
+ // Create a QScriptActivationObject that acts as a proxy
+ node->object = new (frame) QScript::QScriptActivationObject(frame, object);
+ }
+ } else {
+ node->object = object;
+ }
break;
}
node = node->next;