14void StringIteratorPrototype::init(ExecutionEngine *e)
16 defineDefaultProperty(QStringLiteral(
"next"), method_next, 0);
19 ScopedString val(scope, e->newString(QLatin1String(
"String Iterator")));
20 defineReadonlyConfigurableProperty(e->symbol_toStringTag(), val);
23ReturnedValue StringIteratorPrototype::method_next(
const FunctionObject *b,
const Value *that,
const Value *,
int)
26 const StringIteratorObject *thisObject = that->as<StringIteratorObject>();
28 return scope.engine->throwTypeError(QLatin1String(
"Not an String Iterator instance"));
30 ScopedString s(scope, thisObject->d()->iteratedString);
32 QV4::Value undefined = Value::undefinedValue();
33 return IteratorPrototype::createIterResultObject(scope.engine, undefined,
true);
36 quint32 index = thisObject->d()->nextIndex;
38 QString str = s->toQString();
39 quint32 len = str.size();
42 thisObject->d()->iteratedString.set(scope.engine,
nullptr);
43 QV4::Value undefined = Value::undefinedValue();
44 return IteratorPrototype::createIterResultObject(scope.engine, undefined,
true);
47 QChar ch = str.at(index);
49 if (ch.unicode() >= 0xd800 && ch.unicode() <= 0xdbff && index + 1 != len) {
50 ch = str.at(index + 1);
51 if (ch.unicode() >= 0xdc00 && ch.unicode() <= 0xdfff)
55 thisObject->d()->nextIndex += num;
57 ScopedString resultString(scope, scope.engine->newString(s->toQString().mid(index, num)));
58 return IteratorPrototype::createIterResultObject(scope.engine, resultString,
false);