Class IterUtils
@@iterator method go through the spec dance:
call obj[@@iterator]() → repeatedly invoke .next() →
unpack {value, done}.
The @@iterator string key stands in for Symbol.iterator
until real Symbol support lands; built-in iterables expose their iterator
factory under that key so user code (and Map/Set when they arrive) can
use the same protocol.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringStand-in forSymbol.iteratoruntil real Symbol support lands.static final io.karatelabs.js.JsCallableShared@@iteratorstand-in installed on built-in iterable prototypes (JsArrayPrototype,JsStringPrototype). -
Method Summary
Modifier and TypeMethodDescriptionstatic JsIteratorgetIterator(Object source, Context context) GetIterator(source) per spec 7.4.1.static booleanisIterable(Object source, Context context) True iffsourcewould yield a non-null iterator fromtryGetIterator(java.lang.Object, io.karatelabs.js.Context).static JsIteratoriteratorFromCallable(io.karatelabs.js.JsCallable factory, ObjectLike receiver, Context context) SpecGetIteratorFromMethod: invokefactorywithreceiverasthis(no args) and walk the returned iterator.static io.karatelabs.js.JsObjecttoIteratorObject(JsIterator iter) Wraps aJsIteratoras the user-visible iterator object: aJsObjectwith anextmethod returning{value, done}.static JsIteratortryGetIterator(Object source, Context context) LikegetIterator(java.lang.Object, io.karatelabs.js.Context)but returns null instead of throwing — for callers that need to gate behavior on iterability without forcing a TypeError.
-
Field Details
-
SYMBOL_ITERATOR
Stand-in forSymbol.iteratoruntil real Symbol support lands.- See Also:
-
SYMBOL_ITERATOR_METHOD
public static final io.karatelabs.js.JsCallable SYMBOL_ITERATOR_METHODShared@@iteratorstand-in installed on built-in iterable prototypes (JsArrayPrototype,JsStringPrototype). Per spec,Symbol.iteratorlives on the prototype rather than each instance — installing once meansarr.hasOwnProperty('@@iterator') === false(correct: it's inherited) and identity holds across instances.Reads
thisfrom the call context, resolves it viagetIterator(java.lang.Object, io.karatelabs.js.Context), and wraps in the spec iterator-result shape. A non-iterablethissurfaces as a TypeError fromgetIterator— same behavior as spec'sArray.prototype[Symbol.iterator]when detached from an iterable receiver.
-
-
Method Details
-
getIterator
GetIterator(source) per spec 7.4.1. ThrowsJsErrorException(TypeError) ifsourceis null/undefined or otherwise not iterable. -
tryGetIterator
LikegetIterator(java.lang.Object, io.karatelabs.js.Context)but returns null instead of throwing — for callers that need to gate behavior on iterability without forcing a TypeError. -
isIterable
True iffsourcewould yield a non-null iterator fromtryGetIterator(java.lang.Object, io.karatelabs.js.Context). -
iteratorFromCallable
public static JsIterator iteratorFromCallable(io.karatelabs.js.JsCallable factory, ObjectLike receiver, Context context) SpecGetIteratorFromMethod: invokefactorywithreceiverasthis(no args) and walk the returned iterator. Used by Set.prototype.{union/difference/...}'s GetKeysIterator step (call the set-like'skeysproperty).Lenient on the call result: spec demands an iterator Object with
.next(), but built-ins inside karate-js sometimes return raw Lists / JsArrays (e.g.Array.prototype.values()currently returns the underlying list). When the result lacks a.nextmember, fall through togetIterator(Object, Context)so those shortcuts still iterate correctly. test262 tests likeconverts-negative-zero.jsconstruct set-likes that return[-0].values()fromkeysexpecting iteration to work. -
toIteratorObject
Wraps aJsIteratoras the user-visible iterator object: aJsObjectwith anextmethod returning{value, done}. Used by built-in@@iteratorfactories (JsArray,JsString) to expose internal iteration in spec-compliant shape.
-