Skip to content

Commit d8cc2ff

Browse files
aduh95richardlau
authored andcommitted
lib: add primordials.SafeArrayIterator
PR-URL: #36532 Backport-PR-URL: #39446 Reviewed-By: Rich Trott <[email protected]>
1 parent 4efefe0 commit d8cc2ff

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

‎lib/internal/modules/cjs/loader.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ function trySelf(parentPath, request){
438438
constEXPORTS_PATTERN=/^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/;
439439
functionresolveExports(nmPath,request){
440440
// The implementation's behavior is meant to mirror resolution in ESM.
441-
const[,name,expansion='']=
441+
const{1: name,2: expansion=''}=
442442
StringPrototypeMatch(request,EXPORTS_PATTERN)||[];
443443
if(!name)
444444
return;

‎lib/internal/modules/esm/module_job.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const{
1212
PromisePrototypeCatch,
1313
ReflectApply,
1414
RegExpPrototypeTest,
15+
SafeArrayIterator,
1516
SafeSet,
1617
StringPrototypeIncludes,
1718
StringPrototypeMatch,
@@ -76,9 +77,9 @@ class ModuleJob{
7677
});
7778

7879
if(promises!==undefined)
79-
awaitPromiseAll(promises);
80+
awaitPromiseAll(newSafeArrayIterator(promises));
8081

81-
returnPromiseAll(dependencyJobs);
82+
returnPromiseAll(newSafeArrayIterator(dependencyJobs));
8283
};
8384
// Promise for the list of all dependencyJobs.
8485
this.linked=link();
@@ -106,8 +107,8 @@ class ModuleJob{
106107
}
107108
jobsInGraph.add(moduleJob);
108109
constdependencyJobs=awaitmoduleJob.linked;
109-
returnPromiseAll(
110-
ArrayPrototypeMap(dependencyJobs,addJobsToDependencyGraph));
110+
returnPromiseAll(newSafeArrayIterator(
111+
ArrayPrototypeMap(dependencyJobs,addJobsToDependencyGraph)));
111112
};
112113
awaitaddJobsToDependencyGraph(this);
113114

‎lib/internal/per_context/primordials.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ primordials.SafeWeakSet = makeSafe(
263263
// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
264264
[
265265
{name: 'TypedArray',original: Reflect.getPrototypeOf(Uint8Array)},
266+
{name: 'ArrayIterator',original: {
267+
prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
268+
}},
266269
{name: 'StringIterator',original: {
267270
prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),
268271
}},
@@ -274,6 +277,10 @@ primordials.SafeWeakSet = makeSafe(
274277
copyPrototype(original.prototype,primordials,`${name}Prototype`);
275278
});
276279

280+
primordials.SafeArrayIterator=createSafeIterator(
281+
primordials.ArrayPrototypeSymbolIterator,
282+
primordials.ArrayIteratorPrototypeNext
283+
);
277284
primordials.SafeStringIterator=createSafeIterator(
278285
primordials.StringPrototypeSymbolIterator,
279286
primordials.StringIteratorPrototypeNext

‎lib/internal/util/debuglog.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const{
66
ObjectDefineProperty,
77
RegExp,
88
RegExpPrototypeTest,
9+
SafeArrayIterator,
910
StringPrototypeToUpperCase
1011
}=primordials;
1112

@@ -78,15 +79,15 @@ function debuglog(set, cb){
7879
debug=debuglogImpl(enabled,set);
7980
if(typeofcb==='function')
8081
cb(debug);
81-
debug(...args);
82+
debug(...newSafeArrayIterator(args));
8283
};
8384
letenabled;
8485
lettest=()=>{
8586
init();
8687
test=()=>enabled;
8788
returnenabled;
8889
};
89-
constlogger=(...args)=>debug(...args);
90+
constlogger=(...args)=>debug(...newSafeArrayIterator(args));
9091
ObjectDefineProperty(logger,'enabled',{
9192
get(){
9293
returntest();

0 commit comments

Comments
(0)