diff --git a/src/objects/js-function.cc b/src/objects/js-function.cc index 62e21a99c04c..63efffa94fe1 100644 --- a/src/objects/js-function.cc +++ b/src/objects/js-function.cc @@ -676,6 +676,10 @@ void SetInstancePrototype(Isolate* isolate, Handle function, // At that point, a new initial map is created and the prototype is put // into the initial map where it belongs. function->set_prototype_or_initial_map(*value, kReleaseStore); + if (value->IsJSObjectThatCanBeTrackedAsPrototype()) { + // Optimize as prototype to detach it from its transition tree. + JSObject::OptimizeAsPrototype(Handle::cast(value)); + } } else { Handle new_map = Map::Copy(isolate, initial_map, "SetInstancePrototype"); @@ -808,8 +812,10 @@ void JSFunction::EnsureHasInitialMap(Handle function) { Handle prototype; if (function->has_instance_prototype()) { prototype = handle(function->instance_prototype(), isolate); + map->set_prototype(*prototype); } else { prototype = isolate->factory()->NewFunctionPrototype(function); + Map::SetPrototype(isolate, map, prototype); } DCHECK(map->has_fast_object_elements());