mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00

Add a simple `WeakReference` utility that we can use until the language provides something on its own. PR-URL: https://github.com/nodejs/node/pull/25993 Fixes: https://github.com/nodejs/node/issues/23862 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Refael Ackermann <refack@gmail.com>
18 lines
427 B
JavaScript
18 lines
427 B
JavaScript
// Flags: --expose-internals --expose-gc
|
|
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { internalBinding } = require('internal/test/binding');
|
|
const { WeakReference } = internalBinding('util');
|
|
|
|
let obj = { hello: 'world' };
|
|
const ref = new WeakReference(obj);
|
|
assert.strictEqual(ref.get(), obj);
|
|
|
|
setImmediate(() => {
|
|
obj = null;
|
|
global.gc();
|
|
|
|
assert.strictEqual(ref.get(), undefined);
|
|
});
|