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 authored and Michaël Zasso committed 2021-06-11 09:29:55 +02:00
1 parent 6eaf357f49
commit 3aee77d279
2 files changed
+9 -7

No files matched your search

+2 -1
View File
@@ -11,6 +11,7 @@ const {
ObjectGetPrototypeOf,
ObjectSetPrototypeOf,
PromiseAll,
ReflectApply,
SafeWeakMap,
Symbol,
SymbolToStringTag,
@@ -447,7 +448,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;
}
+7 -6
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);
}
});
}
}