2018-10-29 11:53:52 +00:00
|
|
|
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-03-07 15:00:51 +00:00
|
|
|
// Flags: --expose-gc --noincremental-marking
|
2018-10-29 11:53:52 +00:00
|
|
|
|
|
|
|
let r = Realm.create();
|
|
|
|
|
|
|
|
let cleanup = Realm.eval(r, "var stored_global; function cleanup() { stored_global = globalThis; } cleanup");
|
|
|
|
let realm_global_this = Realm.eval(r, "globalThis");
|
|
|
|
|
2020-02-25 01:19:48 +00:00
|
|
|
let fg = new FinalizationRegistry(cleanup);
|
2018-10-29 11:53:52 +00:00
|
|
|
|
2020-02-25 01:19:48 +00:00
|
|
|
// Create an object and a register it in the FinalizationRegistry. The object needs
|
2019-01-30 12:06:32 +00:00
|
|
|
// to be inside a closure so that we can reliably kill them!
|
2018-10-29 11:53:52 +00:00
|
|
|
let weak_cell;
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
let object = {};
|
2019-01-30 12:06:32 +00:00
|
|
|
fg.register(object, {});
|
2018-10-29 11:53:52 +00:00
|
|
|
|
|
|
|
// object goes out of scope.
|
|
|
|
})();
|
|
|
|
|
|
|
|
gc();
|
|
|
|
|
|
|
|
// Assert that the cleanup function was called in its Realm.
|
|
|
|
let timeout_func = function() {
|
|
|
|
let stored_global = Realm.eval(r, "stored_global;");
|
|
|
|
assertNotEquals(stored_global, globalThis);
|
|
|
|
assertEquals(stored_global, realm_global_this);
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(timeout_func, 0);
|