xref: /third_party/node/test/parallel/test-vm-measure-memory-multi-context.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst {
41cb0ef41Sopenharmony_ci  assertDetailedShape,
51cb0ef41Sopenharmony_ci  expectExperimentalWarning
61cb0ef41Sopenharmony_ci} = require('../common/measure-memory');
71cb0ef41Sopenharmony_ciconst vm = require('vm');
81cb0ef41Sopenharmony_ciconst assert = require('assert');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciexpectExperimentalWarning();
111cb0ef41Sopenharmony_ci{
121cb0ef41Sopenharmony_ci  const arr = [];
131cb0ef41Sopenharmony_ci  const count = 10;
141cb0ef41Sopenharmony_ci  for (let i = 0; i < count; ++i) {
151cb0ef41Sopenharmony_ci    const context = vm.createContext({
161cb0ef41Sopenharmony_ci      test: new Array(100).fill('foo')
171cb0ef41Sopenharmony_ci    });
181cb0ef41Sopenharmony_ci    arr.push(context);
191cb0ef41Sopenharmony_ci  }
201cb0ef41Sopenharmony_ci  // Check that one more context shows up in the result
211cb0ef41Sopenharmony_ci  vm.measureMemory({ mode: 'detailed', execution: 'eager' })
221cb0ef41Sopenharmony_ci    .then(common.mustCall((result) => {
231cb0ef41Sopenharmony_ci      // We must hold on to the contexts here so that they
241cb0ef41Sopenharmony_ci      // don't get GC'ed until the measurement is complete
251cb0ef41Sopenharmony_ci      assert.strictEqual(arr.length, count);
261cb0ef41Sopenharmony_ci      assertDetailedShape(result, count + common.isWindows);
271cb0ef41Sopenharmony_ci    }));
281cb0ef41Sopenharmony_ci}
29

Indexes created Thu Nov 07 10:32:03 CST 2024