Skip to content

Commit 3aee77d

Browse files
aduh95targos
authored andcommitted
vm: refactor to avoid unsafe array iteration
PR-URL: #36752 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6eaf357 commit 3aee77d

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎lib/internal/vm/module.js‎

Lines 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,
@@ -447,7 +448,7 @@ class SyntheticModule extends Module {
447448

448449
functionimportModuleDynamicallyWrap(importModuleDynamically){
449450
constimportModuleDynamicallyWrapper=async(...args)=>{
450-
constm=awaitimportModuleDynamically(...args);
451+
constm=awaitReflectApply(importModuleDynamically,this,args);
451452
if(isModuleNamespaceObject(m)){
452453
returnm;
453454
}

‎lib/vm.js‎

Lines 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
returnsigintHandlersWrap(super.runInThisContext,this,args);
132133
}
133-
returnsuper.runInThisContext(...args);
134+
returnReflectApply(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-
returnsigintHandlersWrap(super.runInContext,this,
141-
[contextifiedObject, ...args]);
142+
returnsigintHandlersWrap(super.runInContext,this,args);
142143
}
143-
returnsuper.runInContext(contextifiedObject, ...args);
144+
returnReflectApply(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(constlistenerofsigintListeners){
278+
ArrayPrototypeForEach(sigintListeners,(listener)=>{
278279
process.addListener('SIGINT',listener);
279-
}
280+
});
280281
}
281282
}
282283

0 commit comments

Comments
 (0)