vm: refactor to avoid unsafe array iteration

PR-URL: https://github.com/nodejs/node/pull/36752
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Antoine du Hamel 2020-12-31 13:12:33 +01:00
parent 7c37e046eb
commit e70e793404
2 changed files with 9 additions and 7 deletions

View File

@ -11,6 +11,7 @@ const {
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
PromiseAll,
ReflectApply,
SafeWeakMap,
Symbol,
SymbolToStringTag,
@ -445,7 +446,7 @@ class SyntheticModule extends Module {
function importModuleDynamicallyWrap(importModuleDynamically) {
const importModuleDynamicallyWrapper = async (...args) => {
const m = await importModuleDynamically(...args);
const m = await ReflectApply(importModuleDynamically, this, args);
if (isModuleNamespaceObject(m)) {
return m;
}

View File

@ -23,6 +23,7 @@
const {
ArrayPrototypeForEach,
ArrayPrototypeUnshift,
Symbol,
PromiseReject,
ReflectApply,
@ -130,17 +131,17 @@ class Script extends ContextifyScript {
if (breakOnSigint && process.listenerCount('SIGINT') > 0) {
return sigintHandlersWrap(super.runInThisContext, this, args);
}
return super.runInThisContext(...args);
return ReflectApply(super.runInThisContext, this, args);
}
runInContext(contextifiedObject, options) {
validateContext(contextifiedObject);
const { breakOnSigint, args } = getRunInContextArgs(options);
ArrayPrototypeUnshift(args, contextifiedObject);
if (breakOnSigint && process.listenerCount('SIGINT') > 0) {
return sigintHandlersWrap(super.runInContext, this,
[contextifiedObject, ...args]);
return sigintHandlersWrap(super.runInContext, this, args);
}
return super.runInContext(contextifiedObject, ...args);
return ReflectApply(super.runInContext, this, args);
}
runInNewContext(contextObject, options) {
@ -274,9 +275,9 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
} finally {
// Add using the public methods so that the `newListener` handler of
// process can re-attach the listeners.
for (const listener of sigintListeners) {
ArrayPrototypeForEach(sigintListeners, (listener) => {
process.addListener('SIGINT', listener);
}
});
}
}