15void MapIteratorPrototype::init(ExecutionEngine *e)
17 defineDefaultProperty(QStringLiteral(
"next"), method_next, 0);
20 ScopedString val(scope, e->newString(QLatin1String(
"Map Iterator")));
21 defineReadonlyConfigurableProperty(e->symbol_toStringTag(), val);
24ReturnedValue MapIteratorPrototype::method_next(
const FunctionObject *b,
const Value *that,
const Value *,
int)
27 const MapIteratorObject *thisObject = that->as<MapIteratorObject>();
29 return scope.engine->throwTypeError(QLatin1String(
"Not a Map Iterator instance"));
31 Scoped<MapObject> s(scope, thisObject->d()->iteratedMap);
32 uint index = thisObject->d()->mapNextIndex;
33 IteratorKind itemKind = thisObject->d()->iterationKind;
36 QV4::Value undefined = Value::undefinedValue();
37 return IteratorPrototype::createIterResultObject(scope.engine, undefined,
true);
40 Value *arguments = scope.constructUndefined(2);
42 while (index < s->d()->esTable->size()) {
43 s->d()->esTable->iterate(index, &arguments[0], &arguments[1]);
44 thisObject->d()->mapNextIndex = index + 1;
46 ScopedValue result(scope);
48 if (itemKind == KeyIteratorKind) {
49 result = arguments[0];
50 }
else if (itemKind == ValueIteratorKind) {
51 result = arguments[1];
53 Q_ASSERT(itemKind == KeyValueIteratorKind);
55 result = scope.engine->newArrayObject();
57 Scoped<ArrayObject> resultArray(scope, result);
58 resultArray->arrayReserve(2);
59 resultArray->arrayPut(0, arguments[0]);
60 resultArray->arrayPut(1, arguments[1]);
61 resultArray->setArrayLengthUnchecked(2);
64 return IteratorPrototype::createIterResultObject(scope.engine, result,
false);
67 thisObject->d()->iteratedMap.set(scope.engine,
nullptr);
68 QV4::Value undefined = Value::undefinedValue();
69 return IteratorPrototype::createIterResultObject(scope.engine, undefined,
true);