diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-09-18 15:46:23 +0200 |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-09-18 16:06:01 +0200 |
commit | d380d3435d413fab28192175da30845ca3351752 (patch) | |
tree | a9c9b15fb3174a248f244257bee81be22143512b /src/script | |
parent | a2e914538f651aab9638512a327a31718a8da53e (diff) |
put the this-register calculation into a function
Avoid copy and paste.
Reviewed-by: Olivier Goffart
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/qscriptcontext.cpp | 2 | ||||
-rw-r--r-- | src/script/api/qscriptengine.cpp | 10 | ||||
-rw-r--r-- | src/script/api/qscriptengine_p.h | 1 |
3 files changed, 10 insertions, 3 deletions
diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp index 2ca6d2662f..199ee66689 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 e39e1d1661..163cf5fc13 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 b36787b9b6..c7db27620d 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); |