-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple `WeakReference` utility that we can use until the language provides something on its own. PR-URL: #25993 Fixes: #23862 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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); | ||
}); |