Changeset 102709 in webkit


Ignore:
Timestamp:
Dec 13, 2011 3:17:43 PM (12 years ago)
Author:
oliver@apple.com
Message:

Arguments object doesn't handle mutation of length property correctly
https://bugs.webkit.org/show_bug.cgi?id=74454

Reviewed by Gavin Barraclough.

Source/JavaScriptCore:

Correct handling of arguments objects with overridden length property

  • interpreter/Interpreter.cpp:

(JSC::loadVarargs):

  • runtime/Arguments.cpp:

(JSC::Arguments::copyToArguments):
(JSC::Arguments::fillArgList):

LayoutTests:

Add tests of mutated arguments.length

  • fast/js/arguments-expected.txt:
  • fast/js/script-tests/arguments.js:

(argumentLengthIs5):
(duplicateArgumentAndReturnLast_call):
(duplicateArgumentAndReturnFirst_call):
(duplicateArgumentAndReturnLast_apply):
(duplicateArgumentAndReturnFirst_apply):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r102699 r102709  
     12011-12-13  Oliver Hunt  <oliver@apple.com>
     2
     3        Arguments object doesn't handle mutation of length property correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=74454
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        Add tests of mutated arguments.length
     9
     10        * fast/js/arguments-expected.txt:
     11        * fast/js/script-tests/arguments.js:
     12        (argumentLengthIs5):
     13        (duplicateArgumentAndReturnLast_call):
     14        (duplicateArgumentAndReturnFirst_call):
     15        (duplicateArgumentAndReturnLast_apply):
     16        (duplicateArgumentAndReturnFirst_apply):
     17
    1182011-12-13  Vsevolod Vlasov  <vsevik@chromium.org>
    219
  • trunk/LayoutTests/fast/js/arguments-expected.txt

    r97768 r102709  
    1919PASS access_4(1, 2, 3, 4, 5) is 4
    2020PASS access_5(1, 2, 3, 4, 5) is 5
     21PASS argumentLengthIs5() is 5
     22PASS argumentLengthIs5(1,2,3,4,5) is 5
     23PASS argumentLengthIs5(1,2,3,4,5,6,7,8,9,10) is 5
     24PASS duplicateArgumentAndReturnLast_call(1) is 1
     25PASS duplicateArgumentAndReturnFirst_call(1) is 1
     26PASS duplicateArgumentAndReturnLast_apply(1) is 1
     27PASS duplicateArgumentAndReturnFirst_apply(1) is 1
    2128PASS tear_off_equal_access_1(1, 2, 3) is 1
    2229PASS tear_off_equal_access_2(1, 2, 3) is 2
  • trunk/LayoutTests/fast/js/script-tests/arguments.js

    r98407 r102709  
    2626{
    2727    return arguments[4];
     28}
     29
     30function argumentLengthIs5() {
     31    arguments.length = 5;
     32    return arguments.length;
     33}
     34
     35function duplicateArgumentAndReturnLast_call(a) {
     36    Array.prototype.push.call(arguments, a);
     37    return arguments[1];
     38}
     39
     40function duplicateArgumentAndReturnFirst_call(a) {
     41    Array.prototype.push.call(arguments, a);
     42    return arguments[0];
     43}
     44
     45function duplicateArgumentAndReturnLast_apply(a) {
     46    Array.prototype.push.apply(arguments, arguments);
     47    return arguments[1];
     48}
     49
     50function duplicateArgumentAndReturnFirst_apply(a) {
     51    Array.prototype.push.apply(arguments, arguments);
     52    return arguments[0];
    2853}
    2954
     
    4570shouldBe("access_4(1, 2, 3, 4, 5)", "4");
    4671shouldBe("access_5(1, 2, 3, 4, 5)", "5");
     72
     73shouldBe("argumentLengthIs5()", "5");
     74shouldBe("argumentLengthIs5(1,2,3,4,5)", "5");
     75shouldBe("argumentLengthIs5(1,2,3,4,5,6,7,8,9,10)", "5");
     76shouldBe("duplicateArgumentAndReturnLast_call(1)", "1");
     77shouldBe("duplicateArgumentAndReturnFirst_call(1)", "1");
     78shouldBe("duplicateArgumentAndReturnLast_apply(1)", "1");
     79shouldBe("duplicateArgumentAndReturnFirst_apply(1)", "1");
    4780
    4881function f(a, b, c)
  • trunk/Source/JavaScriptCore/ChangeLog

    r102707 r102709  
     12011-12-13  Oliver Hunt  <oliver@apple.com>
     2
     3        Arguments object doesn't handle mutation of length property correctly
     4        https://bugs.webkit.org/show_bug.cgi?id=74454
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        Correct handling of arguments objects with overridden length property
     9
     10        * interpreter/Interpreter.cpp:
     11        (JSC::loadVarargs):
     12        * runtime/Arguments.cpp:
     13        (JSC::Arguments::copyToArguments):
     14        (JSC::Arguments::fillArgList):
     15
    1162011-12-13  Filip Pizlo  <fpizlo@apple.com>
    217
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r102545 r102709  
    496496        Arguments* argsObject = asArguments(arguments);
    497497        unsigned argCount = argsObject->length(callFrame);
    498         CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister + argCount + 1 + RegisterFile::CallFrameHeaderSize);
     498        CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister + CallFrame::offsetFor(argCount + 1));
    499499        if (argCount > Arguments::MaxArguments || !registerFile->grow(newCallFrame->registers())) {
    500500            callFrame->globalData().exception = createStackOverflowError(callFrame);
     
    510510        JSArray* array = asArray(arguments);
    511511        unsigned argCount = array->length();
    512         CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister + argCount + 1 + RegisterFile::CallFrameHeaderSize);
     512        CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister + CallFrame::offsetFor(argCount + 1));
    513513        if (argCount > Arguments::MaxArguments || !registerFile->grow(newCallFrame->registers())) {
    514514            callFrame->globalData().exception = createStackOverflowError(callFrame);
     
    523523    JSObject* argObject = asObject(arguments);
    524524    unsigned argCount = argObject->get(callFrame, callFrame->propertyNames().length).toUInt32(callFrame);
    525     CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister + argCount + 1 + RegisterFile::CallFrameHeaderSize);
     525    CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + firstFreeRegister + CallFrame::offsetFor(argCount + 1));
    526526    if (argCount > Arguments::MaxArguments || !registerFile->grow(newCallFrame->registers())) {
    527527        callFrame->globalData().exception = createStackOverflowError(callFrame);
  • trunk/Source/JavaScriptCore/runtime/Arguments.cpp

    r102545 r102709  
    5555void Arguments::copyToArguments(ExecState* exec, CallFrame* callFrame, uint32_t length)
    5656{
     57    if (UNLIKELY(d->overrodeLength)) {
     58        length = min(get(exec, exec->propertyNames().length).toUInt32(exec), length);
     59        for (unsigned i = 0; i < length; i++)
     60            callFrame->setArgument(i, get(exec, i));
     61        return;
     62    }
    5763    ASSERT(length == this->length(exec));
    5864    for (size_t i = 0; i < length; ++i) {
     
    6672void Arguments::fillArgList(ExecState* exec, MarkedArgumentBuffer& args)
    6773{
     74    if (UNLIKELY(d->overrodeLength)) {
     75        unsigned length = get(exec, exec->propertyNames().length).toUInt32(exec);
     76        for (unsigned i = 0; i < length; i++)
     77            args.append(get(exec, i));
     78        return;
     79    }
    6880    uint32_t length = this->length(exec);
    6981    for (size_t i = 0; i < length; ++i) {
Note: See TracChangeset for help on using the changeset viewer.