15void ArrayIteratorPrototype::init(ExecutionEngine *e)
17 defineDefaultProperty(QStringLiteral(
"next"), method_next, 0);
20 ScopedString val(scope, e->newString(QLatin1String(
"Array Iterator")));
21 defineReadonlyConfigurableProperty(e->symbol_toStringTag(), val);
24ReturnedValue ArrayIteratorPrototype::method_next(
const FunctionObject *b,
const Value *that,
const Value *,
int)
27 const ArrayIteratorObject *thisObject = that->as<ArrayIteratorObject>();
29 return scope.engine->throwTypeError(QLatin1String(
"Not an Array Iterator instance"));
31 ScopedObject a(scope, thisObject->d()->iteratedObject);
33 QV4::Value undefined = Value::undefinedValue();
34 return IteratorPrototype::createIterResultObject(scope.engine, undefined,
true);
37 quint32 index = thisObject->d()->nextIndex;
38 IteratorKind itemKind = thisObject->d()->iterationKind;
40 quint32 len = a->getLength();
43 thisObject->d()->iteratedObject.set(scope.engine,
nullptr);
44 QV4::Value undefined = Value::undefinedValue();
45 return IteratorPrototype::createIterResultObject(scope.engine, undefined,
true);
48 thisObject->d()->nextIndex = index + 1;
49 if (itemKind == KeyIteratorKind) {
50 return IteratorPrototype::createIterResultObject(scope.engine, Value::fromInt32(index),
false);
53 QV4::ScopedValue elementValue(scope, a->get(index));
56 if (itemKind == ValueIteratorKind) {
57 return IteratorPrototype::createIterResultObject(scope.engine, elementValue,
false);
59 Q_ASSERT(itemKind == KeyValueIteratorKind);
61 ScopedArrayObject resultArray(scope, scope.engine->newArrayObject());
62 resultArray->arrayReserve(2);
63 resultArray->arrayPut(0, Value::fromInt32(index));
64 resultArray->arrayPut(1, elementValue);
65 resultArray->setArrayLengthUnchecked(2);
67 return IteratorPrototype::createIterResultObject(scope.engine, resultArray,
false);