mirror of https://github.com/nodejs/node.git
vm: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/36023 Reviewed-By: Rich Trott <rtrott@gmail.com>pull/36125/head
parent
829786088a
commit
1d02a35869
|
@ -3,15 +3,18 @@
|
|||
const assert = require('internal/assert');
|
||||
const {
|
||||
ArrayIsArray,
|
||||
ArrayPrototypeForEach,
|
||||
ArrayPrototypeIndexOf,
|
||||
ArrayPrototypeSome,
|
||||
ObjectCreate,
|
||||
ObjectDefineProperty,
|
||||
ObjectGetPrototypeOf,
|
||||
ObjectSetPrototypeOf,
|
||||
SafePromise,
|
||||
PromiseAll,
|
||||
SafeWeakMap,
|
||||
Symbol,
|
||||
SymbolToStringTag,
|
||||
TypeError,
|
||||
WeakMap,
|
||||
} = primordials;
|
||||
|
||||
const { isContext } = internalBinding('contextify');
|
||||
|
@ -62,7 +65,7 @@ const STATUS_MAP = {
|
|||
|
||||
let globalModuleId = 0;
|
||||
const defaultModuleName = 'vm:module';
|
||||
const wrapToModuleMap = new WeakMap();
|
||||
const wrapToModuleMap = new SafeWeakMap();
|
||||
|
||||
const kWrap = Symbol('kWrap');
|
||||
const kContext = Symbol('kContext');
|
||||
|
@ -332,7 +335,7 @@ class SourceTextModule extends Module {
|
|||
|
||||
try {
|
||||
if (promises !== undefined) {
|
||||
await SafePromise.all(promises);
|
||||
await PromiseAll(promises);
|
||||
}
|
||||
} catch (e) {
|
||||
this.#error = e;
|
||||
|
@ -392,13 +395,13 @@ class SourceTextModule extends Module {
|
|||
class SyntheticModule extends Module {
|
||||
constructor(exportNames, evaluateCallback, options = {}) {
|
||||
if (!ArrayIsArray(exportNames) ||
|
||||
exportNames.some((e) => typeof e !== 'string')) {
|
||||
ArrayPrototypeSome(exportNames, (e) => typeof e !== 'string')) {
|
||||
throw new ERR_INVALID_ARG_TYPE('exportNames',
|
||||
'Array of unique strings',
|
||||
exportNames);
|
||||
} else {
|
||||
exportNames.forEach((name, i) => {
|
||||
if (exportNames.indexOf(name, i + 1) !== -1) {
|
||||
ArrayPrototypeForEach(exportNames, (name, i) => {
|
||||
if (ArrayPrototypeIndexOf(exportNames, name, i + 1) !== -1) {
|
||||
throw new ERR_INVALID_ARG_VALUE(`exportNames.${name}`,
|
||||
name,
|
||||
'is duplicated');
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
const {
|
||||
ArrayPrototypeForEach,
|
||||
Symbol,
|
||||
PromiseReject
|
||||
PromiseReject,
|
||||
ReflectApply,
|
||||
} = primordials;
|
||||
|
||||
const {
|
||||
|
@ -269,7 +270,7 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
|
|||
process.removeAllListeners('SIGINT');
|
||||
|
||||
try {
|
||||
return fn.apply(thisArg, argsArray);
|
||||
return ReflectApply(fn, thisArg, argsArray);
|
||||
} finally {
|
||||
// Add using the public methods so that the `newListener` handler of
|
||||
// process can re-attach the listeners.
|
||||
|
|
Loading…
Reference in New Issue