OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 // This files contains runtime support implemented in JavaScript. | 5 // This files contains runtime support implemented in JavaScript. |
6 | 6 |
7 // CAUTION: Some of the functions specified in this file are called | 7 // CAUTION: Some of the functions specified in this file are called |
8 // directly from compiled code. These are the functions with names in | 8 // directly from compiled code. These are the functions with names in |
9 // ALL CAPS. The compiled code passes the first argument in 'this'. | 9 // ALL CAPS. The compiled code passes the first argument in 'this'. |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 }); | 35 }); |
36 | 36 |
37 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
38 | 38 |
39 | 39 |
40 /* --------------------------------- | 40 /* --------------------------------- |
41 - - - U t i l i t i e s - - - | 41 - - - U t i l i t i e s - - - |
42 --------------------------------- | 42 --------------------------------- |
43 */ | 43 */ |
44 | 44 |
45 function ConcatIterableToArray(target, iterable) { | |
46 var index = target.length; | |
47 for (var element of iterable) { | |
48 AddIndexedProperty(target, index++, element); | |
49 } | |
50 return target; | |
51 } | |
52 | |
53 | 45 |
54 // This function should be called rather than %AddElement in contexts where the | 46 // This function should be called rather than %AddElement in contexts where the |
55 // argument might not be less than 2**32-1. ES2015 ToLength semantics mean that | 47 // argument might not be less than 2**32-1. ES2015 ToLength semantics mean that |
56 // this is a concern at basically all callsites. | 48 // this is a concern at basically all callsites. |
57 function AddIndexedProperty(obj, index, value) { | 49 function AddIndexedProperty(obj, index, value) { |
58 if (index === TO_UINT32(index) && index !== kMaxUint32) { | 50 if (index === TO_UINT32(index) && index !== kMaxUint32) { |
59 %AddElement(obj, index, value); | 51 %AddElement(obj, index, value); |
60 } else { | 52 } else { |
61 %AddNamedProperty(obj, TO_STRING(index), value, NONE); | 53 %AddNamedProperty(obj, TO_STRING(index), value, NONE); |
62 } | 54 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // Exports | 122 // Exports |
131 | 123 |
132 utils.Export(function(to) { | 124 utils.Export(function(to) { |
133 to.AddIndexedProperty = AddIndexedProperty; | 125 to.AddIndexedProperty = AddIndexedProperty; |
134 to.MaxSimple = MaxSimple; | 126 to.MaxSimple = MaxSimple; |
135 to.MinSimple = MinSimple; | 127 to.MinSimple = MinSimple; |
136 to.ToPositiveInteger = ToPositiveInteger; | 128 to.ToPositiveInteger = ToPositiveInteger; |
137 to.SpeciesConstructor = SpeciesConstructor; | 129 to.SpeciesConstructor = SpeciesConstructor; |
138 }); | 130 }); |
139 | 131 |
140 %InstallToContext([ | |
141 "concat_iterable_to_array", ConcatIterableToArray, | |
142 ]); | |
143 | |
144 }) | 132 }) |
OLD | NEW |