Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Unified Diff: src/harmony-spread.js

Issue 938443002: [es6] implement spread calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Eagerly iterate spread expressions, make parser more complicated, simplify harmony-spread Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
+}

Powered by Google App Engine
This is Rietveld 408576698