summaryrefslogtreecommitdiffstats
path: root/src/script/api
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-08-17 07:21:03 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-08-18 19:04:48 (GMT)
commit94958cf9ff173830fbed66cf4b4158c51df1df7c (patch)
treed37e4a7e4dc24f46e48691bd0f71970593d4696b /src/script/api
parent93f017401ce8bb73415f88955e928a90c6759fc0 (diff)
downloadQt-94958cf9ff173830fbed66cf4b4158c51df1df7c.zip
Qt-94958cf9ff173830fbed66cf4b4158c51df1df7c.tar.gz
Qt-94958cf9ff173830fbed66cf4b4158c51df1df7c.tar.bz2
Fix the QScriptContext::argumentsObject and QScriptContext::argument for js functions
On js functions, if the number of arguments is different from the number of expected arguments, they are located in different place in the stackframe. We need to call the JSC functions that take that into account. Test is the backtrace test Reviewed-by: Kent Hansen
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/qscriptcontext.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp
index 229c8ab..118b551 100644
--- a/src/script/api/qscriptcontext.cpp
+++ b/src/script/api/qscriptcontext.cpp
@@ -273,9 +273,8 @@ QScriptValue QScriptContext::argument(int index) const
return QScriptValue();
if (index >= argumentCount())
return QScriptValue(QScriptValue::UndefinedValue);
- JSC::Register* thisRegister = frame->registers() - JSC::RegisterFile::CallFrameHeaderSize - frame->argumentCount();
- ++index; //skip the 'this' object
- return QScript::scriptEngineFromExec(frame)->scriptValueFromJSCValue(thisRegister[index].jsValue());
+ QScriptValue v = argumentsObject().property(index);
+ return v;
}
/*!
@@ -306,15 +305,23 @@ QScriptValue QScriptContext::callee() const
QScriptValue QScriptContext::argumentsObject() const
{
JSC::CallFrame *frame = const_cast<JSC::ExecState*>(QScriptEnginePrivate::frameForContext(this));
- if (frame == frame->lexicalGlobalObject()->globalExec()) {
- //global context doesn't have any argument, return an empty object
+
+ if (frame == frame->lexicalGlobalObject()->globalExec() || frame->callerFrame()->hasHostCallFrameFlag()) {
+ // <global> or <eval> context doesn't have arguments. return an empty object
return QScriptEnginePrivate::get(QScript::scriptEngineFromExec(frame))->newObject();
}
- Q_ASSERT(frame->argumentCount() > 0); //we need at least 'this' otherwise we'll crash later
+
+ //for a js function
+ if (frame->codeBlock() && frame->callee()) {
+ JSC::JSValue result = frame->interpreter()->retrieveArguments(frame, JSC::asFunction(frame->callee()));
+ return QScript::scriptEngineFromExec(frame)->scriptValueFromJSCValue(result);
+ }
+
+ //for a native function
if (!frame->optionalCalleeArguments()) {
+ Q_ASSERT(frame->argumentCount() > 0); //we need at least 'this' otherwise we'll crash later
JSC::Arguments* arguments = new (&frame->globalData())JSC::Arguments(frame, JSC::Arguments::NoParameters);
frame->setCalleeArguments(arguments);
- frame[JSC::RegisterFile::ArgumentsRegister] = arguments;
}
return QScript::scriptEngineFromExec(frame)->scriptValueFromJSCValue(frame->optionalCalleeArguments());
}