Chromium Code Reviews| 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; | |
| 19 var GlobalArray = global.Array; | 20 var GlobalArray = global.Array; |
| 20 var GlobalBoolean = global.Boolean; | 21 var GlobalBoolean = global.Boolean; |
| 21 var GlobalString = global.String; | 22 var GlobalString = global.String; |
| 22 var isConcatSpreadableSymbol = | |
| 23 utils.ImportNow("is_concat_spreadable_symbol"); | |
| 24 var MakeRangeError; | 23 var MakeRangeError; |
| 24 var MakeTypeError; | |
| 25 var speciesSymbol; | |
| 25 | 26 |
| 26 utils.Import(function(from) { | 27 utils.Import(function(from) { |
| 27 MakeRangeError = from.MakeRangeError; | 28 MakeRangeError = from.MakeRangeError; |
| 29 MakeTypeError = from.MakeTypeError; | |
| 30 speciesSymbol = from.species_symbol; | |
| 31 }); | |
| 32 | |
| 33 utils.ImportFromExperimental(function(from) { | |
| 34 FLAG_harmony_species = from.FLAG_harmony_species; | |
| 28 }); | 35 }); |
| 29 | 36 |
| 30 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
| 31 | 38 |
| 32 /* ----------------------------- | 39 /* ----------------------------- |
| 33 - - - H e l p e r s - - - | 40 - - - H e l p e r s - - - |
| 34 ----------------------------- | 41 ----------------------------- |
| 35 */ | 42 */ |
| 36 | 43 |
| 37 function CONCAT_ITERABLE_TO_ARRAY(iterable) { | 44 function CONCAT_ITERABLE_TO_ARRAY(iterable) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 111 | 118 |
| 112 | 119 |
| 113 function MinSimple(a, b) { | 120 function MinSimple(a, b) { |
| 114 return a > b ? b : a; | 121 return a > b ? b : a; |
| 115 } | 122 } |
| 116 | 123 |
| 117 | 124 |
| 118 %SetForceInlineFlag(MaxSimple); | 125 %SetForceInlineFlag(MaxSimple); |
| 119 %SetForceInlineFlag(MinSimple); | 126 %SetForceInlineFlag(MinSimple); |
| 120 | 127 |
| 128 | |
| 129 // ES2015 7.3.20 | |
| 130 // For the fallback with --harmony-species off, there are two possible choices: | |
| 131 // - "conservative": return defaultConstructor | |
| 132 // - "not conservative": return object.constructor | |
| 133 // This fallback path is only needed in the transition to ES2015, and the | |
| 134 // choice is made simply to preserve the previous behavior so that we don't | |
| 135 // have a three-step upgrade: old behavior, unspecified intermediate behavior, | |
| 136 // and ES2015. | |
| 137 // In some cases, we were "conservative" (e.g., ArrayBuffer, RegExp), and in | |
| 138 // other cases we were "not conservative (e.g., TypedArray, Promise). | |
| 139 function SpeciesConstructor(object, defaultConstructor, conservative) { | |
| 140 if (FLAG_harmony_species) { | |
| 141 var constructor = object.constructor; | |
| 142 if (IS_UNDEFINED(constructor)) { | |
| 143 return defaultConstructor; | |
| 144 } | |
| 145 if (!IS_RECEIVER(constructor)) { | |
| 146 throw MakeTypeError(kSpeciesNotConstructor); | |
|
adamk
2016/01/12 00:11:00
This error message seems wrong here, since @@speci
Dan Ehrenberg
2016/01/12 01:38:33
Added a separate error message.
| |
| 147 } | |
| 148 var species = constructor[speciesSymbol]; | |
| 149 if (IS_NULL_OR_UNDEFINED(species)) { | |
| 150 return defaultConstructor; | |
| 151 } | |
| 152 if (%IsConstructor(species)) { | |
| 153 return species; | |
| 154 } | |
| 155 throw MakeTypeError(kSpeciesNotConstructor); | |
| 156 } else { | |
| 157 return conservative ? defaultConstructor : object.constructor; | |
| 158 } | |
| 159 } | |
| 160 | |
| 121 //---------------------------------------------------------------------------- | 161 //---------------------------------------------------------------------------- |
| 122 | 162 |
| 123 // NOTE: Setting the prototype for Array must take place as early as | 163 // NOTE: Setting the prototype for Array must take place as early as |
| 124 // possible due to code generation for array literals. When | 164 // possible due to code generation for array literals. When |
| 125 // generating code for a array literal a boilerplate array is created | 165 // generating code for a array literal a boilerplate array is created |
| 126 // that is cloned when running the code. It is essential that the | 166 // that is cloned when running the code. It is essential that the |
| 127 // boilerplate gets the right prototype. | 167 // boilerplate gets the right prototype. |
| 128 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); | 168 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); |
| 129 | 169 |
| 130 // ---------------------------------------------------------------------------- | 170 // ---------------------------------------------------------------------------- |
| 131 // Exports | 171 // Exports |
| 132 | 172 |
| 133 utils.Export(function(to) { | 173 utils.Export(function(to) { |
| 134 to.AddIndexedProperty = AddIndexedProperty; | 174 to.AddIndexedProperty = AddIndexedProperty; |
| 135 to.MaxSimple = MaxSimple; | 175 to.MaxSimple = MaxSimple; |
| 136 to.MinSimple = MinSimple; | 176 to.MinSimple = MinSimple; |
| 137 to.SameValue = SameValue; | 177 to.SameValue = SameValue; |
| 138 to.SameValueZero = SameValueZero; | 178 to.SameValueZero = SameValueZero; |
| 139 to.ToPositiveInteger = ToPositiveInteger; | 179 to.ToPositiveInteger = ToPositiveInteger; |
| 180 to.SpeciesConstructor = SpeciesConstructor; | |
| 140 }); | 181 }); |
| 141 | 182 |
| 142 %InstallToContext([ | 183 %InstallToContext([ |
| 143 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, | 184 "concat_iterable_to_array_builtin", CONCAT_ITERABLE_TO_ARRAY, |
| 144 ]); | 185 ]); |
| 145 | 186 |
| 146 %InstallToContext([ | 187 %InstallToContext([ |
| 147 "concat_iterable_to_array", ConcatIterableToArray, | 188 "concat_iterable_to_array", ConcatIterableToArray, |
| 148 ]); | 189 ]); |
| 149 | 190 |
| 150 }) | 191 }) |
| OLD | NEW |