1 // 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 11 var InternalArray = utils.InternalArray; 12 13 // ------------------------------------------------------------------- 14 15 function SpreadArguments() { 16 var count = arguments.length; 17 var args = new InternalArray(); 18 19 for (var i = 0; i < count; ++i) { 20 var array = arguments[i]; 21 var length = array.length; 22 for (var j = 0; j < length; ++j) { 23 args.push(array[j]); 24 } 25 } 26 27 return args; 28 } 29 30 31 function SpreadIterable(collection) { 32 if (IS_NULL_OR_UNDEFINED(collection)) { 33 throw %make_type_error(kNotIterable, collection); 34 } 35 36 var args = new InternalArray(); 37 for (var value of collection) { 38 args.push(value); 39 } 40 return args; 41 } 42 43 // ---------------------------------------------------------------------------- 44 // Exports 45 46 %InstallToContext([ 47 "spread_arguments", SpreadArguments, 48 "spread_iterable", SpreadIterable, 49 ]); 50 51 }) 52