Skip to content

Commit

Permalink
Update es-iterator-helpers shared.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Dec 29, 2024
1 parent 20c4b75 commit bc755cb
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const {
IteratorPrototype,
ReflectApply,
TypeErrorCtor,
abruptCloseIterator,
closeIterator,
ensureObject,
getIteratorDirect
getIteratorDirect,
ifAbruptCloseIterator,
iteratorClose
} = require('../shared')

const { every: IteratorProtoEvery } = IteratorPrototype
Expand Down Expand Up @@ -54,11 +54,11 @@ module.exports =
])
} catch (e) {
// Step 6.d: IfAbruptCloseIterator(result, iterated).
abruptCloseIterator(iterator, e)
ifAbruptCloseIterator(iterator, e)
}
// Step 6.e: If ToBoolean(result) is false, return ? IteratorClose(iterated, NormalCompletion(false)).
if (!predicateResult) {
return closeIterator(iterator, false)
return iteratorClose(iterator, false)
}
// Step 6.f: Set counter to counter + 1.
index += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const {
ReflectApply,
TypeErrorCtor,
abruptCloseIterator,
createIteratorFromClosure,
ensureObject,
getIteratorDirect,
ifAbruptCloseIterator,
setUnderlyingIterator
} = require('../shared')

Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = function filter(predicate) {
selected = predicate(result.value, index++)
} catch (e) {
// Step 5.b.iv: IfAbruptCloseIterator(selected, iterated).
abruptCloseIterator(iterator, e)
ifAbruptCloseIterator(iterator, e)
}
// Step 5.b.v: If ToBoolean(selected) is true,
if (selected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const {
IteratorPrototype,
ReflectApply,
TypeErrorCtor,
abruptCloseIterator,
closeIterator,
ensureObject,
getIteratorDirect
getIteratorDirect,
ifAbruptCloseIterator,
iteratorClose
} = require('../shared')

const { find: IteratorProtoFind } = IteratorPrototype
Expand Down Expand Up @@ -52,11 +52,11 @@ module.exports =
predicateResult = ReflectApply(predicate, undefined, [value, index])
} catch (e) {
// Step 6.d: IfAbruptCloseIterator(result, iterated).
abruptCloseIterator(iterator, e)
ifAbruptCloseIterator(iterator, e)
}
// Step 6.e: If ToBoolean(result) is true, return IteratorClose(iterated, NormalCompletion(value)).
if (predicateResult) {
return closeIterator(iterator, value)
return iteratorClose(iterator, value)
}
// Step 6.f: Set counter to counter + 1.
index += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
const {
ReflectApply,
TypeErrorCtor,
abruptCloseIterator,
createIteratorFromClosure,
ensureObject,
getIteratorDirect,
getIteratorFlattenable,
getMethod,
ifAbruptCloseIterator,
setUnderlyingIterator
} = require('../shared')

Expand Down Expand Up @@ -54,7 +54,7 @@ module.exports = function flatMap(mapper) {
index += 1
} catch (e) {
// Step 5.b.iv: IfAbruptCloseIterator(mapped, iterated).
abruptCloseIterator(iterator, e)
ifAbruptCloseIterator(iterator, e)
}
}
// Step 5.b.viii: Inner loop over innerIterator values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const {
IteratorPrototype,
ReflectApply,
TypeErrorCtor,
abruptCloseIterator,
ensureObject,
getIteratorDirect
getIteratorDirect,
ifAbruptCloseIterator
} = require('../shared')

const { forEach: IteratorProtoForEach } = IteratorPrototype
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports =
ReflectApply(procedure, undefined, [result.value, index])
} catch (e) {
// Step 6.d: IfAbruptCloseIterator(result, iterated).
abruptCloseIterator(iterator, e)
ifAbruptCloseIterator(iterator, e)
}
// Step 6.e: Set counter to counter + 1.
index += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
const {
ReflectApply,
TypeErrorCtor,
abruptCloseIterator,
createIteratorFromClosure,
ensureObject,
getIteratorDirect,
ifAbruptCloseIterator,
setUnderlyingIterator
} = require('../shared')

Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = function map(mapper) {
mappedValue = mapper(result.value, index)
} catch (e) {
// Step 5.b.iv: IfAbruptCloseIterator(mapped, iterated).
abruptCloseIterator(iterator, e)
ifAbruptCloseIterator(iterator, e)
}
// Step 5.b.vii. Set counter to counter + 1.
index += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const {
IteratorPrototype,
ReflectApply,
TypeErrorCtor,
abruptCloseIterator,
ensureObject,
getIteratorDirect
getIteratorDirect,
ifAbruptCloseIterator
} = require('../shared')

