ES6: Implement Array.from()
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2015 00:20:54 +0000 (00:20 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Feb 2015 00:20:54 +0000 (00:20 +0000)
commitd96f4ea793ab23f5ce6c5ce6b1703a0a69309cbb
treedc7d40b1fa8fc9b77fe4b37a877d2ea0c3d62d6a
parent65c496f84ddcecb36a019f1a884c62df80c98050
ES6: Implement Array.from()
https://bugs.webkit.org/show_bug.cgi?id=141054
<rdar://problem/19654521>

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

Implement the Array.from() ES6 method
as defined in Section 22.1.2.1 of the specification.

Given that we can't rely on the built-in
global functions or objects to be untainted,
I had to expose a few of them directly to
the function via private names. In particular:
- Math.floor -> @floor
- Math.abs -> @abs
- Number -> @Number
- Array -> @Array
- isFinite -> @isFinite

* builtins/ArrayConstructor.js: Added.
(from): Implementation of Array.from in JavaScript.
* runtime/ArrayConstructor.cpp: Add "from" to the lookup
table for the constructor object.
* runtime/CommonIdentifiers.h: Add the private versions
of the identifiers listed above.
* runtime/JSGlobalObject.cpp: Add the implementations of
those identifiers to the global object (using their
private names).
(JSC::JSGlobalObject::init):
* runtime/JSGlobalObjectFunctions.cpp:
(JSC::globalPrivateFuncAbs): Implementation of the abs function.
(JSC::globalPrivateFuncFloor): Implementation of the floor function.
* runtime/JSGlobalObjectFunctions.h:

LayoutTests:

Test for Array.from(). The test has
one expected failure: using from() on a
Set object, which will be addressed in
a followup:
https://bugs.webkit.org/show_bug.cgi?id=141055

* js/array-from-expected.txt: Added.
* js/array-from.html: Added.
* js/script-tests/array-from.js: Added.
* js/Object-getOwnPropertyNames.html: Update results for the new value on the constructor.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180370 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
LayoutTests/ChangeLog
LayoutTests/js/Object-getOwnPropertyNames-expected.txt
LayoutTests/js/array-from-expected.txt [new file with mode: 0644]
LayoutTests/js/array-from.html [new file with mode: 0644]
LayoutTests/js/script-tests/Object-getOwnPropertyNames.js
LayoutTests/js/script-tests/array-from.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/builtins/ArrayConstructor.js [new file with mode: 0644]
Source/JavaScriptCore/runtime/ArrayConstructor.cpp
Source/JavaScriptCore/runtime/CommonIdentifiers.h
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.h