Index: src/harmony-spread.js |
diff --git a/src/harmony-spread.js b/src/harmony-spread.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a71355b4be664b62a5f89a3375303e2438b3a7ee |
--- /dev/null |
+++ b/src/harmony-spread.js |
@@ -0,0 +1,96 @@ |
+// 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 SpreadCall(function, thisArg, spread0) { |
arv (Not doing code reviews)
2015/02/18 15:07:06
I'm curious how this will handle?
super(...args)
|
+ if (!IS_SPEC_FUNCTION(function)) { |
+ // TODO(caitp): use name of function rather than value |
+ throw MakeTypeError("called_non_callable", [function]); |
+ } |
+ |
+ var args = new InternalArray(); |
+ |
+ var pos = 3; |
+ var count = %_ArgumentsLength(); |
+ |
+ for (var index = spread0; index < count; ++index) { |
+ var nextSpread = %_Arguments(index); |
+ |
+ while (pos < nextSpread) { |
+ args.push(%_Arguments(pos++)); |
+ } |
+ |
+ var collection = %_Arguments(pos++); |
+ var iterable = collection[symbolIterator]; |
+ var iterator = GetIterator(collection, iterable); |
+ |
+ 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); |
+ } |
+ } |
+ |
+ while (pos < spread0) { |
+ args.push(%_Arguments(pos++)); |
+ } |
+ |
+ return %Apply(function, thisArg, args, 0, args.length); |
+} |
+ |
+ |
+function SpreadCallNew(function, spread0) { |
+ if (!IS_SPEC_FUNCTION(function)) { |
arv (Not doing code reviews)
2015/02/18 15:07:06
How is NewTarget propagated?
caitp (gmail)
2015/02/18 15:32:08
This doesn't deal with any of the new construct pr
|
+ // TODO(caitp): use name of function rather than value |
+ throw MakeTypeError("called_non_callable", [function]); |
+ } |
+ |
+ var args = new InternalArray(); |
+ |
+ var pos = 2; |
+ var count = %_ArgumentsLength(); |
+ |
+ for (var index = spread0; index < count; ++index) { |
+ var nextSpread = %_Arguments(index); |
+ |
+ while (pos < nextSpread) { |
+ args.push(%_Arguments(pos++)); |
+ } |
+ |
+ var collection = %_Arguments(pos++); |
+ var iterable = collection[symbolIterator]; |
+ var iterator = GetIterator(collection, iterable); |
+ |
+ 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); |
+ } |
+ } |
+ |
+ while (pos < spread0) { |
+ args.push(%_Arguments(pos++)); |
+ } |
+ |
+ return %ApplyConstruct(function, args, 0, args.length); |
arv (Not doing code reviews)
2015/02/18 15:07:05
We might need to provide one more param to %ApplyC
|
+} |