11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// This tests that Environment is tracked in heap snapshots.
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cirequire('../common');
71cb0ef41Sopenharmony_ciconst { validateSnapshotNodes } = require('../common/heap');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// This is just using ContextifyScript as an example here, it can be replaced
101cb0ef41Sopenharmony_ci// with any BaseObject that we can easily instantiate here and register in
111cb0ef41Sopenharmony_ci// cleanup hooks.
121cb0ef41Sopenharmony_ci// These can all be changed to reflect the status of how these objects
131cb0ef41Sopenharmony_ci// are captured in the snapshot.
141cb0ef41Sopenharmony_ciconst context = require('vm').createScript('const foo = 123');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_civalidateSnapshotNodes('Node / Environment', [{
171cb0ef41Sopenharmony_ci  children: [
181cb0ef41Sopenharmony_ci    { node_name: 'Node / CleanupQueue', edge_name: 'cleanup_queue' },
191cb0ef41Sopenharmony_ci    { node_name: 'Node / IsolateData', edge_name: 'isolate_data' },
201cb0ef41Sopenharmony_ci    { node_name: 'Node / Realm', edge_name: 'principal_realm' },
211cb0ef41Sopenharmony_ci  ],
221cb0ef41Sopenharmony_ci}]);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_civalidateSnapshotNodes('Node / CleanupQueue', [
251cb0ef41Sopenharmony_ci  // The first one is the cleanup_queue of the Environment.
261cb0ef41Sopenharmony_ci  {},
271cb0ef41Sopenharmony_ci  // The second one is the cleanup_queue of the principal realm.
281cb0ef41Sopenharmony_ci  {
291cb0ef41Sopenharmony_ci    children: [
301cb0ef41Sopenharmony_ci      { node_name: 'Node / ContextifyScript' },
311cb0ef41Sopenharmony_ci    ],
321cb0ef41Sopenharmony_ci  },
331cb0ef41Sopenharmony_ci]);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_civalidateSnapshotNodes('Node / Realm', [{
361cb0ef41Sopenharmony_ci  children: [
371cb0ef41Sopenharmony_ci    { node_name: 'process', edge_name: 'process_object' },
381cb0ef41Sopenharmony_ci  ],
391cb0ef41Sopenharmony_ci}]);
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciconsole.log(context);  // Make sure it's not GC'ed
42