GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — vm: refactor to avoid unsafe array iteration · nodejs/node@0d71947

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • internal/vm
      • module.js
    • vm.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/vm/module.js‎

Copy file name to clipboardExpand all lines: lib/internal/vm/module.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
ObjectGetPrototypeOf,
1212
ObjectSetPrototypeOf,
1313
PromiseAll,
14+
ReflectApply,
1415
SafeWeakMap,
1516
Symbol,
1617
SymbolToStringTag,
@@ -445,7 +446,7 @@ class SyntheticModule extends Module {
445446

446447
function importModuleDynamicallyWrap(importModuleDynamically) {
447448
const importModuleDynamicallyWrapper = async (...args) => {
448-
const m = await importModuleDynamically(...args);
449+
const m = await ReflectApply(importModuleDynamically, this, args);
449450
if (isModuleNamespaceObject(m)) {
450451
return m;
451452
}
Collapse file

‎lib/vm.js‎

Copy file name to clipboardExpand all lines: lib/vm.js
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const {
2525
ArrayPrototypeForEach,
26+
ArrayPrototypeUnshift,
2627
Symbol,
2728
PromiseReject,
2829
ReflectApply,
@@ -130,17 +131,17 @@ class Script extends ContextifyScript {
130131
if (breakOnSigint && process.listenerCount('SIGINT') > 0) {
131132
return sigintHandlersWrap(super.runInThisContext, this, args);
132133
}
133-
return super.runInThisContext(...args);
134+
return ReflectApply(super.runInThisContext, this, args);
134135
}
135136

136137
runInContext(contextifiedObject, options) {
137138
validateContext(contextifiedObject);
138139
const { breakOnSigint, args } = getRunInContextArgs(options);
140+
ArrayPrototypeUnshift(args, contextifiedObject);
139141
if (breakOnSigint && process.listenerCount('SIGINT') > 0) {
140-
return sigintHandlersWrap(super.runInContext, this,
141-
[contextifiedObject, ...args]);
142+
return sigintHandlersWrap(super.runInContext, this, args);
142143
}
143-
return super.runInContext(contextifiedObject, ...args);
144+
return ReflectApply(super.runInContext, this, args);
144145
}
145146

146147
runInNewContext(contextObject, options) {
@@ -274,9 +275,9 @@ function sigintHandlersWrap(fn, thisArg, argsArray) {
274275
} finally {
275276
// Add using the public methods so that the `newListener` handler of
276277
// process can re-attach the listeners.
277-
for (const listener of sigintListeners) {
278+
ArrayPrototypeForEach(sigintListeners, (listener) => {
278279
process.addListener('SIGINT', listener);
279-
}
280+
});
280281
}
281282
}
282283

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.