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

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: Add DCHECK() to prevent intrinsics from being called with spread operator 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..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) {
+ 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)) {
+ // 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);
+}
« no previous file with comments | « src/full-codegen.cc ('k') | src/hydrogen.cc » ('j') | test/mjsunit/harmony/spread-call.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698