File: test-heapdump-env.js

package info (click to toggle)
nodejs 20.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 219,072 kB
  • sloc: cpp: 1,277,408; javascript: 565,332; ansic: 129,476; python: 58,536; sh: 3,841; makefile: 2,725; asm: 1,732; perl: 248; lisp: 222; xml: 42
file content (41 lines) | stat: -rw-r--r-- 1,261 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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