| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 85c6d46 commit 7f4af55
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,10 +148,6 @@ export default [ | |||
| 148 | 148 | name: 'Intl', | |
| 149 | 149 | message: 'Use `const { Intl } = globalThis;` instead of the global.', | |
| 150 | 150 | }, | |
| 151 | - { | ||
| 152 | - name: 'Iterator', | ||
| 153 | - message: 'Use `const { Iterator } = globalThis;` instead of the global.', | ||
| 154 | - }, | ||
| 155 | 151 | { | |
| 156 | 152 | name: 'MessageChannel', | |
| 157 | 153 | message: "Use `const { MessageChannel } = require('internal/worker/io');` instead of the global.", | |
@@ -441,6 +437,7 @@ export default [ | |||
| 441 | 437 | { name: 'Int16Array' }, | |
| 442 | 438 | { name: 'Int32Array' }, | |
| 443 | 439 | { name: 'Int8Array' }, | |
| 440 | + { name: 'Iterator' }, | ||
| 444 | 441 | { | |
| 445 | 442 | name: 'isFinite', | |
| 446 | 443 | into: 'Number', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -202,6 +202,7 @@ function copyPrototype(src, dest, prefix) { | |||
| 202 | 202 | 'Int16Array', | |
| 203 | 203 | 'Int32Array', | |
| 204 | 204 | 'Int8Array', | |
| 205 | + 'Iterator', | ||
| 205 | 206 | 'Map', | |
| 206 | 207 | 'Number', | |
| 207 | 208 | 'Object', | |
@@ -230,10 +231,10 @@ function copyPrototype(src, dest, prefix) { | |||
| 230 | 231 | }); | |
| 231 | 232 | ||
| 232 | 233 | ||
| 233 | - // Create copies of intrinsic objects that require a valid `this` to call | ||
| 234 | - // static methods. | ||
| 235 | - // Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all | ||
| 234 | + // Create copies of intrinsic objects whose static methods require the | ||
| 235 | + // constructor to be passed as the receiver. | ||
| 236 | 236 | [ | |
| 237 | + // Refs: https://tc39.es/ecma-262/#sec-promise.all | ||
| 237 | 238 | 'Promise', | |
| 238 | 239 | ].forEach((name) => { | |
| 239 | 240 | // eslint-disable-next-line no-restricted-globals | |
@@ -244,25 +245,56 @@ function copyPrototype(src, dest, prefix) { | |||
| 244 | 245 | }); | |
| 245 | 246 | ||
| 246 | 247 | // Create copies of abstract intrinsic objects that are not directly exposed | |
| 247 | - // on the global object. | ||
| 248 | - // Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object | ||
| 248 | + // on the global object, and whose static methods require a valid subclass | ||
| 249 | + // constructor to be passed as the receiver. | ||
| 249 | 250 | [ | |
| 251 | + // Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object | ||
| 250 | 252 | { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) }, | |
| 251 | - { name: 'ArrayIterator', original: { | ||
| 252 | - prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()), | ||
| 253 | - } }, | ||
| 254 | - { name: 'StringIterator', original: { | ||
| 255 | - prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()), | ||
| 256 | - } }, | ||
| 257 | 253 | ].forEach(({ name, original }) => { | |
| 258 | 254 | primordials[name] = original; | |
| 259 | - // The static %TypedArray% methods require a valid `this`, but can't be bound, | ||
| 260 | - // as they need a subclass constructor as the receiver: | ||
| 261 | 255 | copyPrototype(original, primordials, name); | |
| 262 | 256 | copyPrototype(original.prototype, primordials, `${name}Prototype`); | |
| 263 | 257 | }); | |
| 264 | 258 | ||
| 265 | - primordials.IteratorPrototype = Reflect.getPrototypeOf(primordials.ArrayIteratorPrototype); | ||
| 259 | + // Create copies of abstract intrinsic prototypes that are not directly exposed | ||
| 260 | + // on the global object and which do not have corresponding constructors. | ||
| 261 | + [ | ||
| 262 | + { | ||
| 263 | + name: 'ArrayIteratorPrototype', | ||
| 264 | + original: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()), | ||
| 265 | + }, | ||
| 266 | + { | ||
| 267 | + name: 'AsyncIteratorPrototype', | ||
| 268 | + original: Reflect.getPrototypeOf(Reflect.getPrototypeOf(async function*() {}).prototype), | ||
| 269 | + }, | ||
| 270 | + { | ||
| 271 | + name: 'IteratorHelperPrototype', | ||
| 272 | + original: Reflect.getPrototypeOf(primordials.IteratorPrototypeDrop({ __proto__: null }, null)), | ||
| 273 | + }, | ||
| 274 | + { | ||
| 275 | + name: 'MapIteratorPrototype', | ||
| 276 | + original: Reflect.getPrototypeOf(new primordials.Map()[Symbol.iterator]()), | ||
| 277 | + }, | ||
| 278 | + { | ||
| 279 | + name: 'RegExpStringIteratorPrototype', | ||
| 280 | + original: Reflect.getPrototypeOf(primordials.RegExp.prototype[Symbol.matchAll]()), | ||
| 281 | + }, | ||
| 282 | + { | ||
| 283 | + name: 'SetIteratorPrototype', | ||
| 284 | + original: Reflect.getPrototypeOf(new primordials.Set()[Symbol.iterator]()), | ||
| 285 | + }, | ||
| 286 | + { | ||
| 287 | + name: 'StringIteratorPrototype', | ||
| 288 | + original: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()), | ||
| 289 | + }, | ||
| 290 | + { | ||
| 291 | + name: 'WrapForValidIteratorPrototype', | ||
| 292 | + original: Reflect.getPrototypeOf(primordials.IteratorFrom({ __proto__: null })), | ||
| 293 | + }, | ||
| 294 | + ].forEach(({ name, original }) => { | ||
| 295 | + primordials[name] = original; | ||
| 296 | + copyPrototype(original, primordials, name); | ||
| 297 | + }); | ||
| 266 | 298 | ||
| 267 | 299 | /* eslint-enable node-core/prefer-primordials */ | |
| 268 | 300 | ||
@@ -366,21 +398,18 @@ const copyProps = (src, dest) => { | |||
| 366 | 398 | /** | |
| 367 | 399 | * @type {typeof primordials.makeSafe} | |
| 368 | 400 | */ | |
| 369 | - const makeSafe = (unsafe, safe) => { | ||
| 370 | - if (SymbolIterator in unsafe.prototype) { | ||
| 401 | + const makeSafe = (unsafe, safe, next) => { | ||
| 402 | + if (next) { | ||
| 371 | 403 | const dummy = new unsafe(); | |
| 372 | - let next; // We can reuse the same `next` method. | ||
| 373 | - | ||
| 374 | 404 | ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => { | |
| 375 | 405 | if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) { | |
| 376 | 406 | const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key); | |
| 377 | 407 | if ( | |
| 378 | 408 | typeof desc.value === 'function' && | |
| 379 | 409 | desc.value.length === 0 && | |
| 380 | - SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {}) | ||
| 410 | + FunctionPrototypeCall(desc.value, dummy)?.next === next | ||
| 381 | 411 | ) { | |
| 382 | 412 | const createIterator = uncurryThis(desc.value); | |
| 383 | - next ??= uncurryThis(createIterator(dummy).next); | ||
| 384 | 413 | const SafeIterator = createSafeIterator(createIterator, next); | |
| 385 | 414 | desc.value = function() { | |
| 386 | 415 | return new SafeIterator(this); | |
@@ -406,6 +435,7 @@ primordials.makeSafe = makeSafe; | |||
| 406 | 435 | primordials.SafeMap = makeSafe( | |
| 407 | 436 | Map, | |
| 408 | 437 | class SafeMap extends Map {}, | |
| 438 | + primordials.MapIteratorPrototypeNext, | ||
| 409 | 439 | ); | |
| 410 | 440 | primordials.SafeWeakMap = makeSafe( | |
| 411 | 441 | WeakMap, | |
@@ -415,6 +445,7 @@ primordials.SafeWeakMap = makeSafe( | |||
| 415 | 445 | primordials.SafeSet = makeSafe( | |
| 416 | 446 | Set, | |
| 417 | 447 | class SafeSet extends Set {}, | |
| 448 | + primordials.SetIteratorPrototypeNext, | ||
| 418 | 449 | ); | |
| 419 | 450 | primordials.SafeWeakSet = makeSafe( | |
| 420 | 451 | WeakSet, | |
@@ -453,11 +484,6 @@ primordials.SafePromisePrototypeFinally = (thisPromise, onFinally) => | |||
| 453 | 484 | .then(a, b), | |
| 454 | 485 | ); | |
| 455 | 486 | ||
| 456 | - primordials.AsyncIteratorPrototype = | ||
| 457 | - primordials.ReflectGetPrototypeOf( | ||
| 458 | - primordials.ReflectGetPrototypeOf( | ||
| 459 | - async function* () {}).prototype); | ||
| 460 | - | ||
| 461 | 487 | const arrayToSafePromiseIterable = (promises, mapFn) => | |
| 462 | 488 | new primordials.SafeArrayIterator( | |
| 463 | 489 | ArrayPrototypeMap( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,7 @@ type TypedArrayContentType<T extends TypedArrayConstructor> = InstanceType<T>[nu | |||
| 40 | 40 | */ | |
| 41 | 41 | declare namespace primordials { | |
| 42 | 42 | export function uncurryThis<T extends (...args: unknown[]) => unknown>(fn: T): UncurryThis<T>; | |
| 43 | - export function makeSafe<T extends NewableFunction>(unsafe: NewableFunction, safe: T): T; | ||
| 43 | + export function makeSafe<T extends NewableFunction>(unsafe: NewableFunction, safe: T, next?: Function): T; | ||
| 44 | 44 | ||
| 45 | 45 | export import decodeURI = globalThis.decodeURI; | |
| 46 | 46 | export import decodeURIComponent = globalThis.decodeURIComponent; | |
@@ -168,7 +168,6 @@ declare namespace primordials { | |||
| 168 | 168 | export const ArrayBufferPrototypeSlice: UncurryThis<typeof ArrayBuffer.prototype.slice> | |
| 169 | 169 | export const ArrayBufferPrototypeTransfer: UncurryThis<typeof ArrayBuffer.prototype.transfer> | |
| 170 | 170 | export const ArrayBufferPrototypeGetByteLength: UncurryGetter<typeof ArrayBuffer.prototype , "byteLength">; | |
| 171 | - export const AsyncIteratorPrototype: AsyncIterable<any>; | ||
| 172 | 171 | export import BigInt = globalThis.BigInt; | |
| 173 | 172 | export const BigIntPrototype: typeof BigInt.prototype | |
| 174 | 173 | export const BigIntAsUintN: typeof BigInt.asUintN | |
@@ -545,6 +544,34 @@ declare namespace primordials { | |||
| 545 | 544 | export const PromisePrototypeFinally: UncurryThis<typeof Promise.prototype.finally> | |
| 546 | 545 | export const PromiseWithResolvers: typeof Promise.withResolvers | |
| 547 | 546 | export import Proxy = globalThis.Proxy | |
| 547 | + export import Iterator = globalThis.Iterator | ||
| 548 | + export const IteratorFrom: typeof Iterator.from | ||
| 549 | + export const IteratorPrototype: typeof Iterator.prototype | ||
| 550 | + export const IteratorPrototypeDrop: UncurryThis<typeof Iterator.prototype.drop> | ||
| 551 | + export const IteratorPrototypeEvery: UncurryThis<typeof Iterator.prototype.every> | ||
| 552 | + export const IteratorPrototypeFilter: UncurryThis<typeof Iterator.prototype.filter> | ||
| 553 | + export const IteratorPrototypeFind: UncurryThis<typeof Iterator.prototype.find> | ||
| 554 | + export const IteratorPrototypeFlatMap: UncurryThis<typeof Iterator.prototype.flatMap> | ||
| 555 | + export const IteratorPrototypeForEach: UncurryThis<typeof Iterator.prototype.forEach> | ||
| 556 | + export const IteratorPrototypeMap: UncurryThis<typeof Iterator.prototype.map> | ||
| 557 | + export const IteratorPrototypeReduce: UncurryThis<typeof Iterator.prototype.reduce> | ||
| 558 | + export const IteratorPrototypeSome: UncurryThis<typeof Iterator.prototype.some> | ||
| 559 | + export const IteratorPrototypeTake: UncurryThis<typeof Iterator.prototype.take> | ||
| 560 | + export const IteratorPrototypeToArray: UncurryThis<typeof Iterator.prototype.toArray> | ||
| 561 | + export const IteratorPrototypeSymbolIterator: UncurryMethod<typeof Iterator.prototype, typeof Symbol.iterator> | ||
| 562 | + export const ArrayIteratorPrototype: ReturnType<typeof Array.prototype[typeof Symbol.iterator]> | ||
| 563 | + export const ArrayIteratorPrototypeNext: UncurryThis<typeof ArrayIteratorPrototype.next> | ||
| 564 | + export const AsyncIteratorPrototype: AsyncIterable<any> | ||
| 565 | + export const IteratorHelperPrototype: ReturnType<typeof Iterator.prototype.drop> | ||
| 566 | + export const MapIteratorPrototype: ReturnType<typeof Map.prototype[typeof Symbol.iterator]> | ||
| 567 | + export const MapIteratorPrototypeNext: UncurryThis<typeof MapIteratorPrototype.next> | ||
| 568 | + export const RegExpStringIteratorPrototype: ReturnType<typeof RegExp.prototype[typeof Symbol.matchAll]> | ||
| 569 | + export const RegExpStringIteratorPrototypeNext: UncurryThis<typeof RegExpStringIteratorPrototype.next> | ||
| 570 | + export const SetIteratorPrototype: ReturnType<typeof Set.prototype[typeof Symbol.iterator]> | ||
| 571 | + export const SetIteratorPrototypeNext: UncurryThis<typeof SetIteratorPrototype.next> | ||
| 572 | + export const StringIteratorPrototype: ReturnType<typeof String.prototype[typeof Symbol.iterator]> | ||
| 573 | + export const StringIteratorPrototypeNext: UncurryThis<typeof StringIteratorPrototype.next> | ||
| 574 | + export const WrapForValidIteratorPrototype: ReturnType<typeof Iterator.from> | ||
| 548 | 575 | import _globalThis = globalThis | |
| 549 | 576 | export { _globalThis as globalThis } | |
| 550 | 577 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments