diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index 12a7f8af8554b0..6bf73291be00c7 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -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; } diff --git a/lib/vm.js b/lib/vm.js index 33893845084141..79c97f3af3ff02 100644 --- a/lib/vm.js +++ b/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); - } + }); } }