Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 6e9a12001de5ba66e2b4907e72d09637a8906822..137ea98b0b826e256cdd00e9b96cbd7a45821ac0 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -2331,6 +2331,42 @@ MaybeHandle<Object> Object::ArraySpeciesConstructor( |
} |
} |
+// ES6 section 7.3.20 SpeciesConstructor ( O, defaultConstructor ) |
+MUST_USE_RESULT MaybeHandle<Object> Object::SpeciesConstructor( |
+ Isolate* isolate, Handle<JSReceiver> recv, |
+ Handle<JSFunction> default_ctor) { |
+ Handle<Object> ctor_obj; |
+ ASSIGN_RETURN_ON_EXCEPTION( |
+ isolate, ctor_obj, |
+ JSObject::GetProperty(recv, isolate->factory()->constructor_string()), |
+ Object); |
+ |
+ if (ctor_obj->IsUndefined(isolate)) return default_ctor; |
+ |
+ if (!ctor_obj->IsJSReceiver()) { |
+ THROW_NEW_ERROR(isolate, |
+ NewTypeError(MessageTemplate::kConstructorNotReceiver), |
+ Object); |
+ } |
+ |
+ Handle<JSReceiver> ctor = Handle<JSReceiver>::cast(ctor_obj); |
+ |
+ Handle<Object> species; |
+ ASSIGN_RETURN_ON_EXCEPTION( |
+ isolate, species, |
+ JSObject::GetProperty(ctor, isolate->factory()->species_symbol()), |
+ Object); |
+ |
+ if (species->IsNullOrUndefined(isolate)) { |
+ return default_ctor; |
+ } |
+ |
+ if (species->IsConstructor()) return species; |
+ |
+ THROW_NEW_ERROR( |
+ isolate, NewTypeError(MessageTemplate::kSpeciesNotConstructor), Object); |
+} |
+ |
bool Object::IterationHasObservableEffects() { |
// Check that this object is an array. |
if (!IsJSArray()) return true; |