mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 16:34:41 +00:00

The C++ implementation can now be done entirely in JS using WeakRef. Re-implement it in JS instead to simplify the code. PR-URL: https://github.com/nodejs/node/pull/49053 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
19 lines
429 B
JavaScript
19 lines
429 B
JavaScript
// Flags: --expose-internals --expose-gc
|
|
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { WeakReference } = require('internal/util');
|
|
|
|
let obj = { hello: 'world' };
|
|
const ref = new WeakReference(obj);
|
|
assert.strictEqual(ref.get(), obj);
|
|
|
|
async function main() {
|
|
obj = null;
|
|
await common.gcUntil(
|
|
'Reference is garbage collected',
|
|
() => ref.get() === undefined);
|
|
}
|
|
|
|
main();
|