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 |
11 | 11 |
12 // The following declarations are shared with other native JS files. | 12 // The following declarations are shared with other native JS files. |
13 // They are all declared at this one spot to avoid redeclaration errors. | 13 // They are all declared at this one spot to avoid redeclaration errors. |
14 | 14 |
15 (function(global, utils) { | 15 (function(global, utils) { |
16 | 16 |
17 %CheckIsBootstrapping(); | 17 %CheckIsBootstrapping(); |
18 | 18 |
19 var FLAG_harmony_species; | |
20 var GlobalArray = global.Array; | 19 var GlobalArray = global.Array; |
21 var GlobalBoolean = global.Boolean; | 20 var GlobalBoolean = global.Boolean; |
22 var GlobalString = global.String; | 21 var GlobalString = global.String; |
23 var MakeRangeError; | 22 var MakeRangeError; |
24 var MakeTypeError; | 23 var MakeTypeError; |
25 var speciesSymbol; | 24 var speciesSymbol; |
26 | 25 |
27 utils.Import(function(from) { | 26 utils.Import(function(from) { |
28 MakeRangeError = from.MakeRangeError; | 27 MakeRangeError = from.MakeRangeError; |
29 MakeTypeError = from.MakeTypeError; | 28 MakeTypeError = from.MakeTypeError; |
30 speciesSymbol = from.species_symbol; | 29 speciesSymbol = from.species_symbol; |
31 }); | 30 }); |
32 | 31 |
33 utils.ImportFromExperimental(function(from) { | |
34 FLAG_harmony_species = from.FLAG_harmony_species; | |
35 }); | |
36 | |
37 // ---------------------------------------------------------------------------- | 32 // ---------------------------------------------------------------------------- |
38 | 33 |
39 | 34 |
40 /* --------------------------------- | 35 /* --------------------------------- |
41 - - - U t i l i t i e s - - - | 36 - - - U t i l i t i e s - - - |
42 --------------------------------- | 37 --------------------------------- |
43 */ | 38 */ |
44 | 39 |
45 | 40 |
46 function ToPositiveInteger(x, rangeErrorIndex) { | 41 function ToPositiveInteger(x, rangeErrorIndex) { |
(...skipping 11 matching lines...) Expand all Loading... |
58 function MinSimple(a, b) { | 53 function MinSimple(a, b) { |
59 return a > b ? b : a; | 54 return a > b ? b : a; |
60 } | 55 } |
61 | 56 |
62 | 57 |
63 %SetForceInlineFlag(MaxSimple); | 58 %SetForceInlineFlag(MaxSimple); |
64 %SetForceInlineFlag(MinSimple); | 59 %SetForceInlineFlag(MinSimple); |
65 | 60 |
66 | 61 |
67 // ES2015 7.3.20 | 62 // ES2015 7.3.20 |
68 // For the fallback with --harmony-species off, there are two possible choices: | 63 function SpeciesConstructor(object, defaultConstructor) { |
69 // - "conservative": return defaultConstructor | 64 var constructor = object.constructor; |
70 // - "not conservative": return object.constructor | 65 if (IS_UNDEFINED(constructor)) { |
71 // This fallback path is only needed in the transition to ES2015, and the | 66 return defaultConstructor; |
72 // choice is made simply to preserve the previous behavior so that we don't | |
73 // have a three-step upgrade: old behavior, unspecified intermediate behavior, | |
74 // and ES2015. | |
75 // In some cases, we were "conservative" (e.g., ArrayBuffer, RegExp), and in | |
76 // other cases we were "not conservative (e.g., TypedArray, Promise). | |
77 function SpeciesConstructor(object, defaultConstructor, conservative) { | |
78 if (FLAG_harmony_species) { | |
79 var constructor = object.constructor; | |
80 if (IS_UNDEFINED(constructor)) { | |
81 return defaultConstructor; | |
82 } | |
83 if (!IS_RECEIVER(constructor)) { | |
84 throw MakeTypeError(kConstructorNotReceiver); | |
85 } | |
86 var species = constructor[speciesSymbol]; | |
87 if (IS_NULL_OR_UNDEFINED(species)) { | |
88 return defaultConstructor; | |
89 } | |
90 if (%IsConstructor(species)) { | |
91 return species; | |
92 } | |
93 throw MakeTypeError(kSpeciesNotConstructor); | |
94 } else { | |
95 return conservative ? defaultConstructor : object.constructor; | |
96 } | 67 } |
| 68 if (!IS_RECEIVER(constructor)) { |
| 69 throw MakeTypeError(kConstructorNotReceiver); |
| 70 } |
| 71 var species = constructor[speciesSymbol]; |
| 72 if (IS_NULL_OR_UNDEFINED(species)) { |
| 73 return defaultConstructor; |
| 74 } |
| 75 if (%IsConstructor(species)) { |
| 76 return species; |
| 77 } |
| 78 throw MakeTypeError(kSpeciesNotConstructor); |
97 } | 79 } |
98 | 80 |
99 //---------------------------------------------------------------------------- | 81 //---------------------------------------------------------------------------- |
100 | 82 |
101 // NOTE: Setting the prototype for Array must take place as early as | 83 // NOTE: Setting the prototype for Array must take place as early as |
102 // possible due to code generation for array literals. When | 84 // possible due to code generation for array literals. When |
103 // generating code for a array literal a boilerplate array is created | 85 // generating code for a array literal a boilerplate array is created |
104 // that is cloned when running the code. It is essential that the | 86 // that is cloned when running the code. It is essential that the |
105 // boilerplate gets the right prototype. | 87 // boilerplate gets the right prototype. |
106 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); | 88 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); |
107 | 89 |
108 // ---------------------------------------------------------------------------- | 90 // ---------------------------------------------------------------------------- |
109 // Exports | 91 // Exports |
110 | 92 |
111 utils.Export(function(to) { | 93 utils.Export(function(to) { |
112 to.MaxSimple = MaxSimple; | 94 to.MaxSimple = MaxSimple; |
113 to.MinSimple = MinSimple; | 95 to.MinSimple = MinSimple; |
114 to.ToPositiveInteger = ToPositiveInteger; | 96 to.ToPositiveInteger = ToPositiveInteger; |
115 to.SpeciesConstructor = SpeciesConstructor; | 97 to.SpeciesConstructor = SpeciesConstructor; |
116 }); | 98 }); |
117 | 99 |
118 }) | 100 }) |
OLD | NEW |