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

Unified Diff: src/objects.cc

Issue 1097113003: Fix unobservable constructor replacement on prototype maps (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: new approach: use prototype_info Created 5 years, 8 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/objects.h ('k') | src/objects-debug.cc » ('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 99bf6534f2b35bb543cf2ec6f306be0997c0a063..c0799264abf20be4ffecf133186af188fdc98a2c 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1697,6 +1697,12 @@ String* JSReceiver::class_name() {
String* Map::constructor_name() {
+ if (is_prototype_map() && prototype_info()->IsPrototypeInfo()) {
+ PrototypeInfo* proto_info = PrototypeInfo::cast(prototype_info());
+ if (proto_info->constructor_name()->IsString()) {
+ return String::cast(proto_info->constructor_name());
+ }
+ }
Object* maybe_constructor = GetConstructor();
if (maybe_constructor->IsJSFunction()) {
JSFunction* constructor = JSFunction::cast(maybe_constructor);
@@ -10061,21 +10067,26 @@ void JSObject::OptimizeAsPrototype(Handle<JSObject> object,
Handle<Map> new_map = Map::Copy(handle(object->map()), "CopyAsPrototype");
JSObject::MigrateToMap(object, new_map);
}
+ object->map()->set_is_prototype_map(true);
+
+ // Replace the pointer to the exact constructor with the Object function
+ // from the same context if undetectable from JS. This is to avoid keeping
+ // memory alive unnecessarily.
Object* maybe_constructor = object->map()->GetConstructor();
if (maybe_constructor->IsJSFunction()) {
JSFunction* constructor = JSFunction::cast(maybe_constructor);
- // Replace the pointer to the exact constructor with the Object function
- // from the same context if undetectable from JS. This is to avoid keeping
- // memory alive unnecessarily.
+ Isolate* isolate = object->GetIsolate();
if (!constructor->shared()->IsApiFunction() &&
- object->class_name() ==
- object->GetIsolate()->heap()->Object_string()) {
+ object->class_name() == isolate->heap()->Object_string()) {
+ Handle<String> constructor_name(object->constructor_name(), isolate);
Context* context = constructor->context()->native_context();
JSFunction* object_function = context->object_function();
object->map()->SetConstructor(object_function);
+ Handle<PrototypeInfo> proto_info =
+ Map::GetOrCreatePrototypeInfo(object, isolate);
+ proto_info->set_constructor_name(*constructor_name);
}
}
- object->map()->set_is_prototype_map(true);
}
}
« no previous file with comments | « src/objects.h ('k') | src/objects-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698