| 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 GlobalArray = global.Array; | 19 var GlobalArray = global.Array; |
| 20 var GlobalBoolean = global.Boolean; | 20 var GlobalBoolean = global.Boolean; |
| 21 var GlobalString = global.String; | 21 var GlobalString = global.String; |
| 22 var MakeRangeError; | |
| 23 var MakeTypeError; | |
| 24 var speciesSymbol; | 22 var speciesSymbol; |
| 25 | 23 |
| 26 utils.Import(function(from) { | 24 utils.Import(function(from) { |
| 27 MakeRangeError = from.MakeRangeError; | |
| 28 MakeTypeError = from.MakeTypeError; | |
| 29 speciesSymbol = from.species_symbol; | 25 speciesSymbol = from.species_symbol; |
| 30 }); | 26 }); |
| 31 | 27 |
| 32 // ---------------------------------------------------------------------------- | 28 // ---------------------------------------------------------------------------- |
| 33 | 29 |
| 34 | 30 |
| 35 /* --------------------------------- | 31 /* --------------------------------- |
| 36 - - - U t i l i t i e s - - - | 32 - - - U t i l i t i e s - - - |
| 37 --------------------------------- | 33 --------------------------------- |
| 38 */ | 34 */ |
| 39 | 35 |
| 40 | 36 |
| 41 function ToPositiveInteger(x, rangeErrorIndex) { | 37 function ToPositiveInteger(x, rangeErrorIndex) { |
| 42 var i = TO_INTEGER(x) + 0; | 38 var i = TO_INTEGER(x) + 0; |
| 43 if (i < 0) throw MakeRangeError(rangeErrorIndex); | 39 if (i < 0) throw %make_range_error(rangeErrorIndex); |
| 44 return i; | 40 return i; |
| 45 } | 41 } |
| 46 | 42 |
| 47 | 43 |
| 48 function MaxSimple(a, b) { | 44 function MaxSimple(a, b) { |
| 49 return a > b ? a : b; | 45 return a > b ? a : b; |
| 50 } | 46 } |
| 51 | 47 |
| 52 | 48 |
| 53 function MinSimple(a, b) { | 49 function MinSimple(a, b) { |
| 54 return a > b ? b : a; | 50 return a > b ? b : a; |
| 55 } | 51 } |
| 56 | 52 |
| 57 | 53 |
| 58 %SetForceInlineFlag(MaxSimple); | 54 %SetForceInlineFlag(MaxSimple); |
| 59 %SetForceInlineFlag(MinSimple); | 55 %SetForceInlineFlag(MinSimple); |
| 60 | 56 |
| 61 | 57 |
| 62 // ES2015 7.3.20 | 58 // ES2015 7.3.20 |
| 63 function SpeciesConstructor(object, defaultConstructor) { | 59 function SpeciesConstructor(object, defaultConstructor) { |
| 64 var constructor = object.constructor; | 60 var constructor = object.constructor; |
| 65 if (IS_UNDEFINED(constructor)) { | 61 if (IS_UNDEFINED(constructor)) { |
| 66 return defaultConstructor; | 62 return defaultConstructor; |
| 67 } | 63 } |
| 68 if (!IS_RECEIVER(constructor)) { | 64 if (!IS_RECEIVER(constructor)) { |
| 69 throw MakeTypeError(kConstructorNotReceiver); | 65 throw %make_type_error(kConstructorNotReceiver); |
| 70 } | 66 } |
| 71 var species = constructor[speciesSymbol]; | 67 var species = constructor[speciesSymbol]; |
| 72 if (IS_NULL_OR_UNDEFINED(species)) { | 68 if (IS_NULL_OR_UNDEFINED(species)) { |
| 73 return defaultConstructor; | 69 return defaultConstructor; |
| 74 } | 70 } |
| 75 if (%IsConstructor(species)) { | 71 if (%IsConstructor(species)) { |
| 76 return species; | 72 return species; |
| 77 } | 73 } |
| 78 throw MakeTypeError(kSpeciesNotConstructor); | 74 throw %make_type_error(kSpeciesNotConstructor); |
| 79 } | 75 } |
| 80 | 76 |
| 81 //---------------------------------------------------------------------------- | 77 //---------------------------------------------------------------------------- |
| 82 | 78 |
| 83 // NOTE: Setting the prototype for Array must take place as early as | 79 // NOTE: Setting the prototype for Array must take place as early as |
| 84 // possible due to code generation for array literals. When | 80 // possible due to code generation for array literals. When |
| 85 // generating code for a array literal a boilerplate array is created | 81 // generating code for a array literal a boilerplate array is created |
| 86 // that is cloned when running the code. It is essential that the | 82 // that is cloned when running the code. It is essential that the |
| 87 // boilerplate gets the right prototype. | 83 // boilerplate gets the right prototype. |
| 88 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); | 84 %FunctionSetPrototype(GlobalArray, new GlobalArray(0)); |
| 89 | 85 |
| 90 // ---------------------------------------------------------------------------- | 86 // ---------------------------------------------------------------------------- |
| 91 // Exports | 87 // Exports |
| 92 | 88 |
| 93 utils.Export(function(to) { | 89 utils.Export(function(to) { |
| 94 to.MaxSimple = MaxSimple; | 90 to.MaxSimple = MaxSimple; |
| 95 to.MinSimple = MinSimple; | 91 to.MinSimple = MinSimple; |
| 96 to.ToPositiveInteger = ToPositiveInteger; | 92 to.ToPositiveInteger = ToPositiveInteger; |
| 97 to.SpeciesConstructor = SpeciesConstructor; | 93 to.SpeciesConstructor = SpeciesConstructor; |
| 98 }); | 94 }); |
| 99 | 95 |
| 100 }) | 96 }) |
| OLD | NEW |