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

Unified Diff: src/objects.cc

Issue 1494673004: For non-prototype objects constructed using base==new.target, use the cached constructor to render … (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 3f028c62824a35653bdc4ef03b265f6eedd4413e..c260550b30be28e778d25ee03f3996d07fbd27a2 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -2280,6 +2280,25 @@ String* JSReceiver::class_name() {
// static
Handle<String> JSReceiver::GetConstructorName(Handle<JSReceiver> receiver) {
Isolate* isolate = receiver->GetIsolate();
+
+ // If the object was instantiated simply with base == new.target, the
+ // constructor on the map provides the most accurate name.
+ // Don't provide the info for prototypes, since their constructors are
+ // reclaimed and replaced by Object in OptimizeAsPrototype.
+ if (!receiver->IsJSProxy() && receiver->map()->new_target_is_base() &&
+ !receiver->map()->is_prototype_map()) {
+ Object* maybe_constructor = receiver->map()->GetConstructor();
+ if (maybe_constructor->IsJSFunction()) {
+ JSFunction* constructor = JSFunction::cast(maybe_constructor);
+ String* name = String::cast(constructor->shared()->name());
+ if (name->length() == 0) name = constructor->shared()->inferred_name();
+ if (name->length() != 0 &&
+ !name->Equals(isolate->heap()->Object_string())) {
+ return handle(name, isolate);
+ }
+ }
+ }
+
if (FLAG_harmony_tostring) {
Handle<Object> maybe_tag = JSReceiver::GetDataProperty(
receiver, isolate->factory()->to_string_tag_symbol());
@@ -2296,14 +2315,8 @@ Handle<String> JSReceiver::GetConstructorName(Handle<JSReceiver> receiver) {
if (maybe_constructor->IsJSFunction()) {
JSFunction* constructor = JSFunction::cast(*maybe_constructor);
String* name = String::cast(constructor->shared()->name());
- if (name->length() > 0) {
- result = handle(name, isolate);
- } else {
- String* inferred_name = constructor->shared()->inferred_name();
- if (inferred_name->length() > 0) {
- result = handle(inferred_name, isolate);
- }
- }
+ if (name->length() == 0) name = constructor->shared()->inferred_name();
+ if (name->length() > 0) result = handle(name, isolate);
}
return result.is_identical_to(isolate->factory()->Object_string())
@@ -12575,6 +12588,7 @@ MaybeHandle<Map> JSFunction::GetDerivedMap(Isolate* isolate,
isolate, prototype,
JSReceiver::GetProperty(new_target_proxy, prototype_string), Map);
Handle<Map> map = Map::CopyInitialMap(constructor_initial_map);
+ map->set_new_target_is_base(false);
if (!prototype->IsJSReceiver()) {
Handle<Context> context;
@@ -12626,6 +12640,7 @@ MaybeHandle<Map> JSFunction::GetDerivedMap(Isolate* isolate,
Handle<Map> map =
Map::CopyInitialMap(constructor_initial_map, instance_size,
in_object_properties, unused_property_fields);
+ map->set_new_target_is_base(false);
JSFunction::SetInitialMap(new_target_function, map, prototype);
map->SetConstructor(*constructor);
@@ -12648,6 +12663,7 @@ MaybeHandle<Map> JSFunction::GetDerivedMap(Isolate* isolate,
}
Handle<Map> map = Map::CopyInitialMap(constructor_initial_map);
+ map->set_new_target_is_base(false);
DCHECK(prototype->IsJSReceiver());
if (map->prototype() != *prototype) {
Map::SetPrototype(map, prototype, FAST_PROTOTYPE);
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698