Skip to content

Commit 181bad5

Browse files
aduh95danielleadams
authored andcommitted
lib: add primordials.SafeArrayIterator
PR-URL: #36532 Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent a4d64f9 commit 181bad5

7 files changed

Lines changed: 33 additions & 9 deletions

File tree

‎lib/internal/event_target.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
ObjectGetOwnPropertyDescriptor,
1414
ObjectGetOwnPropertyDescriptors,
1515
ReflectApply,
16+
SafeArrayIterator,
1617
SafeMap,
1718
String,
1819
Symbol,
@@ -653,6 +654,7 @@ function defineEventHandler(emitter, name) {
653654
constEventEmitterMixin=(Superclass)=>{
654655
classMixedEventEmitterextendsSuperclass{
655656
constructor(...args){
657+
args=newSafeArrayIterator(args);
656658
super(...args);
657659
FunctionPrototypeCall(EventEmitter,this);
658660
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ function trySelf(parentPath, request) {
462462
constEXPORTS_PATTERN=/^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/;
463463
functionresolveExports(nmPath,request){
464464
// The implementation's behavior is meant to mirror resolution in ESM.
465-
const[,name,expansion='']=
465+
const{1: name,2: expansion=''}=
466466
StringPrototypeMatch(request,EXPORTS_PATTERN)||[];
467467
if(!name)
468468
return;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
PromiseResolve,
1111
PromisePrototypeCatch,
1212
ReflectApply,
13+
SafeArrayIterator,
1314
SafeSet,
1415
StringPrototypeIncludes,
1516
StringPrototypeMatch,
@@ -60,9 +61,9 @@ class ModuleJob {
6061
});
6162

6263
if(promises!==undefined)
63-
awaitPromiseAll(promises);
64+
awaitPromiseAll(newSafeArrayIterator(promises));
6465

65-
returnPromiseAll(dependencyJobs);
66+
returnPromiseAll(newSafeArrayIterator(dependencyJobs));
6667
};
6768
// Promise for the list of all dependencyJobs.
6869
this.linked=link();
@@ -90,8 +91,8 @@ class ModuleJob {
9091
}
9192
jobsInGraph.add(moduleJob);
9293
constdependencyJobs=awaitmoduleJob.linked;
93-
returnPromiseAll(
94-
ArrayPrototypeMap(dependencyJobs,addJobsToDependencyGraph));
94+
returnPromiseAll(newSafeArrayIterator(
95+
ArrayPrototypeMap(dependencyJobs,addJobsToDependencyGraph)));
9596
};
9697
awaitaddJobsToDependencyGraph(this);
9798

‎lib/internal/per_context/primordials.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ primordials.SafeWeakSet = makeSafe(
242242
// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
243243
[
244244
{name: 'TypedArray',original: Reflect.getPrototypeOf(Uint8Array)},
245+
{name: 'ArrayIterator',original: {
246+
prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
247+
}},
245248
{name: 'StringIterator',original: {
246249
prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),
247250
}},
@@ -253,6 +256,10 @@ primordials.SafeWeakSet = makeSafe(
253256
copyPrototype(original.prototype,primordials,`${name}Prototype`);
254257
});
255258

259+
primordials.SafeArrayIterator=createSafeIterator(
260+
primordials.ArrayPrototypeSymbolIterator,
261+
primordials.ArrayIteratorPrototypeNext
262+
);
256263
primordials.SafeStringIterator=createSafeIterator(
257264
primordials.StringPrototypeSymbolIterator,
258265
primordials.StringIteratorPrototypeNext

‎lib/internal/url.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ ObjectDefineProperties(URL.prototype, {
446446
if(ctx.host===null&&ctx.path.length>1&&ctx.path[0]===''){
447447
ret+='/.';
448448
}
449-
for(constsegmentofctx.path){
450-
ret+='/'+segment;
449+
if(ctx.path.length){
450+
ret+='/'+ArrayPrototypeJoin(ctx.path,'/');
451451
}
452452
}
453453
if(options.search&&ctx.query!==null)

‎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();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
5+
6+
constArrayIteratorPrototype=
7+
Object.getPrototypeOf(Array.prototype[Symbol.iterator]());
8+
9+
deleteArray.prototype[Symbol.iterator];
10+
deleteArrayIteratorPrototype.next;
11+
12+
require('../common/fixtures');
13+
import('../fixtures/es-modules/test-esm-ok.mjs').then(common.mustCall());

0 commit comments

Comments
 (0)