Title: [91483] trunk
Revision
91483
Author
barraclo...@apple.com
Date
2011-07-21 11:59:38 -0700 (Thu, 21 Jul 2011)

Log 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/_javascript_Core: 

* 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.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (91482 => 91483)


--- trunk/LayoutTests/ChangeLog	2011-07-21 18:57:57 UTC (rev 91482)
+++ trunk/LayoutTests/ChangeLog	2011-07-21 18:59:38 UTC (rev 91483)
@@ -1,3 +1,17 @@
+2011-07-21  Gavin Barraclough  <barraclo...@apple.com>
+
+        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.
+
+        * 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.
+
 2011-07-21  Enrica Casucci  <enr...@apple.com>
 
         Cannot click to position the caret to the right of an image with display:block style.

Modified: trunk/LayoutTests/fast/js/function-apply-expected.txt (91482 => 91483)


--- trunk/LayoutTests/fast/js/function-apply-expected.txt	2011-07-21 18:57:57 UTC (rev 91482)
+++ trunk/LayoutTests/fast/js/function-apply-expected.txt	2011-07-21 18:59:38 UTC (rev 91483)
@@ -1,4 +1,4 @@
-Tests to ensure that Function.apply works correctly for Arrays and arguments.
+Tests to ensure that Function.apply works correctly for Arrays, arguments and array-like objects.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
@@ -36,6 +36,7 @@
 PASS var a = []; a.length = 0x10001; [].constructor.apply('', a).length is 0x10000
 PASS var a = []; a.length = 0xFFFFFFFE; [].constructor.apply('', a).length is 0x10000
 PASS var a = []; a.length = 0xFFFFFFFF; [].constructor.apply('', a).length is 0x10000
+PASS (function(a,b,c,d){ return d ? -1 : (a+b+c); }).apply(undefined, {length:3, 0:100, 1:20, 2:3}) is 123
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/js/script-tests/function-apply.js (91482 => 91483)


--- trunk/LayoutTests/fast/js/script-tests/function-apply.js	2011-07-21 18:57:57 UTC (rev 91482)
+++ trunk/LayoutTests/fast/js/script-tests/function-apply.js	2011-07-21 18:59:38 UTC (rev 91483)
@@ -1,4 +1,4 @@
-description('Tests to ensure that Function.apply works correctly for Arrays and arguments.');
+description('Tests to ensure that Function.apply works correctly for Arrays, arguments and array-like objects.');
 
 function argumentsApply1(a, b, c)
 {
@@ -291,4 +291,7 @@
 shouldBe("var a = []; a.length = 0xFFFFFFFE; [].constructor.apply('', a).length", "0x10000");
 shouldBe("var a = []; a.length = 0xFFFFFFFF; [].constructor.apply('', a).length", "0x10000");
 
+// ES5 permits apply with array-like objects.
+shouldBe("(function(a,b,c,d){ return d ? -1 : (a+b+c); }).apply(undefined, {length:3, 0:100, 1:20, 2:3})", '123');
+
 var successfullyParsed = true;

Modified: 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 (91482 => 91483)


--- 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	2011-07-21 18:57:57 UTC (rev 91482)
+++ 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	2011-07-21 18:59:38 UTC (rev 91483)
@@ -1,6 +1,6 @@
 S15.3.4.3_A6_T1
 
-PASS 
+FAIL SputnikError: #1.1: if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown
 
 TEST COMPLETE
 

Modified: 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 (91482 => 91483)


--- 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	2011-07-21 18:57:57 UTC (rev 91482)
+++ 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	2011-07-21 18:59:38 UTC (rev 91483)
@@ -1,6 +1,6 @@
 S15.3.4.3_A6_T4
 
-PASS 
+FAIL SputnikError: #1.1: if argArray is neither an array nor an arguments object (see 10.1.8), a TypeError exception is thrown
 
 TEST COMPLETE
 

Modified: trunk/Source/_javascript_Core/ChangeLog (91482 => 91483)


--- trunk/Source/_javascript_Core/ChangeLog	2011-07-21 18:57:57 UTC (rev 91482)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-07-21 18:59:38 UTC (rev 91483)
@@ -1,5 +1,20 @@
 2011-07-21  Gavin Barraclough  <barraclo...@apple.com>
 
+        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.
+
+        * 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.
+
+2011-07-21  Gavin Barraclough  <barraclo...@apple.com>
+
         https://bugs.webkit.org/show_bug.cgi?id=64964
         DFG JIT - Enable support for eval code
 

Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.cpp (91482 => 91483)


--- trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2011-07-21 18:57:57 UTC (rev 91482)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2011-07-21 18:59:38 UTC (rev 91483)
@@ -4313,7 +4313,7 @@
                     goto vm_throw;
                 }
                 array->copyToRegisters(callFrame, callFrame->registers() + argsOffset, argCount);
