node/test/parallel/test-vm-measure-memory-multi-context.js
Antoine du Hamel 464d1c1558
lib: reset RegExp statics before running user code
Fixes: https://github.com/nodejs/node/issues/43740

PR-URL: https://github.com/nodejs/node/pull/43741
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-08-05 10:01:32 +02:00

29 lines
822 B
JavaScript

'use strict';
const common = require('../common');
const {
assertDetailedShape,
expectExperimentalWarning
} = require('../common/measure-memory');
const vm = require('vm');
const assert = require('assert');
expectExperimentalWarning();
{
const arr = [];
const count = 10;
for (let i = 0; i < count; ++i) {
const context = vm.createContext({
test: new Array(100).fill('foo')
});
arr.push(context);
}
// Check that one more context shows up in the result
vm.measureMemory({ mode: 'detailed', execution: 'eager' })
.then(common.mustCall((result) => {
// We must hold on to the contexts here so that they
// don't get GC'ed until the measurement is complete
assert.strictEqual(arr.length, count);
assertDetailedShape(result, count + common.isWindows);
}));
}