summaryrefslogtreecommitdiffstats
path: root/src/script
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-07-28 09:50:57 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-07-28 09:57:08 (GMT)
commitacac0684d0eb13792cbb8b9bde6f077642dcc640 (patch)
treead5272b020b90380b92747fefce7af894559b8ef /src/script
parent9e9f896312edf68584bea5c9b70ec0f1205a11ab (diff)
downloadQt-acac0684d0eb13792cbb8b9bde6f077642dcc640.zip
Qt-acac0684d0eb13792cbb8b9bde6f077642dcc640.tar.gz
Qt-acac0684d0eb13792cbb8b9bde6f077642dcc640.tar.bz2
Fix tst_QScriptEngine::nestedEvaluate
The 'this' value was not correctly set when evaluating Reviewed-by: Kent Hansen
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/qscriptcontext.cpp8
-rw-r--r--src/script/api/qscriptengine.cpp17
-rw-r--r--src/script/api/qscriptengine_p.h1
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;