mirror of
https://github.com/nodejs/node.git
synced 2025-05-03 11:12:55 +00:00

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>
23 lines
553 B
JavaScript
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);
|
|
}));
|
|
}
|