public ArrayLikeIterator(ArrayOperations obj) { _obj = obj; _length = obj.GetLength(); Reset(); }
public override bool TryIteratorStep(out ObjectInstance nextItem) { uint len; if (_typedArray is not null) { _typedArray._viewedArrayBuffer.AssertNotDetached(); len = _typedArray.Length; } else { len = _operations.GetLength(); } if (!_closed && _position < len) { JsValue value; if (_typedArray is not null) { nextItem = _kind switch { ArrayIteratorType.Key => new ValueIteratorPosition(_engine, _position), ArrayIteratorType.Value => new ValueIteratorPosition(_engine, _typedArray[(int)_position]), _ => new KeyValueIteratorPosition(_engine, _position, _typedArray[(int)_position]) }; } else { _operations.TryGetValue(_position, out value); if (_kind == ArrayIteratorType.Key) { nextItem = new ValueIteratorPosition(_engine, _position); } else if (_kind == ArrayIteratorType.Value) { nextItem = new ValueIteratorPosition(_engine, value); } else { nextItem = new KeyValueIteratorPosition(_engine, _position, value); } } _position++; return(true); } _closed = true; nextItem = KeyValueIteratorPosition.Done(_engine); return(false); }