Skip to content

Commit a1efa53

Browse files
verwaestV8 LUCI CQ
authored andcommitted
Merged: [runtime] Set instance prototypes directly on maps
Bug: chromium:1452137 (cherry picked from commit c7c4477) Change-Id: I611c41f942e2e51f3c4b4f1d119c18410617188e Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4637888 Commit-Queue: Igor Sheludko <[email protected]> Auto-Submit: Igor Sheludko <[email protected]> Commit-Queue: Toon Verwaest <[email protected]> Reviewed-by: Toon Verwaest <[email protected]> Cr-Commit-Position: refs/branch-heads/11.4@{#47} Cr-Branched-From: 8a8a1e7-refs/heads/11.4.183@{#1} Cr-Branched-From: 5483d8e-refs/heads/main@{#87241}
1 parent 3625de4 commit a1efa53

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/objects/js-function.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ void SetInstancePrototype(Isolate* isolate, Handle<JSFunction> function,
676676
// At that point, a new initial map is created and the prototype is put
677677
// into the initial map where it belongs.
678678
function->set_prototype_or_initial_map(*value, kReleaseStore);
679+
if (value->IsJSObjectThatCanBeTrackedAsPrototype()) {
680+
// Optimize as prototype to detach it from its transition tree.
681+
JSObject::OptimizeAsPrototype(Handle<JSObject>::cast(value));
682+
}
679683
} else {
680684
Handle<Map> new_map =
681685
Map::Copy(isolate, initial_map, "SetInstancePrototype");
@@ -801,8 +805,10 @@ void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) {
801805
Handle<HeapObject> prototype;
802806
if (function->has_instance_prototype()) {
803807
prototype = handle(function->instance_prototype(), isolate);
808+
map->set_prototype(*prototype);
804809
} else {
805810
prototype = isolate->factory()->NewFunctionPrototype(function);
811+
Map::SetPrototype(isolate, map, prototype);
806812
}
807813
DCHECK(map->has_fast_object_elements());
808814

0 commit comments

Comments
 (0)