Changeset 91483 in webkit


Ignore:
Timestamp:
Jul 21, 2011, 11:59:38 AM (14 years ago)
Author:
barraclough@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=64900
Function.prototype.apply should accept an array-like object as its second argument

Reviewed by Sam Weinig.

Source/JavaScriptCore:

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::privateExecute):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncApply):

  • Remove the type error if object is not an array.

LayoutTests:

  • fast/js/function-apply-expected.txt:
  • fast/js/script-tests/function-apply.js:
    • Add a test for array-like objects.
  • sputnik/Conformance/15_Native_Objects/15.3_Function/15.3.4/15.3.4.3_Function.prototype.apply/S15.3.4.3_A6_T1-expected.txt:
  • sputnik/Conformance/15_Native_Objects/15.3_Function/15.3.4/15.3.4.3_Function.prototype.apply/S15.3.4.3_A6_T4-expected.txt:
    • These tests are incorrect & assert ES3 behaviour.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r91481 r91483  
     12011-07-21  Gavin Barraclough  <barraclough@apple.com>
     2
     3        https://bugs.webkit.org/show_bug.cgi?id=64900
     4        Function.prototype.apply should accept an array-like object as its second argument
     5
     6        Reviewed by Sam Weinig.
     7
     8        * fast/js/function-apply-expected.txt:
     9        * fast/js/script-tests/function-apply.js:
     10            - Add a test for array-like objects.
     11        * sputnik/Conformance/15_Native_Objects/15.3_Function/15.3.4/15.3.4.3_Function.prototype.apply/S15.3.4.3_A6_T1-expected.txt:
     12        * sputnik/Conformance/15_Native_Objects/15.3_Function/15.3.4/15.3.4.3_Function.prototype.apply/S15.3.4.3_A6_T4-expected.txt:
     13            - These tests are incorrect & assert ES3 behaviour.
     14
    1152011-07-21  Enrica Casucci  <enrica@apple.com>
    216
  • trunk/LayoutTests/fast/js/function-apply-expected.txt

    r62456 r91483  
    1 Tests to ensure that Function.apply works correctly for Arrays and arguments.
     1Tests to ensure that Function.apply works correctly for Arrays, arguments and array-like objects.
    22
    33On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     
    3737PASS var a = []; a.length = 0xFFFFFFFE; [].constructor.apply('', a).length is 0x10000
    3838PASS var a = []; a.length = 0xFFFFFFFF; [].constructor.apply('', a).length is 0x10000
     39PASS (function(a,b,c,d){ return d ? -1 : (a+b+c); }).apply(undefined, {length:3, 0:100, 1:20, 2:3}) is 123
    3940PASS successfullyParsed is true
    4041
  • trunk/LayoutTests/fast/js/script-tests/function-apply.js

    r62456 r91483  
    1 description('Tests to ensure that Function.apply works correctly for Arrays and arguments.');
     1description('Tests to ensure that Function.apply works correctly for Arrays, arguments and array-like objects.');
    22
    33function argumentsApply1(a, b, c)
     
    292292shouldBe("var a = []; a.length = 0xFFFFFFFF; [].constructor.apply('', a).length", "0x10000");
    293293
     294// ES5 permits apply with array-like objects.
     295shouldBe("(function(a,b,c,d){ return d ? -1 : (a+b+c); }).apply(undefined, {length:3, 0:100, 1:20, 2:3})", '123');
     296
    294297var successfullyParsed = true;
  • trunk/LayoutTests/sputnik/Conformance/15_Native_Objects/15.3_Function/15.3.4/15.3.4.3_Function.prototype.apply/S15.3.4.3_A6_T1-expected.txt

    r58534 r91483  
    11S15.3.4.3_A6_T1
    22
    3 PASS
     3FAIL SputnikError: #1.1: if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown
    44
    55TEST COMPLETE
  • trunk/LayoutTests/sputnik/Conformance/15_Native_Objects/15.3_Function/15.3.4/15.3.4.3_Function.prototype.apply/S15.3.4.3_A6_T4-expected.txt

    r58534 r91483  
    11S15.3.4.3_A6_T4
    22
    3 PASS
     3FAIL SputnikError: #1.1: if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown
    44
    55TEST COMPLETE
  • trunk/Source/JavaScriptCore/ChangeLog

    r91482 r91483  
     12011-07-21  Gavin Barraclough  <barraclough@apple.com>
     2
     3        https://bugs.webkit.org/show_bug.cgi?id=64900
     4        Function.prototype.apply should accept an array-like object as its second argument
     5
     6        Reviewed by Sam Weinig.
     7
     8        * interpreter/Interpreter.cpp:
     9        (JSC::Interpreter::privateExecute):
     10        * jit/JITStubs.cpp:
     11        (JSC::DEFINE_STUB_FUNCTION):
     12        * runtime/FunctionPrototype.cpp:
     13        (JSC::functionProtoFuncApply):
     14            - Remove the type error if object is not an array.
     15
    1162011-07-21  Gavin Barraclough  <barraclough@apple.com>
    217
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r91216 r91483  
    43144314                }
    43154315                array->copyToRegisters(callFrame, callFrame->registers() + argsOffset, argCount);
    4316             } else if (asObject(arguments)->inherits(&JSArray::s_info)) {
     4316            } else {
    43174317                JSObject* argObject = asObject(arguments);
    43184318                argCount = argObject->get(callFrame, callFrame->propertyNames().length).toUInt32(callFrame);
     
    43294329                    CHECK_FOR_EXCEPTION();
    43304330                }
    4331             } else {
    4332                 exceptionValue = createInvalidParamError(callFrame, "Function.prototype.apply", arguments);
    4333                 goto vm_throw;
    43344331            }
    43354332        }
  • trunk/Source/JavaScriptCore/jit/JITStubs.cpp

    r91194 r91483  
    25602560            }
    25612561            array->copyToRegisters(callFrame, callFrame->registers() + argsOffset, argCount);
    2562         } else if (asObject(arguments)->inherits(&JSArray::s_info)) {
     2562        } else {
    25632563            JSObject* argObject = asObject(arguments);
    25642564            argCount = argObject->get(callFrame, callFrame->propertyNames().length).toUInt32(callFrame);
     
    25752575                CHECK_FOR_EXCEPTION();
    25762576            }
    2577         } else {
    2578             stackFrame.globalData->exception = createInvalidParamError(callFrame, "Function.prototype.apply", arguments);
    2579             VM_THROW_EXCEPTION();
    25802577        }
    25812578    }
  • trunk/Source/JavaScriptCore/runtime/FunctionPrototype.cpp

    r91194 r91483  
    122122        else if (isJSArray(&exec->globalData(), array))
    123123            asArray(array)->fillArgList(exec, applyArgs);
    124         else if (asObject(array)->inherits(&JSArray::s_info)) {
    125             unsigned length = asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
     124        else {
     125            unsigned length = asObject(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
    126126            for (unsigned i = 0; i < length; ++i)
    127127                applyArgs.append(asArray(array)->get(exec, i));
    128         } else
    129             return throwVMTypeError(exec);
     128        }
    130129    }
    131130
Note: See TracChangeset for help on using the changeset viewer.