Skip to content

Commit 89b353d

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

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
const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/;
439439
function resolveExports(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-
await PromiseAll(promises);
80+
await PromiseAll(new SafeArrayIterator(promises));
8081

81-
return PromiseAll(dependencyJobs);
82+
return PromiseAll(new SafeArrayIterator(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
const dependencyJobs = await moduleJob.linked;
109-
return PromiseAll(
110-
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph));
110+
return PromiseAll(new SafeArrayIterator(
111+
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph)));
111112
};
112113
await addJobsToDependencyGraph(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 (typeof cb === 'function')
8081
cb(debug);
81-
debug(...args);
82+
debug(...new SafeArrayIterator(args));
8283
};
8384
let enabled;
8485
let test = () => {
8586
init();
8687
test = () => enabled;
8788
return enabled;
8889
};
89-
const logger = (...args) => debug(...args);
90+
const logger = (...args) => debug(...new SafeArrayIterator(args));
9091
ObjectDefineProperty(logger, 'enabled', {
9192
get() {
9293
return test();

0 commit comments

Comments
 (0)