Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(726)

Unified Diff: src/js/runtime.js

Issue 1574903004: TypedArray and ArrayBuffer support for @@species (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Upload tests and make some code more clear Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/js/arraybuffer.js ('k') | src/js/typedarray.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/runtime.js
diff --git a/src/js/runtime.js b/src/js/runtime.js
index af5f2da84cdccd4b2176fe609aca30711feddd7f..301d75a391c2391921489830b18733ea96365cc7 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(kConstructorNotReceiver);
+ }
+ 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([
« no previous file with comments | « src/js/arraybuffer.js ('k') | src/js/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698