node/test/parallel/test-shadow-realm-gc.js
legendecas ac0853c4ee src: make realm binding data store weak
The binding data must be weak so that it won't keep the realm reachable
from strong GC roots indefinitely. The wrapper object of binding data
should be referenced from JavaScript, thus the binding data should be
reachable throughout the lifetime of the realm.

PR-URL: https://github.com/nodejs/node/pull/47688
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-06-14 02:05:00 +00:00

23 lines
553 B
JavaScript

// Flags: --experimental-shadow-realm --max-old-space-size=20
'use strict';
/**
* Verifying ShadowRealm instances can be correctly garbage collected.
*/
const common = require('../common');
const assert = require('assert');
const { isMainThread, Worker } = require('worker_threads');
for (let i = 0; i < 100; i++) {
const realm = new ShadowRealm();
realm.evaluate('new TextEncoder(); 1;');
}
if (isMainThread) {
const worker = new Worker(__filename);
worker.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 0);
}));
}