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

Unified Diff: src/js/runtime.js

Issue 1470193002: Array/TypedArray/ArrayBuffer method subclassing and @@species (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase 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/regexp.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..3ada50c49b1ac63e131fce62cdc0c3db47445c70 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,30 @@ function MinSimple(a, b) {
%SetForceInlineFlag(MaxSimple);
%SetForceInlineFlag(MinSimple);
+
+// ES2015 7.3.20
+function SpeciesConstructor(object, defaultConstructor) {
+ if (FLAG_harmony_species) {
+ var constructor = object.constructor;
+ if (IS_UNDEFINED(constructor)) {
+ return defaultConstructor;
+ }
+ if (!IS_RECEIVER(constructor)) {
+ throw MakeTypeError(kSpeciesNotConstructor);
+ }
+ var species = constructor[speciesSymbol];
+ if (IS_NULL_OR_UNDEFINED(species)) {
+ return defaultConstructor;
+ }
+ if (%IsConstructor(species)) {
+ return species;
+ }
+ throw MakeTypeError(kSpeciesNotConstructor);
+ } else {
+ return defaultConstructor;
+ }
+}
+
//----------------------------------------------------------------------------
// NOTE: Setting the prototype for Array must take place as early as
@@ -137,6 +168,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/regexp.js ('k') | src/js/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698