Commit 28a5e1c9 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[heap] Keep DroppableApiWrappers alive if used as WeakMap key

This ensures that ApiObjects in V8 are not dropped if they are
currently used as WeakCollection keys. As proxy to determine key
status we use the presence of the identity hash on the object.

R=ulan@chromium.org

Bug: v8:8557, chromium:949244
Change-Id: Ifa0e24be44431a0200fd6a1d9898cd366b940bd5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1557143Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60675}
parent 3b2aa862
......@@ -2553,6 +2553,7 @@ bool JSObject::IsUnmodifiedApiObject(FullObjectSlot o) {
if (!maybe_constructor->IsJSFunction()) return false;
JSFunction constructor = JSFunction::cast(maybe_constructor);
if (js_object->elements()->length() != 0) return false;
if (!js_object->GetIdentityHash()->IsUndefined()) return false;
return constructor->initial_map() == heap_object->map();
}
......
......@@ -310,6 +310,20 @@ TEST(WeakHandleToUnmodifiedJSApiObjectDiesOnScavenge) {
[]() { InvokeScavenge(); }, SurvivalMode::kDies);
}
TEST(WeakHandleToJSApiObjectWithIdentityHashSurvivesScavenge) {
CcTest::InitializeVM();
WeakHandleTest(
CcTest::isolate(), &ConstructJSApiObject,
[](FlagAndPersistent* fp) {
v8::HandleScope scope(CcTest::isolate());
v8::Local<v8::Object> handle =
v8::Local<v8::Object>::New(CcTest::isolate(), fp->handle);
handle->GetIdentityHash();
handle.Clear();
},
[]() { InvokeScavenge(); }, SurvivalMode::kSurvives);
}
TEST(WeakHandleToUnmodifiedJSApiObjectSurvivesScavengeWhenInHandle) {
CcTest::InitializeVM();
WeakHandleTest(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment