From acac0684d0eb13792cbb8b9bde6f077642dcc640 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 28 Jul 2009 11:50:57 +0200 Subject: Fix tst_QScriptEngine::nestedEvaluate The 'this' value was not correctly set when evaluating Reviewed-by: Kent Hansen --- src/script/api/qscriptcontext.cpp | 8 +------- src/script/api/qscriptengine.cpp | 17 ++++++++++++++++- src/script/api/qscriptengine_p.h | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp index 8d4fe18..c286a70 100644 --- a/src/script/api/qscriptcontext.cpp +++ b/src/script/api/qscriptcontext.cpp @@ -452,13 +452,7 @@ void QScriptContext::setActivationObject(const QScriptValue &activation) QScriptValue QScriptContext::thisObject() const { Q_D(const QScriptContext); - JSC::JSValue result; - if (d->frame->codeBlock() != 0) { - result = d->frame->thisValue(); - } else { - JSC::Register* thisRegister = d->frame->registers() - JSC::RegisterFile::CallFrameHeaderSize - d->frame->argumentCount(); - result = thisRegister->jsValue(); - } + JSC::JSValue result = d->engine->thisForContext(d->frame); if (!result || result.isNull()) result = d->frame->globalThisValue(); return d->engine->scriptValueFromJSCValue(result); diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index a3686ed..61bf271 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -1152,6 +1152,20 @@ JSC::JSValue QScriptEnginePrivate::toUsableValue(JSC::JSValue value) originalGlobalObjectProxy = new (currentFrame)QScript::OriginalGlobalObjectProxy(scriptObjectStructure, originalGlobalObject()); return originalGlobalObjectProxy; } +/*! + \internal + Return the 'this' value for a given context + The result may be null for the global context +*/ +JSC::JSValue QScriptEnginePrivate::thisForContext(JSC::ExecState *frame) +{ + if (frame->codeBlock() != 0) { + return frame->thisValue(); + } else { + JSC::Register* thisRegister = frame->registers() - JSC::RegisterFile::CallFrameHeaderSize - frame->argumentCount(); + return thisRegister->jsValue(); + } +} void QScriptEnginePrivate::mark() { @@ -2182,7 +2196,8 @@ QScriptValue QScriptEngine::evaluate(const QString &program, const QString &file JSC::ScopeChain scopeChain = JSC::ScopeChain(exec->scopeChain()); JSC::DynamicGlobalObjectScope dynamicGlobalObjectScope(exec, exec->scopeChain()->globalObject()); JSC::Completion comp = JSC::evaluate(exec, scopeChain, - JSC::makeSource(jscProgram, jscFileName, lineNumber)); + JSC::makeSource(jscProgram, jscFileName, lineNumber), + d->thisForContext(exec)); if ((comp.complType() == JSC::Normal) || (comp.complType() == JSC::ReturnValue)) { Q_ASSERT(!exec->hadException()); return d->scriptValueFromJSCValue(comp.value()); diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index c0f5e13..151ddb2 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -117,6 +117,7 @@ public: void setGlobalObject(JSC::JSObject *object); JSC::ExecState *globalExec() const; JSC::JSValue toUsableValue(JSC::JSValue value); + static JSC::JSValue thisForContext(JSC::ExecState *frame); void mark(); bool isCollecting() const; -- cgit v0.12