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

Unified Diff: src/objects.cc

Issue 1560763002: Add Array support for @@species and subclassing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Some fixes 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
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 8286e1ba4939cdbec62f87fb63010b3a1442a4f5..c48722bffd2ed1f05fd096b0d5852fd42878c656 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1605,6 +1605,54 @@ bool Object::SameValueZero(Object* other) {
}
+MaybeHandle<Object> Object::ArraySpeciesConstructor(
+ Isolate* isolate, Handle<Object> originalArray) {
adamk 2016/01/06 00:10:12 original_array
Dan Ehrenberg 2016/01/07 00:42:58 Done
+ Context* native_context = isolate->context()->native_context();
adamk 2016/01/06 00:10:12 Please stuff this in a handle immediately; raw poi
Dan Ehrenberg 2016/01/07 00:42:58 Oops, fixed (turns out the Handle API is more ergo
+ if (!FLAG_harmony_species) {
+ return Handle<Object>(native_context->array_function(), isolate);
+ }
+ Handle<Object> constructor(isolate->heap()->undefined_value(), isolate);
adamk 2016/01/06 00:10:12 isolate->factory()->undefined_value() will hand yo
Dan Ehrenberg 2016/01/07 00:42:58 Done
+ Maybe<bool> is_array = Object::IsArray(originalArray);
+ MAYBE_RETURN_NULL(is_array);
+ if (is_array.FromJust()) {
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, constructor,
+ Object::GetProperty(isolate, originalArray, "constructor", STRICT),
adamk 2016/01/06 00:10:12 You can make this slightly faster by using a diffe
Dan Ehrenberg 2016/01/07 00:42:58 Done
+ Object);
+ if (constructor->IsConstructor()) {
+ Context* constructor_context =
adamk 2016/01/06 00:10:12 Again, please store in a handle.
Dan Ehrenberg 2016/01/07 00:42:58 Done
+ JSFunction::cast(*constructor)->context()->native_context();
+ if (constructor_context != native_context &&
+ *constructor == constructor_context->array_function()) {
+ constructor =
+ Handle<Object>(isolate->heap()->undefined_value(), isolate);
adamk 2016/01/06 00:10:12 isolate->factory()->undefined_value()
Dan Ehrenberg 2016/01/07 00:42:58 Done
+ }
+ }
+ if (constructor->IsJSReceiver()) {
+ ASSIGN_RETURN_ON_EXCEPTION(
+ isolate, constructor,
+ Object::GetProperty(constructor,
+ Handle<Name>(isolate->heap()->species_symbol())),
adamk 2016/01/06 00:10:12 isolate->factory()->species_symbol()
Dan Ehrenberg 2016/01/07 00:42:58 Done
+ Object);
+ if (constructor->IsNull()) {
+ constructor =
+ Handle<Object>(isolate->heap()->undefined_value(), isolate);
adamk 2016/01/06 00:10:12 factory version
Dan Ehrenberg 2016/01/07 00:42:58 Done
+ }
+ }
+ }
+ if (constructor->IsUndefined()) {
+ return Handle<Object>(native_context->array_function(), isolate);
+ } else {
+ if (!constructor->IsConstructor()) {
+ isolate->Throw(*isolate->factory()->NewTypeError(
adamk 2016/01/06 00:10:12 I think you want to return what Throw() returns. A
Dan Ehrenberg 2016/01/07 00:42:57 Fixed
+ MessageTemplate::kSpeciesNotConstructor));
+ return MaybeHandle<Object>();
+ }
+ return constructor;
+ }
+}
+
+
void Object::ShortPrint(FILE* out) {
OFStream os(out);
os << Brief(this);

Powered by Google App Engine
This is Rietveld 408576698