-static inline EncodedJSValue JSC_HOST_CALL arrayIteratorNext(CallFrame* callFrame)
-{
- JSArrayIterator* iterator = jsDynamicCast<JSArrayIterator*>(callFrame->thisValue());
- if (!iterator) {
- ASSERT_NOT_REACHED();
- return JSValue::encode(throwTypeError(callFrame, ASCIILiteral("Cannot call ArrayIterator.next() on a non-ArrayIterator object")));
- }
- JSObject* iteratedObject = iterator->iteratedObject();
- size_t index = iterator->nextIndex();
- ArrayIterationKind kind = iterator->iterationKind();
- JSValue jsLength = JSValue(iteratedObject).get(callFrame, callFrame->propertyNames().length);
- if (callFrame->hadException())
- return JSValue::encode(jsNull());
-
- size_t length = jsLength.toUInt32(callFrame);
- if (callFrame->hadException())
- return JSValue::encode(jsNull());
-
- if (index >= length) {
- iterator->finish();
- return createIteratorResult(callFrame, kind, index, jsUndefined(), true);
- }
- if (JSValue result = iteratedObject->tryGetIndexQuickly(index)) {
- iterator->setNextIndex(index + 1);
- return createIteratorResult(callFrame, kind, index, result, false);
- }
-
- JSValue result = jsUndefined();
- PropertySlot slot(iteratedObject);
- if (kind > ArrayIterateSparseTag) {
- // We assume that the indexed property will be an own property so cache the getOwnProperty
- // method locally
- auto getOwnPropertySlotByIndex = iteratedObject->methodTable()->getOwnPropertySlotByIndex;
- while (index < length) {
- if (getOwnPropertySlotByIndex(iteratedObject, callFrame, index, slot)) {
- result = slot.getValue(callFrame, index);
- break;
- }
- if (iteratedObject->getPropertySlot(callFrame, index, slot)) {
- result = slot.getValue(callFrame, index);
- break;
- }
- index++;
- }
- } else if (iteratedObject->getPropertySlot(callFrame, index, slot))
- result = slot.getValue(callFrame, index);
-
- if (index == length)
- iterator->finish();
- else
- iterator->setNextIndex(index + 1);
- return createIteratorResult(callFrame, kind, index, jsUndefined(), index == length);
-}
-
-EncodedJSValue JSC_HOST_CALL arrayIteratorNextKey(CallFrame* callFrame)
-{
- return arrayIteratorNext(callFrame);
-}
-
-EncodedJSValue JSC_HOST_CALL arrayIteratorNextValue(CallFrame* callFrame)