| 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);
|
| +}
|
|
|