Chromium Code Reviews| Index: src/js/runtime.js |
| diff --git a/src/js/runtime.js b/src/js/runtime.js |
| index af5f2da84cdccd4b2176fe609aca30711feddd7f..730fd834da961f68e98d0f749b85ccdecef7c253 100644 |
| --- a/src/js/runtime.js |
| +++ b/src/js/runtime.js |
| @@ -16,15 +16,22 @@ |
| %CheckIsBootstrapping(); |
| +var FLAG_harmony_species; |
| var GlobalArray = global.Array; |
| var GlobalBoolean = global.Boolean; |
| var GlobalString = global.String; |
| -var isConcatSpreadableSymbol = |
| - utils.ImportNow("is_concat_spreadable_symbol"); |
| var MakeRangeError; |
| +var MakeTypeError; |
| +var speciesSymbol; |
| utils.Import(function(from) { |
| MakeRangeError = from.MakeRangeError; |
| + MakeTypeError = from.MakeTypeError; |
| + speciesSymbol = from.species_symbol; |
| +}); |
| + |
| +utils.ImportFromExperimental(function(from) { |
| + FLAG_harmony_species = from.FLAG_harmony_species; |
| }); |
| // ---------------------------------------------------------------------------- |
| @@ -118,6 +125,39 @@ function MinSimple(a, b) { |
| %SetForceInlineFlag(MaxSimple); |
| %SetForceInlineFlag(MinSimple); |
| + |
| +// ES2015 7.3.20 |
| +// For the fallback with --harmony-species off, there are two possible choices: |
| +// - "conservative": return defaultConstructor |
| +// - "not conservative": return object.constructor |
| +// This fallback path is only needed in the transition to ES2015, and the |
| +// choice is made simply to preserve the previous behavior so that we don't |
| +// have a three-step upgrade: old behavior, unspecified intermediate behavior, |
| +// and ES2015. |
| +// In some cases, we were "conservative" (e.g., ArrayBuffer, RegExp), and in |
| +// other cases we were "not conservative (e.g., TypedArray, Promise). |
| +function SpeciesConstructor(object, defaultConstructor, conservative) { |
| + if (FLAG_harmony_species) { |
| + var constructor = object.constructor; |
| + if (IS_UNDEFINED(constructor)) { |
| + return defaultConstructor; |
| + } |
| + if (!IS_RECEIVER(constructor)) { |
| + 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.
|
| + } |
| + var species = constructor[speciesSymbol]; |
| + if (IS_NULL_OR_UNDEFINED(species)) { |
| + return defaultConstructor; |
| + } |
| + if (%IsConstructor(species)) { |
| + return species; |
| + } |
| + throw MakeTypeError(kSpeciesNotConstructor); |
| + } else { |
| + return conservative ? defaultConstructor : object.constructor; |
| + } |
| +} |
| + |
| //---------------------------------------------------------------------------- |
| // NOTE: Setting the prototype for Array must take place as early as |
| @@ -137,6 +177,7 @@ utils.Export(function(to) { |
| to.SameValue = SameValue; |
| to.SameValueZero = SameValueZero; |
| to.ToPositiveInteger = ToPositiveInteger; |
| + to.SpeciesConstructor = SpeciesConstructor; |
| }); |
| %InstallToContext([ |