From d8cde61540b94e36a759d9d6a5adbb432f3625ea Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 9 Jul 2009 11:40:52 +0200 Subject: make arguments object work for native functions There's an off-by-one issue that we just work around for now. --- .../webkit/JavaScriptCore/runtime/Arguments.h | 2 ++ src/script/api/qscriptcontext.cpp | 2 +- tests/auto/qscriptcontext/tst_qscriptcontext.cpp | 26 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/3rdparty/webkit/JavaScriptCore/runtime/Arguments.h b/src/3rdparty/webkit/JavaScriptCore/runtime/Arguments.h index a3941b6..1f5b600 100644 --- a/src/3rdparty/webkit/JavaScriptCore/runtime/Arguments.h +++ b/src/3rdparty/webkit/JavaScriptCore/runtime/Arguments.h @@ -193,6 +193,8 @@ namespace JSC { extraArguments = d->extraArgumentsFixedBuffer; Register* argv = callFrame->registers() - RegisterFile::CallFrameHeaderSize - numArguments - 1; + if (callFrame->callee() && !callFrame->callee()->isObject(&JSC::JSFunction::info)) + ++argv; // ### off-by-one issue with native functions for (unsigned i = 0; i < numArguments; ++i) extraArguments[i] = argv[i]; diff --git a/src/script/api/qscriptcontext.cpp b/src/script/api/qscriptcontext.cpp index c70b3d4..ed631bf 100644 --- a/src/script/api/qscriptcontext.cpp +++ b/src/script/api/qscriptcontext.cpp @@ -302,7 +302,7 @@ QScriptValue QScriptContext::argument(int index) const return QScriptValue(QScriptValue::UndefinedValue); JSC::Register* thisRegister = d->frame->registers() - JSC::RegisterFile::CallFrameHeaderSize - d->frame->argumentCount(); if (d->frame->codeBlock() == 0) - ++index; + ++index; // ### off-by-one issue with native functions return d->engine->scriptValueFromJSCValue(thisRegister[index].jsValue()); } diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp index 8a64007..3fc60df 100644 --- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp +++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp @@ -209,6 +209,10 @@ void tst_QScriptContext::arguments() QScriptValue replacedLength(&eng, 456); result.setProperty("length", replacedLength); QVERIFY(result.property("length").equals(replacedLength)); + result.setProperty("callee", QScriptValue()); + QVERIFY(!result.property("callee").isValid()); + result.setProperty("length", QScriptValue()); + QVERIFY(!result.property("length").isValid()); } { @@ -231,6 +235,28 @@ void tst_QScriptContext::arguments() QCOMPARE(result.property("2").toBoolean(), true); QCOMPARE(result.property("3").isUndefined(), true); } + + // arguments object returned from script + { + QScriptValue result = eng.evaluate("(function() { return arguments; })(123)"); + QCOMPARE(result.isArray(), false); + QVERIFY(result.isObject()); + QCOMPARE(result.property("length").toUInt32(), quint32(1)); + QCOMPARE(result.property("0").isNumber(), true); + QCOMPARE(result.property("0").toNumber(), 123.0); + } + + { + QScriptValue result = eng.evaluate("(function() { return arguments; })('ciao', null, true, undefined)"); + QCOMPARE(result.isArray(), false); + QCOMPARE(result.property("length").toUInt32(), quint32(4)); + QCOMPARE(result.property("0").isString(), true); + QCOMPARE(result.property("0").toString(), QString("ciao")); + QCOMPARE(result.property("1").isNull(), true); + QCOMPARE(result.property("2").isBoolean(), true); + QCOMPARE(result.property("2").toBoolean(), true); + QCOMPARE(result.property("3").isUndefined(), true); + } } } -- cgit v0.12