• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3
4// This tests that Environment is tracked in heap snapshots.
5
6require('../common');
7const { validateSnapshotNodes } = require('../common/heap');
8
9// This is just using ContextifyScript as an example here, it can be replaced
10// with any BaseObject that we can easily instantiate here and register in
11// cleanup hooks.
12// These can all be changed to reflect the status of how these objects
13// are captured in the snapshot.
14const context = require('vm').createScript('const foo = 123');
15
16validateSnapshotNodes('Node / Environment', [{
17  children: [
18    { node_name: 'Node / CleanupQueue', edge_name: 'cleanup_queue' },
19    { node_name: 'Node / IsolateData', edge_name: 'isolate_data' },
20    { node_name: 'Node / Realm', edge_name: 'principal_realm' },
21  ],
22}]);
23
24validateSnapshotNodes('Node / CleanupQueue', [
25  // The first one is the cleanup_queue of the Environment.
26  {},
27  // The second one is the cleanup_queue of the principal realm.
28  {
29    children: [
30      { node_name: 'Node / ContextifyScript' },
31    ],
32  },
33]);
34
35validateSnapshotNodes('Node / Realm', [{
36  children: [
37    { node_name: 'process', edge_name: 'process_object' },
38  ],
39}]);
40
41console.log(context);  // Make sure it's not GC'ed
42