diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-11 22:23:56 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-13 12:55:20 +0000 |
commit | 3d5ba9f86e32950204bfcdf6591c4740a8ef7507 (patch) | |
tree | 9c599ad6b7fd2bd06d0880dde70ff21d6f522bef /src/qml/jsruntime/qv4runtime.cpp | |
parent | 2d6b08bd17377aa6bcb663029a196a8d19cac6ac (diff) |
Add instructions to simplify for-of loops
Added an IteratorNext instruction to fetch the next
iteration value (empty if the iterator is done).
This will also help to implement array destructuring without
requiring huge amounts of byte code.
Change-Id: If96c1e81471e5e2b0b7b2af122238d87741aa371
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4runtime.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 986684302c..eadbcb9557 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -715,6 +715,24 @@ ReturnedValue Runtime::method_getIterator(ExecutionEngine *engine, const Value & return engine->newForInIteratorObject(o)->asReturnedValue(); } +ReturnedValue Runtime::method_iteratorNext(ExecutionEngine *engine, const Value &iterator) +{ + Q_ASSERT(iterator.isObject()); + + Scope scope(engine); + ScopedFunctionObject f(scope, static_cast<const Object &>(iterator).get(engine->id_next())); + if (!f) + return engine->throwTypeError(); + JSCallData cData(scope, 0, nullptr, &iterator); + ScopedObject o(scope, f->call(cData)); + if (!o) + return engine->throwTypeError(); + ScopedValue v(scope, o->get(engine->id_done())); + if (v->toBoolean() == true) + return Primitive::emptyValue().asReturnedValue(); + return o->get(engine->id_value()); +} + void Runtime::method_storeNameSloppy(ExecutionEngine *engine, int nameIndex, const Value &value) { Scope scope(engine); |