Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index 716694bdfe96b3c016887c54209d34265b2b519f..47c79b5e73e093eded54e085dccad0a3327c6704 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -9976,6 +9976,19 @@ void JSObject::OptimizeAsPrototype(Handle<JSObject> object, |
Handle<Map> new_map = Map::Copy(handle(object->map()), "CopyAsPrototype"); |
JSObject::MigrateToMap(object, new_map); |
} |
+ if (object->map()->constructor()->IsJSFunction()) { |
+ JSFunction* constructor = JSFunction::cast(object->map()->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. |
+ if (!constructor->shared()->IsApiFunction() && |
+ object->class_name() == |
+ object->GetIsolate()->heap()->Object_string()) { |
+ Context* context = constructor->context()->native_context(); |
+ JSFunction* object_function = context->object_function(); |
+ object->map()->set_constructor(object_function); |
+ } |
+ } |
object->map()->set_is_prototype_map(true); |
} |
} |