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