diff options
| author | Lars Knoll <lars.knoll@qt.io> | 2017-06-14 14:32:49 +0200 |
|---|---|---|
| committer | Lars Knoll <lars.knoll@qt.io> | 2017-06-20 09:56:04 +0000 |
| commit | abc4707fbdf7cc96fe255e4524c52eaf7127acef (patch) | |
| tree | 8d1290e9fc0e023bf5e6f8dcf6f5159168fc928d /src/qml/compiler/qv4codegen.cpp | |
| parent | 4f9edb6e986a3b926254ec012cdfc78aef4b7e57 (diff) | |
Implement typeof
Change-Id: I52db8e7a28de8f27699283543e1788d524a0c8b1
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
| -rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 0665ba65ec..1620307d46 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2306,14 +2306,26 @@ bool Codegen::visit(TypeOfExpression *ast) if (hasError) return false; + _expr.result = Reference::fromTemp(this, bytecodeGenerator->newTemp()); + TempScope scope(_function); - Result expr = expression(ast->expression); + Reference expr = expression(ast->expression); if (hasError) return false; - IR::ExprList *args = _function->New<IR::ExprList>(); - args->init(reference(*expr)); - _expr.code = call(_block->NAME(IR::Name::builtin_typeof, ast->typeofToken.startLine, ast->typeofToken.startColumn), args); + + if (expr.type == Reference::Name) { + // special handling as typeof doesn't throw here + Moth::Instruction::CallBuiltinTypeofName instr; + instr.name = expr.nameIndex; + instr.result = _expr.result.asLValue(); + bytecodeGenerator->addInstruction(instr); + } else { + Moth::Instruction::CallBuiltinTypeofValue instr; + instr.value = expr.asRValue(); + instr.result = _expr.result.asLValue(); + bytecodeGenerator->addInstruction(instr); + } return false; } |
