[test] Fix WeakGlobalHandle test with --stress-concurrent-allocation

Use Global instead of Persistent such that GlobalHandle is reset at the
end of the function. Persistent doesn't reset in the destructor,
which means that the GC resets the GlobalHandle. With
--stress-concurrent-allocation this might not happen in the test
function itself but when the cctest framework itself works through
the event queue. At that point the Persistent isn't live anymore.

Bug: v8:10315
Change-Id: If77388ad5acb80538852beca0ab22a4ebaf0b5c1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2426612
Commit-Queue: Dominik Inführ <dinfuehr@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70111}
This commit is contained in:
Dominik Inführ 2020-09-24 00:10:06 +02:00 committed by Commit Bot
parent 18da08757f
commit d17b83e5df

View File

@ -2445,27 +2445,18 @@ bool HasWeakGlobalHandle() {
}
static void PersistentHandleCallback(
const v8::WeakCallbackInfo<v8::Persistent<v8::Object> >& data) {
data.GetParameter()->Reset();
}
TEST(WeakGlobalHandle) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
CHECK(!HasWeakGlobalHandle());
v8::Persistent<v8::Object> handle;
v8::Global<v8::Object> handle;
handle.Reset(env->GetIsolate(), v8::Object::New(env->GetIsolate()));
handle.SetWeak(&handle, PersistentHandleCallback,
v8::WeakCallbackType::kParameter);
handle.SetWeak();
CHECK(HasWeakGlobalHandle());
CcTest::CollectAllGarbage();
EmptyMessageQueues(env->GetIsolate());
}