Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 181bad5

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

File tree

Expand file treeCollapse file tree

7 files changed

+33
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+33
-9
lines changed
Open diff view settings
Collapse file

‎lib/internal/event_target.js‎

Copy file name to clipboardExpand all lines: lib/internal/event_target.js
+2Lines 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
const EventEmitterMixin = (Superclass) => {
654655
class MixedEventEmitter extends Superclass {
655656
constructor(...args) {
657+
args = new SafeArrayIterator(args);
656658
super(...args);
657659
FunctionPrototypeCall(EventEmitter, this);
658660
}
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ function trySelf(parentPath, request) {
462462
const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/;
463463
function resolveExports(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;
Collapse file

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

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/module_job.js
+5-4Lines 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-
await PromiseAll(promises);
64+
await PromiseAll(new SafeArrayIterator(promises));
6465

65-
return PromiseAll(dependencyJobs);
66+
return PromiseAll(new SafeArrayIterator(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
const dependencyJobs = await moduleJob.linked;
93-
return PromiseAll(
94-
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph));
94+
return PromiseAll(new SafeArrayIterator(
95+
ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph)));
9596
};
9697
await addJobsToDependencyGraph(this);
9798

Collapse file

‎lib/internal/per_context/primordials.js‎

Copy file name to clipboardExpand all lines: lib/internal/per_context/primordials.js
+7Lines 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
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+2-2Lines 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 (const segment of ctx.path) {
450-
ret += '/' + segment;
449+
if (ctx.path.length) {
450+
ret += '/' + ArrayPrototypeJoin(ctx.path, '/');
451451
}
452452
}
453453
if (options.search && ctx.query !== null)
Collapse file

‎lib/internal/util/debuglog.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/debuglog.js
+3-2Lines 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();
Collapse file
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
6+
const ArrayIteratorPrototype =
7+
Object.getPrototypeOf(Array.prototype[Symbol.iterator]());
8+
9+
delete Array.prototype[Symbol.iterator];
10+
delete ArrayIteratorPrototype.next;
11+
12+
require('../common/fixtures');
13+
import('../fixtures/es-modules/test-esm-ok.mjs').then(common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.