Title: [184942] trunk
Revision
184942
Author
[email protected]
Date
2015-05-27 22:47:11 -0700 (Wed, 27 May 2015)

Log Message

Array.of should work with other constructors
https://bugs.webkit.org/show_bug.cgi?id=145365
Source/_javascript_Core:

Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.of
step 4

Patch by Jordan Harband <[email protected]> on 2015-05-27
Reviewed by Yusuke Suzuki.

* builtins/ArrayConstructor.js:
(of):
* runtime/ArrayConstructor.cpp:
(JSC::arrayConstructorOf): Deleted.

LayoutTests:

Patch by Jordan Harband <[email protected]> on 2015-05-27
Reviewed by Yusuke Suzuki.

* js/array-of-expected.txt:
* js/script-tests/array-of.js:
(Foo):

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (184941 => 184942)


--- trunk/LayoutTests/ChangeLog	2015-05-28 04:52:25 UTC (rev 184941)
+++ trunk/LayoutTests/ChangeLog	2015-05-28 05:47:11 UTC (rev 184942)
@@ -1,3 +1,14 @@
+2015-05-27  Jordan Harband  <[email protected]>
+
+        Array.of should work with other constructors
+        https://bugs.webkit.org/show_bug.cgi?id=145365
+
+        Reviewed by Yusuke Suzuki.
+
+        * js/array-of-expected.txt:
+        * js/script-tests/array-of.js:
+        (Foo):
+
 2015-05-27  Benjamin Poulain  <[email protected]>
 
         [JSC] Add undefined->double conversion to DoubleRep

Modified: trunk/LayoutTests/js/array-of-expected.txt (184941 => 184942)


--- trunk/LayoutTests/js/array-of-expected.txt	2015-05-28 04:52:25 UTC (rev 184941)
+++ trunk/LayoutTests/js/array-of-expected.txt	2015-05-28 05:47:11 UTC (rev 184942)
@@ -3,6 +3,8 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
+PASS Array.of.length is 0
+PASS Array.of.name is 'of'
 PASS Array.of(1) is [1]
 PASS Array.of(1, 2) is [1, 2]
 PASS Array.of(1, 2, 3) is [1, 2, 3]
@@ -15,6 +17,9 @@
 PASS x[1].length is 5
 Check that a setter isn't called.
 PASS Array.of(1, 2, 3) did not throw exception.
+PASS Array.of.call(Foo, 'a', 'b', 'c') instanceof Foo is true
+PASS Array.of.call(Foo, 'a', 'b', 'c').givenLength is 3
+PASS var foo = Array.of.call(Foo, 'a', 'b', 'c'); [foo.length, foo[0], foo[1], foo[2]] is [3, 'a', 'b', 'c']
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/script-tests/array-of.js (184941 => 184942)


--- trunk/LayoutTests/js/script-tests/array-of.js	2015-05-28 04:52:25 UTC (rev 184941)
+++ trunk/LayoutTests/js/script-tests/array-of.js	2015-05-28 05:47:11 UTC (rev 184942)
@@ -1,5 +1,8 @@
 description("Tests for Array.of");
 
+shouldBe("Array.of.length", "0");
+shouldBe("Array.of.name", "'of'");
+
 shouldBe("Array.of(1)", "[1]");
 shouldBe("Array.of(1, 2)", "[1, 2]");
 shouldBe("Array.of(1, 2, 3)", "[1, 2, 3]");
@@ -22,3 +25,7 @@
 
 shouldNotThrow("Array.of(1, 2, 3)");
 
+var Foo = function FooBar(length) { this.givenLength = length; };
+shouldBeTrue("Array.of.call(Foo, 'a', 'b', 'c') instanceof Foo")
+shouldBe("Array.of.call(Foo, 'a', 'b', 'c').givenLength", "3");
+shouldBe("var foo = Array.of.call(Foo, 'a', 'b', 'c'); [foo.length, foo[0], foo[1], foo[2]]", "[3, 'a', 'b', 'c']");

Modified: trunk/Source/_javascript_Core/ChangeLog (184941 => 184942)


--- trunk/Source/_javascript_Core/ChangeLog	2015-05-28 04:52:25 UTC (rev 184941)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-05-28 05:47:11 UTC (rev 184942)
@@ -1,3 +1,17 @@
+2015-05-27  Jordan Harband  <[email protected]>
+
+        Array.of should work with other constructors
+        https://bugs.webkit.org/show_bug.cgi?id=145365
+        Per https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.of
+        step 4
+
+        Reviewed by Yusuke Suzuki.
+
+        * builtins/ArrayConstructor.js:
+        (of):
+        * runtime/ArrayConstructor.cpp:
+        (JSC::arrayConstructorOf): Deleted.
+
 2015-05-27  Benjamin Poulain  <[email protected]>
 
         [JSC] Add undefined->double conversion to DoubleRep

Modified: trunk/Source/_javascript_Core/builtins/ArrayConstructor.js (184941 => 184942)


--- trunk/Source/_javascript_Core/builtins/ArrayConstructor.js	2015-05-28 04:52:25 UTC (rev 184941)
+++ trunk/Source/_javascript_Core/builtins/ArrayConstructor.js	2015-05-28 05:47:11 UTC (rev 184942)
@@ -23,6 +23,19 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+function of(/* items... */)
+{
+    "use strict";
+
+    var length = arguments.length;
+    // TODO: Need isConstructor(this) instead of typeof "function" check.
+    var array = typeof this === 'function' ? new this(length) : new @Array(length);
+    for (var k = 0; k < length; ++k)
+        @putByValDirect(array, k, arguments[k]);
+    array.length = length;
+    return array;
+}
+
 function from(items /*, mapFn, thisArg */) {
     "use strict";
 

Modified: trunk/Source/_javascript_Core/runtime/ArrayConstructor.cpp (184941 => 184942)


--- trunk/Source/_javascript_Core/runtime/ArrayConstructor.cpp	2015-05-28 04:52:25 UTC (rev 184941)
+++ trunk/Source/_javascript_Core/runtime/ArrayConstructor.cpp	2015-05-28 05:47:11 UTC (rev 184942)
@@ -37,7 +37,6 @@
 namespace JSC {
 
 static EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*);
-static EncodedJSValue JSC_HOST_CALL arrayConstructorOf(ExecState*);
 
 }
 
@@ -129,17 +128,4 @@
     return JSValue::encode(jsBoolean(exec->argument(0).inherits(JSArray::info())));
 }
 
-EncodedJSValue JSC_HOST_CALL arrayConstructorOf(ExecState* exec)
-{
-    ArgList args(exec);
-    size_t length = args.size();
-
-    JSArray* result = constructEmptyArray(exec, nullptr, length);
-
-    for (unsigned i = 0; i < length; i++)
-        result->putDirectIndex(exec, i, args.at(i));
-
-    return JSValue::encode(result);
-}
-
 } // namespace JSC
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to