Title: [178662] trunk
Revision
178662
Author
d...@apple.com
Date
2015-01-19 12:03:00 -0800 (Mon, 19 Jan 2015)

Log Message

ES6: Support Array.of construction
https://bugs.webkit.org/show_bug.cgi?id=140605
<rdar://problem/19513655>

Reviewed by Geoffrey Garen.

Source/_javascript_Core:

Add and implementation of Array.of, described in 22.1.2.3 of the ES6
specification (15 Jan 2015). The Array.of() method creates a new Array
instance with a variable number of arguments, regardless of number or type
of the arguments.

* runtime/ArrayConstructor.cpp:
(JSC::arrayConstructorOf): Create a new empty Array, then iterate
over the arguments, setting them to the appropriate index.

LayoutTests:

Add 'of' to the Array properties, and a
test for Array.of().

* js/Object-getOwnPropertyNames-expected.txt:
* js/array-of-expected.txt: Added.
* js/array-of.html: Added.
* js/script-tests/Object-getOwnPropertyNames.js:
* js/script-tests/array-of.js: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (178661 => 178662)


--- trunk/LayoutTests/ChangeLog	2015-01-19 20:02:01 UTC (rev 178661)
+++ trunk/LayoutTests/ChangeLog	2015-01-19 20:03:00 UTC (rev 178662)
@@ -1,3 +1,20 @@
+2015-01-18  Dean Jackson  <d...@apple.com>
+
+        ES6: Support Array.of construction
+        https://bugs.webkit.org/show_bug.cgi?id=140605
+        <rdar://problem/19513655>
+
+        Reviewed by Geoffrey Garen.
+
+        Add 'of' to the Array properties, and a
+        test for Array.of().
+
+        * js/Object-getOwnPropertyNames-expected.txt:
+        * js/array-of-expected.txt: Added.
+        * js/array-of.html: Added.
+        * js/script-tests/Object-getOwnPropertyNames.js:
+        * js/script-tests/array-of.js: Added.
+
 2015-01-16  Ada Chan  <adac...@apple.com>
 
         HTMLMediaElement::isPlayingAudio() should return false if the element is explicitly muted by script.

Modified: trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt (178661 => 178662)


--- trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2015-01-19 20:02:01 UTC (rev 178661)
+++ trunk/LayoutTests/js/Object-getOwnPropertyNames-expected.txt	2015-01-19 20:03:00 UTC (rev 178662)
@@ -44,7 +44,7 @@
 PASS getSortedOwnPropertyNames(Object.prototype) is ['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']
 PASS getSortedOwnPropertyNames(Function) is ['length', 'name', 'prototype']
 PASS getSortedOwnPropertyNames(Function.prototype) is ['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']
-PASS getSortedOwnPropertyNames(Array) is ['isArray', 'length', 'name', 'prototype']
+PASS getSortedOwnPropertyNames(Array) is ['isArray', 'length', 'name', 'of', 'prototype']
 PASS getSortedOwnPropertyNames(Array.prototype) is ['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']
 PASS getSortedOwnPropertyNames(String) is ['fromCharCode', 'length', 'name', 'prototype']
 PASS getSortedOwnPropertyNames(String.prototype) is ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']

Added: trunk/LayoutTests/js/array-of-expected.txt (0 => 178662)


--- trunk/LayoutTests/js/array-of-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/js/array-of-expected.txt	2015-01-19 20:03:00 UTC (rev 178662)
@@ -0,0 +1,21 @@
+Tests for Array.of
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Array.of(1) is [1]
+PASS Array.of(1, 2) is [1, 2]
+PASS Array.of(1, 2, 3) is [1, 2, 3]
+PASS Array.of() is []
+PASS Array.of(undefined) is [undefined]
+PASS Array.of('hello') is ['hello']
+Construct nested Array with Array.of(Array.of(1, 2, 3), Array.of(4, 5, 6, 7, 8)).
+PASS x.length is 2
+PASS x[0].length is 3
+PASS x[1].length is 5
+Check that a setter isn't called.
+PASS Array.of(1, 2, 3) did not throw exception.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/js/array-of-expected.txt
___________________________________________________________________

Added: svn:mime-type

Added: svn:keywords

Added: svn:eol-style

Added: trunk/LayoutTests/js/array-of.html (0 => 178662)


--- trunk/LayoutTests/js/array-of.html	                        (rev 0)
+++ trunk/LayoutTests/js/array-of.html	2015-01-19 20:03:00 UTC (rev 178662)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/js/array-of.html
___________________________________________________________________

Added: svn:mime-type

Added: svn:keywords

Added: svn:eol-style

Modified: trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js (178661 => 178662)


--- trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2015-01-19 20:02:01 UTC (rev 178661)
+++ trunk/LayoutTests/js/script-tests/Object-getOwnPropertyNames.js	2015-01-19 20:03:00 UTC (rev 178662)
@@ -52,7 +52,7 @@
     "Object.prototype": "['__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', '__proto__', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf']",
     "Function": "['length', 'name', 'prototype']",
     "Function.prototype": "['apply', 'bind', 'call', 'constructor', 'length', 'name', 'toString']",
-    "Array": "['isArray', 'length', 'name', 'prototype']",
+    "Array": "['isArray', 'length', 'name', 'of', 'prototype']",
     "Array.prototype": "['concat', 'constructor', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'forEach', 'indexOf', 'join', 'keys', 'lastIndexOf', 'length', 'map', 'pop', 'push', 'reduce', 'reduceRight', 'reverse', 'shift', 'slice', 'some', 'sort', 'splice', 'toLocaleString', 'toString', 'unshift']",
     "String": "['fromCharCode', 'length', 'name', 'prototype']",
     "String.prototype": "['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'constructor', 'endsWith', 'fixed', 'fontcolor', 'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice', 'small', 'split', 'startsWith', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase', 'trim', 'trimLeft', 'trimRight', 'valueOf']",

Added: trunk/LayoutTests/js/script-tests/array-of.js (0 => 178662)


--- trunk/LayoutTests/js/script-tests/array-of.js	                        (rev 0)
+++ trunk/LayoutTests/js/script-tests/array-of.js	2015-01-19 20:03:00 UTC (rev 178662)
@@ -0,0 +1,24 @@
+description("Tests for Array.of");
+
+shouldBe("Array.of(1)", "[1]");
+shouldBe("Array.of(1, 2)", "[1, 2]");
+shouldBe("Array.of(1, 2, 3)", "[1, 2, 3]");
+
+shouldBe("Array.of()", "[]");
+shouldBe("Array.of(undefined)", "[undefined]");
+shouldBe("Array.of('hello')", "['hello']");
+
+debug("Construct nested Array with Array.of(Array.of(1, 2, 3), Array.of(4, 5, 6, 7, 8)).");
+var x = Array.of(Array.of(1, 2, 3), Array.of(4, 5, 6, 7, 8));
+shouldBe("x.length", "2");
+shouldBe("x[0].length", "3");
+shouldBe("x[1].length", "5");
+
+debug("Check that a setter isn't called.");
+
+Array.prototype.__defineSetter__("0", function (value) {
+    throw new Error("This should not be called.");
+});
+
+shouldNotThrow("Array.of(1, 2, 3)");
+
Property changes on: trunk/LayoutTests/js/script-tests/array-of.js
___________________________________________________________________

Added: svn:mime-type

Added: svn:keywords

Added: svn:eol-style

Modified: trunk/Source/_javascript_Core/ChangeLog (178661 => 178662)


--- trunk/Source/_javascript_Core/ChangeLog	2015-01-19 20:02:01 UTC (rev 178661)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-01-19 20:03:00 UTC (rev 178662)
@@ -1,3 +1,20 @@
+2015-01-18  Dean Jackson  <d...@apple.com>
+
+        ES6: Support Array.of construction
+        https://bugs.webkit.org/show_bug.cgi?id=140605
+        <rdar://problem/19513655>
+
+        Reviewed by Geoffrey Garen.
+
+        Add and implementation of Array.of, described in 22.1.2.3 of the ES6
+        specification (15 Jan 2015). The Array.of() method creates a new Array
+        instance with a variable number of arguments, regardless of number or type
+        of the arguments.
+
+        * runtime/ArrayConstructor.cpp:
+        (JSC::arrayConstructorOf): Create a new empty Array, then iterate
+        over the arguments, setting them to the appropriate index.
+
 2015-01-19  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [SVG -> OTF Converter] Flip the switch on

Modified: trunk/Source/_javascript_Core/runtime/ArrayConstructor.cpp (178661 => 178662)


--- trunk/Source/_javascript_Core/runtime/ArrayConstructor.cpp	2015-01-19 20:02:01 UTC (rev 178661)
+++ trunk/Source/_javascript_Core/runtime/ArrayConstructor.cpp	2015-01-19 20:03:00 UTC (rev 178662)
@@ -37,6 +37,7 @@
 namespace JSC {
 
 static EncodedJSValue JSC_HOST_CALL arrayConstructorIsArray(ExecState*);
+static EncodedJSValue JSC_HOST_CALL arrayConstructorOf(ExecState*);
 
 }
 
@@ -51,6 +52,7 @@
 /* Source for ArrayConstructor.lut.h
 @begin arrayConstructorTable
   isArray   arrayConstructorIsArray     DontEnum|Function 1
+  of        arrayConstructorOf          DontEnum|Function 0
 @end
 */
 
@@ -126,4 +128,17 @@
     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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to