blob: 82ea83959853634d274089d13b54bc4db6918b01 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5(function(global, utils) {
6
7'use strict';
8
9// -------------------------------------------------------------------
10// Imports
11var InternalArray = utils.InternalArray;
12var MakeTypeError;
13
14utils.Import(function(from) {
15 MakeTypeError = from.MakeTypeError;
16});
17
18// -------------------------------------------------------------------
19
20function SpreadArguments() {
Ben Murdoch097c5b22016-05-18 11:27:45 +010021 var count = arguments.length;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000022 var args = new InternalArray();
23
24 for (var i = 0; i < count; ++i) {
Ben Murdoch097c5b22016-05-18 11:27:45 +010025 var array = arguments[i];
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026 var length = array.length;
27 for (var j = 0; j < length; ++j) {
28 args.push(array[j]);
29 }
30 }
31
32 return args;
33}
34
35
36function SpreadIterable(collection) {
37 if (IS_NULL_OR_UNDEFINED(collection)) {
38 throw MakeTypeError(kNotIterable, collection);
39 }
40
41 var args = new InternalArray();
42 for (var value of collection) {
43 args.push(value);
44 }
45 return args;
46}
47
48// ----------------------------------------------------------------------------
49// Exports
50
51%InstallToContext([
52 "spread_arguments", SpreadArguments,
53 "spread_iterable", SpreadIterable,
54]);
55
56})