node/lib/internal/main/run_main_module.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

24 lines
792 B
JavaScript

'use strict';
const { RegExpPrototypeExec } = primordials;
const {
prepareMainThreadExecution,
markBootstrapComplete
} = require('internal/process/pre_execution');
prepareMainThreadExecution(true);
markBootstrapComplete();
// Necessary to reset RegExp statics before user code runs.
RegExpPrototypeExec(/^/, '');
// Note: this loads the module through the ESM loader if the module is
// determined to be an ES module. This hangs from the CJS module loader
// because we currently allow monkey-patching of the module loaders
// in the preloaded scripts through require('module').
// runMain here might be monkey-patched by users in --require.
// XXX: the monkey-patchability here should probably be deprecated.
require('internal/modules/cjs/loader').Module.runMain(process.argv[1]);