From 052d22e116957a170e290a49d077d3e9f290a237 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 4 Sep 2018 12:19:10 +0200 Subject: ES7: Implement Tail Position Calls in the runtime Change-Id: If1629109722496b3fd10b36b2376548440f2fee9 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4functionobject.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/qml/jsruntime/qv4functionobject.cpp') diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index f6b279ddaf..93cc55f8ad 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -498,7 +498,7 @@ ReturnedValue ArrowFunction::virtualCall(const FunctionObject *fo, const Value * { ExecutionEngine *engine = fo->engine(); CppStackFrame frame; - frame.init(engine, fo->function(), argv, argc); + frame.init(engine, fo->function(), argv, argc, true); frame.setupJSFrame(engine->jsStackTop, *fo, fo->scope(), thisObject ? *thisObject : Value::undefinedValue(), Value::undefinedValue()); @@ -506,7 +506,12 @@ ReturnedValue ArrowFunction::virtualCall(const FunctionObject *fo, const Value * frame.push(); engine->jsStackTop += frame.requiredJSStackFrameSize(); - ReturnedValue result = Moth::VME::exec(&frame, engine); + ReturnedValue result; + + do { + frame.pendingTailCall = false; + result = Moth::VME::exec(&frame, engine); + } while (frame.pendingTailCall); frame.pop(); @@ -530,6 +535,7 @@ void Heap::ArrowFunction::init(QV4::ExecutionContext *scope, Function *function, Q_ASSERT(internalClass && internalClass->verifyIndex(s.engine->id_length()->propertyKey(), Index_Length)); setProperty(s.engine, Index_Length, Value::fromInt32(int(function->compiledFunction->length))); + canBeTailCalled = true; } void Heap::ScriptFunction::init(QV4::ExecutionContext *scope, Function *function) -- cgit v1.2.1