diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-07-02 09:42:58 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-07-02 09:42:58 (GMT) |
commit | 0869219f0f58ad93149e416016b0b880d79bae47 (patch) | |
tree | 97089169e826cc38497eada0dfb58144ff0cf840 /src/script/bridge/qscriptqobject.cpp | |
parent | 4518d4d0d8b5842bdc6a7c554b566e0e23e0bf82 (diff) | |
download | Qt-0869219f0f58ad93149e416016b0b880d79bae47.zip Qt-0869219f0f58ad93149e416016b0b880d79bae47.tar.gz Qt-0869219f0f58ad93149e416016b0b880d79bae47.tar.bz2 |
create a new QScriptContext when calling a Qt method
Makes the args, thisObject etc. available if QScriptable is used.
Diffstat (limited to 'src/script/bridge/qscriptqobject.cpp')
-rw-r--r-- | src/script/bridge/qscriptqobject.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp index 0162b63..ae7a75b 100644 --- a/src/script/bridge/qscriptqobject.cpp +++ b/src/script/bridge/qscriptqobject.cpp @@ -19,6 +19,7 @@ #include <QtScript/qscriptable.h> #include "../api/qscriptengine_p.h" #include "../api/qscriptable_p.h" +#include "../api/qscriptcontext_p.h" #include "Error.h" #include "PrototypeFunction.h" @@ -917,11 +918,22 @@ JSC::JSValue QtFunction::call(JSC::ExecState *exec, JSC::JSValue thisValue, const JSC::ClassInfo QtFunction::info = { "QtFunction", 0, 0, 0 }; JSC::JSValue QtFunction_call(JSC::ExecState *exec, JSC::JSObject *callee, - JSC::JSValue thisValue, const JSC::ArgList &args) + JSC::JSValue thisValue, const JSC::ArgList &args) { if (!callee->isObject(&QtFunction::info)) return throwError(exec, JSC::TypeError); - return static_cast<QtFunction*>(callee)->call(exec, thisValue, args); + QtFunction *qfun = static_cast<QtFunction*>(callee); + QScriptEnginePrivate *eng_p = static_cast<QScript::GlobalObject*>(exec->dynamicGlobalObject())->engine; + QScriptContext *previousContext = eng_p->currentContext; + QScriptContextPrivate ctx_p(callee, thisValue, args, + /*calledAsConstructor=*/false, + previousContext, eng_p); + QScriptContext *ctx = QScriptContextPrivate::create(ctx_p); + eng_p->currentContext = ctx; + JSC::JSValue result = qfun->call(exec, thisValue, args); + eng_p->currentContext = previousContext; + delete ctx; + return result; } const JSC::ClassInfo QObjectWrapperObject::info = { "QObject", 0, 0, 0 }; |