Chromium Code Reviews| Index: src/harmony-spread.js |
| diff --git a/src/harmony-spread.js b/src/harmony-spread.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b2b88188093457da104555714ac54158112a4988 |
| --- /dev/null |
| +++ b/src/harmony-spread.js |
| @@ -0,0 +1,45 @@ |
| +// Copyright 2013 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +'use strict'; |
| + |
| +// ------------------------------------------------------------------- |
| + |
| +function SpreadArguments(a) { |
| + // Each argument should be an array |
| + var count = %_ArgumentsLength(); |
| + var array = (new InternalArray()).concat(%_Arguments(0)); |
|
arv (Not doing code reviews)
2015/02/23 17:55:56
Why not Push. concat creates a new array so we cre
rossberg
2015/02/24 16:22:47
+1, use push
|
| + |
| + for (var i = 1; i < count; ++i) { |
| + array = array.concat(%_Arguments(i)); |
|
arv (Not doing code reviews)
2015/02/23 17:55:56
push here as well
or roll your own loop. It is us
|
| + } |
| + |
| + return array; |
| +} |
| + |
| +function SpreadIterable(collection) { |
| + if (IS_NULL_OR_UNDEFINED(collection)) { |
| + throw MakeTypeError("not_iterable", [collection]); |
| + } |
| + |
| + var iterable = collection[symbolIterator]; |
| + var iterator = GetIterator(collection, iterable); |
|
arv (Not doing code reviews)
2015/02/23 17:55:56
I'm on a mission to replace all of these with for-
|
| + var args = new InternalArray(); |
| + |
| + while (true) { |
| + var next = iterator.next(); |
| + |
| + if (!IS_OBJECT(next)) { |
| + throw MakeTypeError("iterator_result_not_an_object", [next]); |
| + } |
| + |
| + if (next.done) { |
| + break; |
| + } |
| + |
| + args.push(next.value); |
| + } |
| + |
| + return args; |
| +} |