node/test/pummel/test-heapdump-env.js
Chengzhong Wu e6b4d30a2f
src: bootstrap Web [Exposed=*] APIs in the shadow realm
This is the initial work to bootstrap Web interfaces that are defined
with extended attributes `[Exposed=*]`.

The ShadowRealm instances are garbage-collected once it is
unreachable. However, V8 can not infer the reference cycles between
the per-realm strong persistent function handles and the realm's
context handle. To allow the context to be gc-ed once it is not
reachable, the per-realm persistent handles are attached to the
context's global object and the persistent handles are set as weak.

PR-URL: https://github.com/nodejs/node/pull/46809
Refs: https://github.com/nodejs/node/issues/42528
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2023-03-16 00:22:06 +08:00

42 lines
1.2 KiB
JavaScript

// Flags: --expose-internals
'use strict';
// This tests that Environment is tracked in heap snapshots.
require('../common');
const { validateSnapshotNodes } = require('../common/heap');
// This is just using ContextifyScript as an example here, it can be replaced
// with any BaseObject that we can easily instantiate here and register in
// cleanup hooks.
// These can all be changed to reflect the status of how these objects
// are captured in the snapshot.
const context = require('vm').createScript('const foo = 123');
validateSnapshotNodes('Node / Environment', [{
children: [
{ node_name: 'Node / CleanupQueue', edge_name: 'cleanup_queue' },
{ node_name: 'Node / IsolateData', edge_name: 'isolate_data' },
{ node_name: 'Node / PrincipalRealm', edge_name: 'principal_realm' },
],
}]);
validateSnapshotNodes('Node / CleanupQueue', [
// The first one is the cleanup_queue of the Environment.
{},
// The second one is the cleanup_queue of the principal realm.
{
children: [
{ node_name: 'Node / ContextifyScript' },
],
},
]);
validateSnapshotNodes('Node / PrincipalRealm', [{
children: [
{ node_name: 'process', edge_name: 'process_object' },
],
}]);
console.log(context); // Make sure it's not GC'ed