-            } else if (asObject(arguments)->inherits(&JSArray::s_info)) {
+            } else {
                 JSObject* argObject = asObject(arguments);
                 argCount = argObject->get(callFrame, callFrame->propertyNames().length).toUInt32(callFrame);
                 argCount = min<uint32_t>(argCount, Arguments::MaxArguments);
@@ -4328,9 +4328,6 @@
                     argsBuffer[i] = asObject(arguments)->get(callFrame, i);
                     CHECK_FOR_EXCEPTION();
                 }
-            } else {
-                exceptionValue = createInvalidParamError(callFrame, "Function.prototype.apply", arguments);
-                goto vm_throw;
             }
         }
         CHECK_FOR_EXCEPTION();

Modified: trunk/Source/_javascript_Core/jit/JITStubs.cpp (91482 => 91483)


--- trunk/Source/_javascript_Core/jit/JITStubs.cpp	2011-07-21 18:57:57 UTC (rev 91482)
+++ trunk/Source/_javascript_Core/jit/JITStubs.cpp	2011-07-21 18:59:38 UTC (rev 91483)
@@ -2559,7 +2559,7 @@
                 VM_THROW_EXCEPTION();
             }
             array->copyToRegisters(callFrame, callFrame->registers() + argsOffset, argCount);
-        } else if (asObject(arguments)->inherits(&JSArray::s_info)) {
+        } else {
             JSObject* argObject = asObject(arguments);
             argCount = argObject->get(callFrame, callFrame->propertyNames().length).toUInt32(callFrame);
             argCount = min(argCount, static_cast<uint32_t>(Arguments::MaxArguments));
@@ -2574,9 +2574,6 @@
                 argsBuffer[i] = asObject(arguments)->get(callFrame, i);
                 CHECK_FOR_EXCEPTION();
             }
-        } else {
-            stackFrame.globalData->exception = createInvalidParamError(callFrame, "Function.prototype.apply", arguments);
-            VM_THROW_EXCEPTION();
         }
     }
 

Modified: trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp (91482 => 91483)


--- trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp	2011-07-21 18:57:57 UTC (rev 91482)
+++ trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp	2011-07-21 18:59:38 UTC (rev 91483)
@@ -121,12 +121,11 @@
             asArguments(array)->fillArgList(exec, applyArgs);
         else if (isJSArray(&exec->globalData(), array))
             asArray(array)->fillArgList(exec, applyArgs);
-        else if (asObject(array)->inherits(&JSArray::s_info)) {
-            unsigned length = asArray(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
+        else {
+            unsigned length = asObject(array)->get(exec, exec->propertyNames().length).toUInt32(exec);
             for (unsigned i = 0; i < length; ++i)
                 applyArgs.append(asArray(array)->get(exec, i));
-        } else
-            return throwVMTypeError(exec);
+        }
     }
 
     return JSValue::encode(call(exec, thisValue, callType, callData, exec->argument(0), applyArgs));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to