const { reduce: IteratorProtoReduce } = IteratorPrototype
Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports =
])
} catch (e) {
// Step 7.d: IfAbruptCloseIterator(result, iterated).
abruptCloseIterator(iterator, e)
ifAbruptCloseIterator(iterator, e)
}
// Step 7.e: Set accumulator to result.
// Step 7.f: Set counter to counter + 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const {
IteratorPrototype,
ReflectApply,
TypeErrorCtor,
abruptCloseIterator,
closeIterator,
ensureObject,
getIteratorDirect
getIteratorDirect,
ifAbruptCloseIterator,
iteratorClose
} = require('../shared')

const { some: IteratorProtoSome } = IteratorPrototype
Expand Down Expand Up @@ -54,11 +54,11 @@ module.exports =
])
} catch (e) {
// Step 6.d: IfAbruptCloseIterator(result, iterated).
abruptCloseIterator(iterator, e)
ifAbruptCloseIterator(iterator, e)
}
// Step 6.e: If ToBoolean(result) is true, return IteratorClose(iterated, NormalCompletion(true)).
if (predicateResult) {
return closeIterator(iterator, true)
return iteratorClose(iterator, true)
}
// Step 6.f: Set counter to counter + 1.
index += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const {
RangeErrorCtor,
ReflectApply,
TypeErrorCtor,
closeIterator,
createIteratorFromClosure,
ensureObject,
getIteratorDirect,
iteratorClose,
setUnderlyingIterator,
toIntegerOrInfinity
} = require('../shared')
Expand Down Expand Up @@ -52,7 +52,7 @@ module.exports =
next() {
// Step 8.b.i: If remaining = 0, then return IteratorClose(iterated, ReturnCompletion(undefined)).
if (remaining === 0) {
closeIterator(iterator, undefined)
iteratorClose(iterator, undefined)
return { value: undefined, done: true }
}
// Step 8.b.iii: Let value be IteratorStepValue(iterated).
Expand Down
31 changes: 23 additions & 8 deletions packages/npm/es-iterator-helpers/shared.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
declare type FinishResults<T, U> = (results: T[]) => U
interface IteratorRecord<T> {
iterator: Iterator<T>
next: () => IteratorResult<T>
}
declare interface Iterator<T> {
next(value?: any): IteratorResult<T>
return?(value?: any): IteratorResult<T>
Expand All @@ -14,6 +19,7 @@ declare interface IteratorResult<T> {
value: T
done: boolean
}
declare type Mode = 'longest' | 'shortest' | 'strict'
declare interface InternalShared {
SLOT: WeakMap<any, any>
SLOT_GENERATOR_CONTEXT: string
Expand All @@ -28,33 +34,42 @@ declare interface InternalShared {
IteratorHelperPrototype: IteratorHelper<any>
WrapForValidIteratorPrototype: Iterator<any>
NumberCtor: NumberConstructor
MathTrunc: (x: number) => number
MathTrunc: typeof Math.trunc
NegativeInfinity: number
NumberIsNaN: (x: number) => boolean
ObjectCreate: <T>(o: T, properties?: PropertyDescriptorMap) => T
NumberIsNaN: typeof Number.isNaN
ObjectCreate: typeof Object.create
ObjectDefineProperty: typeof Object.defineProperty
ObjectGetOwnPropertyDescriptor: typeof Object.getOwnPropertyDescriptor
RangeErrorCtor: typeof RangeError
ReflectApply: (target: Function, thisArg: any, args: any[]) => any
ReflectGetPrototypeOf: (target: any) => any
ReflectApply: typeof Reflect.apply
ReflectGetPrototypeOf: typeof Reflect.getPrototypeOf
ReflectOwnKeys: typeof Reflect.ownKeys
SymbolIterator: symbol
SymbolToStringTag: symbol
TypeErrorCtor: typeof TypeError
abruptCloseIterator(iterator: Iterator<any>, error: any): void
closeIterator<T>(iterator: Iterator<T>, completion: T): T
createIteratorFromClosure<T>(closure: Iterator<T>): Iterator<T>
ensureObject(thisArg: any, what?: string): void
getIterator<T>(obj: any): Iterator<T>
getIteratorDirect<T>(obj: any): IteratorRecord<T>
getIteratorFlattenable(obj: any): IteratorRecord<any>
getMethod(
obj: any,
key: string | symbol
): ((...args: any[]) => any) | undefined
getOptionsObject<T = any>(options: T): T extends object ? T : {}
getSlot(O: any, slot: string): any
ifAbruptCloseIterator(iterator: Iterator<any>, error: any): void
isIteratorProtoNextCheckBuggy(
method: (...args: any[]) => any,
arg: any
): boolean
isObjectType(value: any): boolean
iteratorClose<T>(iterator: Iterator<T>, completion: T): T
iteratorZip<T, U = T>(
iters: Array<IteratorRecord<T>>,
mode: Mode,
padding: Array<U | undefined>,
finishResults?: FinishResults<T, U>
): Generator<U, void, unknown>
resolveSlots(O: any, slot: string): any
setSlot(O: any, slot: string, value: any): void
setUnderlyingIterator(generator: Iterator<any>, iterator: Iterator<any>): void
Expand Down
Loading

0 comments on commit bc755cb

Please sign in to comment.