diff options
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 52 | ||||
-rw-r--r-- | tests/auto/qml/v4misc/tst_v4misc.cpp | 1 |
2 files changed, 28 insertions, 25 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 295ce08071..54aef16970 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -3083,34 +3083,36 @@ int Codegen::defineFunction(const QString &name, AST::Node *ast, statementList(body); - bytecodeGenerator->setLocation(ast->lastSourceLocation()); - _context->emitBlockFooter(this); - - if (_returnLabel || hasError || !functionEndsWithReturn) { - if (_returnLabel) - _returnLabel->link(); + if (!hasError) { + bytecodeGenerator->setLocation(ast->lastSourceLocation()); + _context->emitBlockFooter(this); + + if (_returnLabel || !functionEndsWithReturn) { + if (_returnLabel) + _returnLabel->link(); + + if (_returnLabel || requiresReturnValue) { + Instruction::LoadReg load; + load.reg = Moth::StackSlot::createRegister(_returnAddress); + bytecodeGenerator->addInstruction(load); + } else { + Reference::fromConst(this, Encode::undefined()).loadInAccumulator(); + } - if (_returnLabel || requiresReturnValue) { - Instruction::LoadReg load; - load.reg = Moth::StackSlot::createRegister(_returnAddress); - bytecodeGenerator->addInstruction(load); - } else { - Reference::fromConst(this, Encode::undefined()).loadInAccumulator(); + bytecodeGenerator->addInstruction(Instruction::Ret()); } - bytecodeGenerator->addInstruction(Instruction::Ret()); - } - - Q_ASSERT(_context == _functionContext); - bytecodeGenerator->finalize(_context); - _context->registerCountInFunction = bytecodeGenerator->registerCount(); - static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_BYTECODE"); - if (showCode) { - qDebug() << "=== Bytecode for" << _context->name << "strict mode" << _context->isStrict - << "register count" << _context->registerCountInFunction << "implicit return" << requiresReturnValue; - QV4::Moth::dumpBytecode(_context->code, _context->locals.size(), _context->arguments.size(), - _context->line, _context->lineNumberMapping); - qDebug(); + Q_ASSERT(_context == _functionContext); + bytecodeGenerator->finalize(_context); + _context->registerCountInFunction = bytecodeGenerator->registerCount(); + static const bool showCode = qEnvironmentVariableIsSet("QV4_SHOW_BYTECODE"); + if (showCode) { + qDebug() << "=== Bytecode for" << _context->name << "strict mode" << _context->isStrict + << "register count" << _context->registerCountInFunction << "implicit return" << requiresReturnValue; + QV4::Moth::dumpBytecode(_context->code, _context->locals.size(), _context->arguments.size(), + _context->line, _context->lineNumberMapping); + qDebug(); + } } qSwap(_returnAddress, returnAddress); diff --git a/tests/auto/qml/v4misc/tst_v4misc.cpp b/tests/auto/qml/v4misc/tst_v4misc.cpp index da7b610978..c35f412870 100644 --- a/tests/auto/qml/v4misc/tst_v4misc.cpp +++ b/tests/auto/qml/v4misc/tst_v4misc.cpp @@ -115,6 +115,7 @@ void tst_v4misc::parserMisc_data() QTest::newRow("for (va() in obj) {}") << QString("ReferenceError: Invalid left-hand side expression for 'in' expression"); QTest::newRow("[1]=7[A=8=9]") << QString("ReferenceError: left-hand side of assignment operator is not an lvalue"); QTest::newRow("var asmvalsLen = asmvals{{{{{ngth}}}}};") << QString("SyntaxError: Expected token `;'"); + QTest::newRow("T||9[---L6i]") << QString("ReferenceError: Prefix ++ operator applied to value that is not a reference."); } void tst_v4misc::parserMisc() |