node/test/fixtures/snapshot/weak-reference.js
Joyee Cheung 8dcce52c33 lib: implement WeakReference on top of JS WeakRef
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>
2023-08-16 18:45:07 +02:00

15 lines
317 B
JavaScript

'use strict';
const { WeakReference } = require('internal/util');
const {
setDeserializeMainFunction
} = require('v8').startupSnapshot
const assert = require('assert');
let obj = { hello: 'world' };
const ref = new WeakReference(obj);
setDeserializeMainFunction(() => {
assert.strictEqual(ref.get(), obj);
});