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 18 matching lines...) Expand all Loading... |
29 MakeTypeError = from.MakeTypeError; | 29 MakeTypeError = from.MakeTypeError; |
30 speciesSymbol = from.species_symbol; | 30 speciesSymbol = from.species_symbol; |
31 }); | 31 }); |
32 | 32 |
33 utils.ImportFromExperimental(function(from) { | 33 utils.ImportFromExperimental(function(from) { |
34 FLAG_harmony_species = from.FLAG_harmony_species; | 34 FLAG_harmony_species = from.FLAG_harmony_species; |
35 }); | 35 }); |
36 | 36 |
37 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
38 | 38 |
39 /* ------------------------------------- | 39 |
40 - - - C o n v e r s i o n s - - - | 40 /* --------------------------------- |
41 ------------------------------------- | 41 - - - U t i l i t i e s - - - |
| 42 --------------------------------- |
42 */ | 43 */ |
43 | 44 |
44 // ES5, section 9.12 | |
45 function SameValue(x, y) { | |
46 if (typeof x !== typeof y) return false; | |
47 if (IS_NUMBER(x)) { | |
48 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; | |
49 // x is +0 and y is -0 or vice versa. | |
50 if (x === 0 && y === 0 && 1/x !== 1/y) { | |
51 return false; | |
52 } | |
53 } | |
54 if (IS_SIMD_VALUE(x)) return %SimdSameValue(x, y); | |
55 return x === y; | |
56 } | |
57 | |
58 | |
59 // ES6, section 7.2.4 | |
60 function SameValueZero(x, y) { | |
61 if (typeof x !== typeof y) return false; | |
62 if (IS_NUMBER(x)) { | |
63 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; | |
64 } | |
65 if (IS_SIMD_VALUE(x)) return %SimdSameValueZero(x, y); | |
66 return x === y; | |
67 } | |
68 | |
69 | |
70 function ConcatIterableToArray(target, iterable) { | 45 function ConcatIterableToArray(target, iterable) { |
71 var index = target.length; | 46 var index = target.length; |
72 for (var element of iterable) { | 47 for (var element of iterable) { |
73 AddIndexedProperty(target, index++, element); | 48 AddIndexedProperty(target, index++, element); |
74 } | 49 } |
75 return target; | 50 return target; |
76 } | 51 } |
77 | 52 |
78 | 53 |
79 /* --------------------------------- | |
80 - - - U t i l i t i e s - - - | |
81 --------------------------------- | |
82 */ | |
83 | |
84 | |
85 // This function should be called rather than %AddElement in contexts where the | 54 // This function should be called rather than %AddElement in contexts where the |
86 // argument might not be less than 2**32-1. ES2015 ToLength semantics mean that | 55 // argument might not be less than 2**32-1. ES2015 ToLength semantics mean that |
87 // this is a concern at basically all callsites. | 56 // this is a concern at basically all callsites. |
88 function AddIndexedProperty(obj, index, value) { | 57 function AddIndexedProperty(obj, index, value) { |
89 if (index === TO_UINT32(index) && index !== kMaxUint32) { | 58 if (index === TO_UINT32(index) && index !== kMaxUint32) { |
90 %AddElement(obj, index, value); | 59 %AddElement(obj, index, value); |
91 } else { | 60 } else { |
92 %AddNamedProperty(obj, TO_STRING(index), value, NONE); | 61 %AddNamedProperty(obj, TO_STRING(index), value, NONE); |
93 } | 62 } |
94 } | 63 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // boilerplate gets the right prototype. | 126 // boilerplate gets the right prototype. |
158 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); | 127 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); |
159 | 128 |
160 // ---------------------------------------------------------------------------- | 129 // ---------------------------------------------------------------------------- |
161 // Exports | 130 // Exports |
162 | 131 |
163 utils.Export(function(to) { | 132 utils.Export(function(to) { |
164 to.AddIndexedProperty = AddIndexedProperty; | 133 to.AddIndexedProperty = AddIndexedProperty; |
165 to.MaxSimple = MaxSimple; | 134 to.MaxSimple = MaxSimple; |
166 to.MinSimple = MinSimple; | 135 to.MinSimple = MinSimple; |
167 to.SameValue = SameValue; | |
168 to.SameValueZero = SameValueZero; | |
169 to.ToPositiveInteger = ToPositiveInteger; | 136 to.ToPositiveInteger = ToPositiveInteger; |
170 to.SpeciesConstructor = SpeciesConstructor; | 137 to.SpeciesConstructor = SpeciesConstructor; |
171 }); | 138 }); |
172 | 139 |
173 %InstallToContext([ | 140 %InstallToContext([ |
174 "concat_iterable_to_array", ConcatIterableToArray, | 141 "concat_iterable_to_array", ConcatIterableToArray, |
175 ]); | 142 ]); |
176 | 143 |
177 }) | 144 }) |
OLD | NEW |