Chromium Code Reviews| Index: src/harmony-array.js |
| diff --git a/src/harmony-array.js b/src/harmony-array.js |
| index dbcb292a0876842e8d3a6d4c0d21d997cdf6d977..49f07db93c5fe83ea7a22e523e412114af16b07f 100644 |
| --- a/src/harmony-array.js |
| +++ b/src/harmony-array.js |
| @@ -123,11 +123,85 @@ function ArrayFill(value /* [, start [, end ] ] */) { // length == 1 |
| return array; |
| } |
| +// ES6, 22.1.2.1 --- Requires harmony_symbols and harmony_iteration |
| +function ArrayFrom(arrayLike /* [, mapfn [, receiver] ] */) { // length == 1 |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
Just keep the mapfn and receiver here. You can set
caitp (gmail)
2014/07/02 19:22:05
I haven't found a way to set the arity of a functi
arv (Not doing code reviews)
2014/07/02 19:29:09
%FunctionSetLength(f, len);
|
| + var items = ToObject(arrayLike); |
| + var mapping = false; |
| + var array; |
| + var mapfn; |
| + var receiver; |
| + |
| + if (%_ArgumentsLength() > 1) { |
| + mapfn = %_Arguments(1); |
| + if (%_ArgumentsLength() > 2) { |
| + receiver = %_Arguments(2); |
| + } |
| + } |
| + |
| + if (!IS_UNDEFINED(mapfn)) { |
| + if (!IS_SPEC_FUNCTION(mapfn)) { |
| + throw MakeTypeError('called_non_callable', [ mapfn ]); |
| + } |
| + if (IS_NULL_OR_UNDEFINED(receiver)) { |
| + receiver = %GetDefaultReceiver(mapfn) || receiver; |
| + } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(mapfn)) { |
| + receiver = ToObject(receiver); |
| + } |
| + mapping = true; |
| + } |
| + |
| + var usingIterator = items[symbolIterator]; |
| + var k = 0; |
| + var value; |
|
aandrey
2014/07/02 18:28:15
var stepping = mapping && DEBUG_IS_ACTIVE && %Debu
|
| + |
| + if (!IS_UNDEFINED(usingIterator)) { |
| + if (!IS_SPEC_FUNCTION(usingIterator)) { |
| + throw MakeTypeError('called_non_callable', [ usingIterator ]); |
| + } |
| + |
| + var iterator = %_CallFunction(items, usingIterator); |
| + if (!IS_OBJECT(iterator)) { |
| + throw MakeTypeError('iterator_result_not_an_object', [ iterator ]); |
| + } |
| + |
| + array = []; |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
This should use new this if this is a constructor.
arv (Not doing code reviews)
2014/07/02 18:26:43
The ordering here is not correct.
caitp (gmail)
2014/07/02 19:22:05
You mean, because the array is created after condi
arv (Not doing code reviews)
2014/07/02 19:29:09
We could try to change the spec. But for now, we s
|
| + var next; |
| + while (!(next = iterator.next()).done) { |
| + value = next.value; |
| + if (mapping) { |
| + value = %_CallFunction(receiver, value, k, mapfn); |
|
aandrey
2014/07/02 18:28:15
if (stepping) %DebugPrepareStepInIfStepping(mapfn)
|
| + } |
| + array[k++] = value; |
| + } |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
Let putStatus be Put(A, "length", k, true).
is mi
|
| + } else { |
| + var len = +items.length; |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
How about adding TO_LENGTH to macros.py?
caitp (gmail)
2014/07/02 19:22:05
Will do, but I'm not actually sure this is really
|
| + if (len < +0 || len !== len) { |
| + len = +0; |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
len = 0
|
| + } |
| + |
| + array = new $Array(len); |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
new this here as well.
caitp (gmail)
2014/07/02 19:22:05
After reading that, I think I understand what you
arv (Not doing code reviews)
2014/07/02 19:29:09
Unfortunately V8 has no concept of [[Constructor]]
rossberg
2014/07/03 11:16:57
IS_SPEC_FUNCTION is more what you want.
|
| + for (; k < len; ++k) { |
| + value = items[k]; |
| + if (mapping) { |
| + value = %_CallFunction(receiver, value, k, mapfn); |
|
aandrey
2014/07/02 18:28:15
ditto
|
| + } |
| + array[k] = value; |
| + } |
| + } |
| + |
|
arv (Not doing code reviews)
2014/07/02 18:26:43
Put length here as well.
|
| + return array; |
| +} |
| + |
| // ------------------------------------------------------------------- |
| function HarmonyArrayExtendArrayPrototype() { |
| %CheckIsBootstrapping(); |
| + // Set up non-enumerable functions on the Array object. |
| + InstallFunctions($Array, DONT_ENUM, $Array( |
| + "from", ArrayFrom |
| + )); |
| + |
| // Set up the non-enumerable functions on the Array prototype object. |
| InstallFunctions($Array.prototype, DONT_ENUM, $Array( |
| "find", ArrayFind, |