GeezerVison is showing github.com — vm: refactor to avoid unsafe array iteration · nodejs/node@0d71947
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/vm/module.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,7 @@ const { | 11 | 11 | ObjectGetPrototypeOf, | 12 | 12 | ObjectSetPrototypeOf, | 13 | 13 | PromiseAll, | | 14 | + ReflectApply, | 14 | 15 | SafeWeakMap, | 15 | 16 | Symbol, | 16 | 17 | SymbolToStringTag, | @@ -445,7 +446,7 @@ class SyntheticModule extends Module { | 445 | 446 |
| 446 | 447 | function importModuleDynamicallyWrap(importModuleDynamically) { | 447 | 448 | const importModuleDynamicallyWrapper = async (...args) => { | 448 | | - const m = await importModuleDynamically(...args); | | 449 | + const m = await ReflectApply(importModuleDynamically, this, args); | 449 | 450 | if (isModuleNamespaceObject(m)) { | 450 | 451 | return m; | 451 | 452 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/vm.js +7-6Lines changed: 7 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 |
| 24 | 24 | const { | 25 | 25 | ArrayPrototypeForEach, | | 26 | + ArrayPrototypeUnshift, | 26 | 27 | Symbol, | 27 | 28 | PromiseReject, | 28 | 29 | ReflectApply, | @@ -130,17 +131,17 @@ class Script extends ContextifyScript { | 130 | 131 | if (breakOnSigint && process.listenerCount('SIGINT') > 0) { | 131 | 132 | return sigintHandlersWrap(super.runInThisContext, this, args); | 132 | 133 | } | 133 | | - return super.runInThisContext(...args); | | 134 | + return ReflectApply(super.runInThisContext, this, args); | 134 | 135 | } | 135 | 136 |
| 136 | 137 | runInContext(contextifiedObject, options) { | 137 | 138 | validateContext(contextifiedObject); | 138 | 139 | const { breakOnSigint, args } = getRunInContextArgs(options); | | 140 | + ArrayPrototypeUnshift(args, contextifiedObject); | 139 | 141 | if (breakOnSigint && process.listenerCount('SIGINT') > 0) { | 140 | | - return sigintHandlersWrap(super.runInContext, this, | 141 | | - [contextifiedObject, ...args]); | | 142 | + return sigintHandlersWrap(super.runInContext, this, args); | 142 | 143 | } | 143 | | - return super.runInContext(contextifiedObject, ...args); | | 144 | + return ReflectApply(super.runInContext, this, args); | 144 | 145 | } | 145 | 146 |
| 146 | 147 | runInNewContext(contextObject, options) { | @@ -274,9 +275,9 @@ function sigintHandlersWrap(fn, thisArg, argsArray) { | 274 | 275 | } finally { | 275 | 276 | // Add using the public methods so that the `newListener` handler of | 276 | 277 | // process can re-attach the listeners. | 277 | | - for (const listener of sigintListeners) { | | 278 | + ArrayPrototypeForEach(sigintListeners, (listener) => { | 278 | 279 | process.addListener('SIGINT', listener); | 279 | | - } | | 280 | + }); | 280 | 281 | } | 281 | 282 | } | 282 | 283 |
| |
|