mirror of https://github.com/nodejs/node.git
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:
parent
7c37e046eb
commit
e70e793404
|
@ -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;
|
||||
}
|
||||
|
|
13
lib/vm.js
13
lib/vm.js
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue