diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-08-05 09:26:32 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-08-05 09:27:50 (GMT) |
commit | f22c8da7c2c98cb25642c255c4b4f05fa4e4da3d (patch) | |
tree | 6d782174703c5e223701e67ca34f391fc8605d79 | |
parent | 4a3cf019b7261779ca3e8267278bf07947132db4 (diff) | |
download | Qt-f22c8da7c2c98cb25642c255c4b4f05fa4e4da3d.zip Qt-f22c8da7c2c98cb25642c255c4b4f05fa4e4da3d.tar.gz Qt-f22c8da7c2c98cb25642c255c4b4f05fa4e4da3d.tar.bz2 |
don't store QScriptEngine pointer in native function wrappers
We can infer it from the JSC environment when the function is
actually called.
-rw-r--r-- | src/script/api/qscriptengine.cpp | 6 | ||||
-rw-r--r-- | src/script/bridge/qscriptfunction.cpp | 34 | ||||
-rw-r--r-- | src/script/bridge/qscriptfunction_p.h | 20 |
3 files changed, 31 insertions, 29 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 9fba7cb..02a5e2d 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -1512,7 +1512,7 @@ QScriptValue QScriptEngine::newFunction(QScriptEngine::FunctionSignature fun, { Q_D(QScriptEngine); JSC::ExecState* exec = d->currentFrame; - JSC::JSValue function = new (exec)QScript::FunctionWrapper(this, length, JSC::Identifier(exec, ""), fun); + JSC::JSValue function = new (exec)QScript::FunctionWrapper(exec, length, JSC::Identifier(exec, ""), fun); QScriptValue result = d->scriptValueFromJSCValue(function); result.setProperty(QLatin1String("prototype"), prototype, QScriptValue::Undeletable); const_cast<QScriptValue&>(prototype) @@ -1838,7 +1838,7 @@ QScriptValue QScriptEngine::newFunction(QScriptEngine::FunctionSignature fun, in { Q_D(QScriptEngine); JSC::ExecState* exec = d->currentFrame; - JSC::JSValue function = new (exec)QScript::FunctionWrapper(this, length, JSC::Identifier(exec, ""), fun); + JSC::JSValue function = new (exec)QScript::FunctionWrapper(exec, length, JSC::Identifier(exec, ""), fun); QScriptValue result = d->scriptValueFromJSCValue(function); QScriptValue proto = newObject(); result.setProperty(QLatin1String("prototype"), proto, QScriptValue::Undeletable); @@ -1855,7 +1855,7 @@ QScriptValue QScriptEngine::newFunction(QScriptEngine::FunctionWithArgSignature { Q_D(QScriptEngine); JSC::ExecState* exec = d->currentFrame; - JSC::JSValue function = new (exec)QScript::FunctionWithArgWrapper(this, /*length=*/0, JSC::Identifier(exec, ""), fun, arg); + JSC::JSValue function = new (exec)QScript::FunctionWithArgWrapper(exec, /*length=*/0, JSC::Identifier(exec, ""), fun, arg); QScriptValue result = d->scriptValueFromJSCValue(function); QScriptValue proto = newObject(); result.setProperty(QLatin1String("prototype"), proto, QScriptValue::Undeletable); diff --git a/src/script/bridge/qscriptfunction.cpp b/src/script/bridge/qscriptfunction.cpp index 04c1abd..5b3de9e 100644 --- a/src/script/bridge/qscriptfunction.cpp +++ b/src/script/bridge/qscriptfunction.cpp @@ -61,12 +61,11 @@ namespace QScript { -FunctionWrapper::FunctionWrapper(QScriptEngine *engine, int length, const JSC::Identifier &name, - QScriptEngine::FunctionSignature function) - : JSC::PrototypeFunction(QScriptEnginePrivate::get(engine)->globalExec(), - length, name, proxyCall), data(new Data()) +FunctionWrapper::FunctionWrapper(JSC::ExecState *exec, int length, const JSC::Identifier &name, + QScriptEngine::FunctionSignature function) + : JSC::PrototypeFunction(exec, length, name, proxyCall), + data(new Data()) { - data->engine = engine; data->function = function; } @@ -85,13 +84,13 @@ JSC::JSValue FunctionWrapper::proxyCall(JSC::ExecState *exec, JSC::JSObject *cal JSC::JSValue thisObject, const JSC::ArgList &args) { FunctionWrapper *self = static_cast<FunctionWrapper*>(callee); - QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(self->data->engine); + QScriptEnginePrivate *eng_p = QScript::scriptEngineFromExec(exec); QScriptContext *ctx = eng_p->contextForFrame(exec); //We might have nested eval inside our function so we should create another scope QScriptPushScopeHelper scope(exec); - QScriptValue result = self->data->function(ctx, self->data->engine); + QScriptValue result = self->data->function(ctx, QScriptEnginePrivate::get(eng_p)); if (!result.isValid()) result = QScriptValue(QScriptValue::UndefinedValue); @@ -102,26 +101,25 @@ JSC::JSObject* FunctionWrapper::proxyConstruct(JSC::ExecState *exec, JSC::JSObje const JSC::ArgList &args) { FunctionWrapper *self = static_cast<FunctionWrapper*>(callee); - QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(self->data->engine); + QScriptEnginePrivate *eng_p = QScript::scriptEngineFromExec(exec); QScriptContext *ctx = eng_p->contextForFrame(exec); //We might have nested eval inside our function so we should create another scope QScriptPushScopeHelper scope(exec, true); QScriptValue defaultObject = ctx->thisObject(); - QScriptValue result = self->data->function(ctx, self->data->engine); + QScriptValue result = self->data->function(ctx, QScriptEnginePrivate::get(eng_p)); if (!result.isObject()) result = defaultObject; return JSC::asObject(eng_p->scriptValueToJSCValue(result)); } -FunctionWithArgWrapper::FunctionWithArgWrapper(QScriptEngine *engine, int length, const JSC::Identifier &name, - QScriptEngine::FunctionWithArgSignature function, void *arg) - : JSC::PrototypeFunction(QScriptEnginePrivate::get(engine)->globalExec(), - length, name, proxyCall), data(new Data()) +FunctionWithArgWrapper::FunctionWithArgWrapper(JSC::ExecState *exec, int length, const JSC::Identifier &name, + QScriptEngine::FunctionWithArgSignature function, void *arg) + : JSC::PrototypeFunction(exec, length, name, proxyCall), + data(new Data()) { - data->engine = engine; data->function = function; data->arg = arg; } @@ -141,12 +139,12 @@ JSC::JSValue FunctionWithArgWrapper::proxyCall(JSC::ExecState *exec, JSC::JSObje JSC::JSValue thisObject, const JSC::ArgList &args) { FunctionWithArgWrapper *self = static_cast<FunctionWithArgWrapper*>(callee); - QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(self->data->engine); + QScriptEnginePrivate *eng_p = QScript::scriptEngineFromExec(exec); //We might have nested eval inside our function so we should create another scope QScriptPushScopeHelper scope(exec); - QScriptValue result = self->data->function(eng_p->contextForFrame(exec), self->data->engine, self->data->arg); + QScriptValue result = self->data->function(eng_p->contextForFrame(exec), QScriptEnginePrivate::get(eng_p), self->data->arg); return eng_p->scriptValueToJSCValue(result); } @@ -155,14 +153,14 @@ JSC::JSObject* FunctionWithArgWrapper::proxyConstruct(JSC::ExecState *exec, JSC: const JSC::ArgList &args) { FunctionWithArgWrapper *self = static_cast<FunctionWithArgWrapper*>(callee); - QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(self->data->engine); + QScriptEnginePrivate *eng_p = QScript::scriptEngineFromExec(exec); QScriptContext *ctx = eng_p->contextForFrame(exec); //We might have nested eval inside our function so we should create another scope QScriptPushScopeHelper scope(exec, true); QScriptValue defaultObject = ctx->thisObject(); - QScriptValue result = self->data->function(ctx, self->data->engine, self->data->arg); + QScriptValue result = self->data->function(ctx, QScriptEnginePrivate::get(eng_p) , self->data->arg); if (!result.isObject()) result = defaultObject; diff --git a/src/script/bridge/qscriptfunction_p.h b/src/script/bridge/qscriptfunction_p.h index 360b40c..4901b72 100644 --- a/src/script/bridge/qscriptfunction_p.h +++ b/src/script/bridge/qscriptfunction_p.h @@ -72,18 +72,20 @@ public: // work around CELL_SIZE limitation struct Data { - QScriptEngine *engine; QScriptEngine::FunctionSignature function; }; - FunctionWrapper(QScriptEngine *, int length, const JSC::Identifier&, QScriptEngine::FunctionSignature); + FunctionWrapper(JSC::ExecState*, int length, const JSC::Identifier&, + QScriptEngine::FunctionSignature); ~FunctionWrapper(); private: virtual JSC::ConstructType getConstructData(JSC::ConstructData&); - static JSC::JSValue JSC_HOST_CALL proxyCall(JSC::ExecState *, JSC::JSObject *, JSC::JSValue, const JSC::ArgList &); - static JSC::JSObject* proxyConstruct(JSC::ExecState *, JSC::JSObject *, const JSC::ArgList &); + static JSC::JSValue JSC_HOST_CALL proxyCall(JSC::ExecState *, JSC::JSObject *, + JSC::JSValue, const JSC::ArgList &); + static JSC::JSObject* proxyConstruct(JSC::ExecState *, JSC::JSObject *, + const JSC::ArgList &); private: Data *data; @@ -95,19 +97,21 @@ public: // work around CELL_SIZE limitation struct Data { - QScriptEngine *engine; QScriptEngine::FunctionWithArgSignature function; void *arg; }; - FunctionWithArgWrapper(QScriptEngine *, int length, const JSC::Identifier&, QScriptEngine::FunctionWithArgSignature, void *); + FunctionWithArgWrapper(JSC::ExecState*, int length, const JSC::Identifier&, + QScriptEngine::FunctionWithArgSignature, void *); ~FunctionWithArgWrapper(); private: virtual JSC::ConstructType getConstructData(JSC::ConstructData&); - static JSC::JSValue JSC_HOST_CALL proxyCall(JSC::ExecState *, JSC::JSObject *, JSC::JSValue , const JSC::ArgList &); - static JSC::JSObject* proxyConstruct(JSC::ExecState *, JSC::JSObject *, const JSC::ArgList &); + static JSC::JSValue JSC_HOST_CALL proxyCall(JSC::ExecState *, JSC::JSObject *, + JSC::JSValue , const JSC::ArgList &); + static JSC::JSObject* proxyConstruct(JSC::ExecState *, JSC::JSObject *, + const JSC::ArgList &); private: Data *data; |