GeezerVison is showing github.com — lib: add primordials.SafeArrayIterator · nodejs/node@181bad5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/event_target.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ const { | 13 | 13 | ObjectGetOwnPropertyDescriptor, | 14 | 14 | ObjectGetOwnPropertyDescriptors, | 15 | 15 | ReflectApply, | | 16 | + SafeArrayIterator, | 16 | 17 | SafeMap, | 17 | 18 | String, | 18 | 19 | Symbol, | @@ -653,6 +654,7 @@ function defineEventHandler(emitter, name) { | 653 | 654 | const EventEmitterMixin = (Superclass) => { | 654 | 655 | class MixedEventEmitter extends Superclass { | 655 | 656 | constructor(...args) { | | 657 | + args = new SafeArrayIterator(args); | 656 | 658 | super(...args); | 657 | 659 | FunctionPrototypeCall(EventEmitter, this); | 658 | 660 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -462,7 +462,7 @@ function trySelf(parentPath, request) { | 462 | 462 | const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/; | 463 | 463 | function resolveExports(nmPath, request) { | 464 | 464 | // The implementation's behavior is meant to mirror resolution in ESM. | 465 | | - const [, name, expansion = ''] = | | 465 | + const { 1: name, 2: expansion = '' } = | 466 | 466 | StringPrototypeMatch(request, EXPORTS_PATTERN) || []; | 467 | 467 | if (!name) | 468 | 468 | return; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/module_job.js +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ const { | 10 | 10 | PromiseResolve, | 11 | 11 | PromisePrototypeCatch, | 12 | 12 | ReflectApply, | | 13 | + SafeArrayIterator, | 13 | 14 | SafeSet, | 14 | 15 | StringPrototypeIncludes, | 15 | 16 | StringPrototypeMatch, | @@ -60,9 +61,9 @@ class ModuleJob { | 60 | 61 | }); | 61 | 62 |
| 62 | 63 | if (promises !== undefined) | 63 | | - await PromiseAll(promises); | | 64 | + await PromiseAll(new SafeArrayIterator(promises)); | 64 | 65 |
| 65 | | - return PromiseAll(dependencyJobs); | | 66 | + return PromiseAll(new SafeArrayIterator(dependencyJobs)); | 66 | 67 | }; | 67 | 68 | // Promise for the list of all dependencyJobs. | 68 | 69 | this.linked = link(); | @@ -90,8 +91,8 @@ class ModuleJob { | 90 | 91 | } | 91 | 92 | jobsInGraph.add(moduleJob); | 92 | 93 | const dependencyJobs = await moduleJob.linked; | 93 | | - return PromiseAll( | 94 | | - ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph)); | | 94 | + return PromiseAll(new SafeArrayIterator( | | 95 | + ArrayPrototypeMap(dependencyJobs, addJobsToDependencyGraph))); | 95 | 96 | }; | 96 | 97 | await addJobsToDependencyGraph(this); | 97 | 98 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/per_context/primordials.js +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -242,6 +242,9 @@ primordials.SafeWeakSet = makeSafe( | 242 | 242 | // Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object | 243 | 243 | [ | 244 | 244 | { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) }, | | 245 | + { name: 'ArrayIterator', original: { | | 246 | + prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()), | | 247 | + } }, | 245 | 248 | { name: 'StringIterator', original: { | 246 | 249 | prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()), | 247 | 250 | } }, | @@ -253,6 +256,10 @@ primordials.SafeWeakSet = makeSafe( | 253 | 256 | copyPrototype(original.prototype, primordials, `${name}Prototype`); | 254 | 257 | }); | 255 | 258 |
| | 259 | +primordials.SafeArrayIterator = createSafeIterator( | | 260 | + primordials.ArrayPrototypeSymbolIterator, | | 261 | + primordials.ArrayIteratorPrototypeNext | | 262 | +); | 256 | 263 | primordials.SafeStringIterator = createSafeIterator( | 257 | 264 | primordials.StringPrototypeSymbolIterator, | 258 | 265 | primordials.StringIteratorPrototypeNext | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/url.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -446,8 +446,8 @@ ObjectDefineProperties(URL.prototype, { | 446 | 446 | if (ctx.host === null && ctx.path.length > 1 && ctx.path[0] === '') { | 447 | 447 | ret += '/.'; | 448 | 448 | } | 449 | | - for (const segment of ctx.path) { | 450 | | - ret += '/' + segment; | | 449 | + if (ctx.path.length) { | | 450 | + ret += '/' + ArrayPrototypeJoin(ctx.path, '/'); | 451 | 451 | } | 452 | 452 | } | 453 | 453 | if (options.search && ctx.query !== null) | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/util/debuglog.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | ObjectDefineProperty, | 7 | 7 | RegExp, | 8 | 8 | RegExpPrototypeTest, | | 9 | + SafeArrayIterator, | 9 | 10 | StringPrototypeToUpperCase | 10 | 11 | } = primordials; | 11 | 12 |
| @@ -78,15 +79,15 @@ function debuglog(set, cb) { | 78 | 79 | debug = debuglogImpl(enabled, set); | 79 | 80 | if (typeof cb === 'function') | 80 | 81 | cb(debug); | 81 | | - debug(...args); | | 82 | + debug(...new SafeArrayIterator(args)); | 82 | 83 | }; | 83 | 84 | let enabled; | 84 | 85 | let test = () => { | 85 | 86 | init(); | 86 | 87 | test = () => enabled; | 87 | 88 | return enabled; | 88 | 89 | }; | 89 | | - const logger = (...args) => debug(...args); | | 90 | + const logger = (...args) => debug(...new SafeArrayIterator(args)); | 90 | 91 | ObjectDefineProperty(logger, 'enabled', { | 91 | 92 | get() { | 92 | 93 | return test(); | |
Collapse file Copy file name to clipboard +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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()); |
|