Skip to content

Commit

Permalink
lib: add primordials.SafeArrayIterator
Browse files Browse the repository at this point in the history
PR-URL: nodejs#36532
Backport-PR-URL: nodejs#39446
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
aduh95 authored and foxxyz committed Oct 18, 2021
1 parent f601232 commit 9d57349
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ function trySelf(parentPath, request) {
const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/;
function resolveExports(nmPath, request) {
// The implementation's behavior is meant to mirror resolution in ESM.
const [, name, expansion = ''] =
const { 1: name, 2: expansion = '' } =
StringPrototypeMatch(request, EXPORTS_PATTERN) || [];
if (!name)
return;
Expand Down
9 changes: 5 additions & 4 deletions lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
PromisePrototypeCatch,
ReflectApply,
RegExpPrototypeTest,
SafeArrayIterator,
SafeSet,
StringPrototypeIncludes,
StringPrototypeMatch,
Expand Down Expand Up @@ -76,9 +77,9 @@ class ModuleJob {
});

if (promises !== undefined)
await PromiseAll(promises);
await PromiseAll(new SafeArrayIterator(promises));

return PromiseAll(dependencyJobs);
return PromiseAll(new SafeArrayIterator(dependencyJobs));
};
// Promise for the list of all dependencyJobs.
this.linked = link();
Expand Down Expand Up @@ -106,8 +107,8 @@ class ModuleJob {
}
jobsInGraph.add(moduleJob);
const dependencyJobs = await moduleJob.linked;
return PromiseAll(
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph));
return PromiseAll(new SafeArrayIterator(
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph)));
};
await addJobsToDependencyGraph(this);

Expand Down
7 changes: 7 additions & 0 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ primordials.SafeWeakSet = makeSafe(
// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
[
{ name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) },
{ name: 'ArrayIterator', original: {
prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
} },
{ name: 'StringIterator', original: {
prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),
} },
Expand All @@ -274,6 +277,10 @@ primordials.SafeWeakSet = makeSafe(
copyPrototype(original.prototype, primordials, `${name}Prototype`);
});

primordials.SafeArrayIterator = createSafeIterator(
primordials.ArrayPrototypeSymbolIterator,
primordials.ArrayIteratorPrototypeNext
);
primordials.SafeStringIterator = createSafeIterator(
primordials.StringPrototypeSymbolIterator,
primordials.StringIteratorPrototypeNext
Expand Down
5 changes: 3 additions & 2 deletions lib/internal/util/debuglog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
ObjectDefineProperty,
RegExp,
RegExpPrototypeTest,
SafeArrayIterator,
StringPrototypeToUpperCase
} = primordials;

Expand Down Expand Up @@ -78,15 +79,15 @@ function debuglog(set, cb) {
debug = debuglogImpl(enabled, set);
if (typeof cb === 'function')
cb(debug);
debug(...args);
debug(...new SafeArrayIterator(args));
};
let enabled;
let test = () => {
init();
test = () => enabled;
return enabled;
};
const logger = (...args) => debug(...args);
const logger = (...args) => debug(...new SafeArrayIterator(args));
ObjectDefineProperty(logger, 'enabled', {
get() {
return test();
Expand Down

0 comments on commit 9d57349

Please sign in to comment.