summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-09-18 13:46:23 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-09-18 14:06:01 (GMT)
commitd380d3435d413fab28192175da30845ca3351752 (patch)
treea9c9b15fb3174a248f244257bee81be22143512b /src
parenta2e914538f651aab9638512a327a31718a8da53e (diff)
downloadQt-d380d3435d413fab28192175da30845ca3351752.zip
Qt-d380d3435d413fab28192175da30845ca3351752.tar.gz
Qt-d380d3435d413fab28192175da30845ca3351752.tar.bz2
put the this-register calculation into a function
Avoid copy and paste. Reviewed-by: Olivier Goffart
Diffstat (limited to 'src')
-rw-r--r--src/script/api/qscriptcontext.cpp2
-rw-r--r--src/script/api/qscriptengine.cpp10
-rw-r--r--src/script/api/qscriptengine_p.h1
3 files changed, 10 insertions, 3 deletions
diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp
index 2ca6d26..199ee66 100644
--- a/src/script/api/qscriptcontext.cpp
+++ b/src/script/api/qscriptcontext.cpp
@@ -571,7 +571,7 @@ void QScriptContext::setThisObject(const QScriptValue &thisObject)
if (cb != 0) {
frame[cb->thisRegister()] = jscThisObject;
} else {
- JSC::Register* thisRegister = frame->registers() - JSC::RegisterFile::CallFrameHeaderSize - frame->argumentCount();
+ JSC::Register* thisRegister = QScriptEnginePrivate::thisRegisterForFrame(frame);
thisRegister[0] = jscThisObject;
}
}
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index e39e1d1..163cf5f 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -1077,11 +1077,17 @@ 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();
+ JSC::Register *thisRegister = thisRegisterForFrame(frame);
return thisRegister->jsValue();
}
}
+JSC::Register* QScriptEnginePrivate::thisRegisterForFrame(JSC::ExecState *frame)
+{
+ Q_ASSERT(frame->codeBlock() == 0); // only for native calls
+ return frame->registers() - JSC::RegisterFile::CallFrameHeaderSize - frame->argumentCount();
+}
+
/*! \internal
For native context, we use the ReturnValueRegister entry in the stackframe header to store flags.
We can do that because this header is not used as the native function return their value thought C++
@@ -2306,7 +2312,7 @@ JSC::CallFrame *QScriptEnginePrivate::pushContext(JSC::CallFrame *exec, JSC::JSV
#endif
if (calledAsConstructor) {
//update the new created this
- JSC::Register* thisRegister = newCallFrame->registers() - JSC::RegisterFile::CallFrameHeaderSize - newCallFrame->argumentCount();
+ JSC::Register* thisRegister = thisRegisterForFrame(newCallFrame);
*thisRegister = thisObject;
}
}
diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h
index b36787b..c7db276 100644
--- a/src/script/api/qscriptengine_p.h
+++ b/src/script/api/qscriptengine_p.h
@@ -154,6 +154,7 @@ public:
JSC::ExecState *globalExec() const;
JSC::JSValue toUsableValue(JSC::JSValue value);
static JSC::JSValue thisForContext(JSC::ExecState *frame);
+ static JSC::Register *thisRegisterForFrame(JSC::ExecState *frame);
JSC::CallFrame *pushContext(JSC::CallFrame *exec, JSC::JSValue thisObject, const JSC::ArgList& args,
JSC::JSObject *callee, bool calledAsConstructor = false);