aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp20
-rw-r--r--src/qml/jsruntime/qv4runtimeapi_p.h2
-rw-r--r--src/qml/jsruntime/qv4vme_moth.cpp2
3 files changed, 15 insertions, 9 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 2c00826b46..650f5c6735 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -715,7 +715,7 @@ ReturnedValue Runtime::method_getIterator(ExecutionEngine *engine, const Value &
return engine->newForInIteratorObject(o)->asReturnedValue();
}
-ReturnedValue Runtime::method_iteratorNext(ExecutionEngine *engine, const Value &iterator, int returnUndefinedWhenDone)
+ReturnedValue Runtime::method_iteratorNext(ExecutionEngine *engine, const Value &iterator, Value *value)
{
Q_ASSERT(iterator.isObject());
@@ -727,10 +727,14 @@ ReturnedValue Runtime::method_iteratorNext(ExecutionEngine *engine, const Value
ScopedObject o(scope, f->call(cData));
if (!o)
return engine->throwTypeError();
- ScopedValue v(scope, o->get(engine->id_done()));
- if (v->toBoolean() == true)
- return returnUndefinedWhenDone ? Encode::undefined() : Primitive::emptyValue().asReturnedValue();
- return o->get(engine->id_value());
+ ScopedValue d(scope, o->get(engine->id_done()));
+ bool done = d->toBoolean();
+ if (done) {
+ *value = Encode::undefined();
+ } else {
+ *value = o->get(engine->id_value());
+ }
+ return Encode(done);
}
ReturnedValue Runtime::method_destructureRestElement(ExecutionEngine *engine, const Value &iterator)
@@ -742,10 +746,12 @@ ReturnedValue Runtime::method_destructureRestElement(ExecutionEngine *engine, co
array->arrayCreate();
uint index = 0;
while (1) {
- ScopedValue n(scope, method_iteratorNext(engine, iterator, false));
+ ScopedValue n(scope);
+ ScopedValue done(scope, method_iteratorNext(engine, iterator, n));
if (engine->hasException)
return Encode::undefined();
- if (n->isEmpty())
+ Q_ASSERT(done->isBoolean());
+ if (done->booleanValue())
break;
array->arraySet(index, n);
++index;
diff --git a/src/qml/jsruntime/qv4runtimeapi_p.h b/src/qml/jsruntime/qv4runtimeapi_p.h
index 0d27fbfe7b..a22a053cd1 100644
--- a/src/qml/jsruntime/qv4runtimeapi_p.h
+++ b/src/qml/jsruntime/qv4runtimeapi_p.h
@@ -146,7 +146,7 @@ struct ExceptionCheck<void (*)(QV4::NoThrowEngine *, A, B, C)> {
\
/* for-in, for-of and array destructuring */ \
F(ReturnedValue, getIterator, (ExecutionEngine *engine, const Value &in, int iterator)) \
- F(ReturnedValue, iteratorNext, (ExecutionEngine *engine, const Value &iterator, int returnUndefinedWhenDone)) \
+ F(ReturnedValue, iteratorNext, (ExecutionEngine *engine, const Value &iterator, Value *value)) \
F(ReturnedValue, destructureRestElement, (ExecutionEngine *engine, const Value &iterator)) \
\
/* unary operators */ \
diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp
index 8b45226fcd..17ed1ae044 100644
--- a/src/qml/jsruntime/qv4vme_moth.cpp
+++ b/src/qml/jsruntime/qv4vme_moth.cpp
@@ -961,7 +961,7 @@ QV4::ReturnedValue VME::interpret(CppStackFrame &frame, const uchar *code)
MOTH_BEGIN_INSTR(IteratorNext)
STORE_ACC();
- acc = Runtime::method_iteratorNext(engine, accumulator, returnUndefinedWhenDone);
+ acc = Runtime::method_iteratorNext(engine, accumulator, &STACK_VALUE(value));
CHECK_EXCEPTION;
MOTH_END_INSTR(IteratorNext)