From 05557e7fbd123f20a3da845545d5b0228fc37060 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 29 Jun 2017 12:48:47 +0200 Subject: Mark QML id objects as read-only Change-Id: I39510d59ee6f05a6e45718fd33a1815fb7c46d81 Reviewed-by: Lars Knoll --- src/qml/compiler/qqmlirbuilder.cpp | 1 + src/qml/compiler/qv4codegen.cpp | 6 +++--- src/qml/compiler/qv4codegen_p.h | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index f8165b2acd..6aa57a6390 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -1970,6 +1970,7 @@ QQmlJS::Codegen::Reference JSCodeGen::fallbackNameLookup(const QString &name) load.index = mapping.idIndex; load.result = result.asLValue(); bytecodeGenerator->addInstruction(load); + result.isReadonly = true; #if 0 if (mapping.type) { diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 394568fbb8..d3129c983d 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2279,7 +2279,7 @@ bool Codegen::visit(RegExpLiteral *ast) return false; _expr.result = Reference::fromTemp(this); - _expr.result.isLiteral = true; + _expr.result.isReadonly = true; Instruction::LoadRegExp instr; instr.result = _expr.result.asLValue(); @@ -2294,7 +2294,7 @@ bool Codegen::visit(StringLiteral *ast) return false; _expr.result = Reference::fromTemp(this); - _expr.result.isLiteral = true; + _expr.result.isReadonly = true; Instruction::LoadRuntimeString instr; instr.result = _expr.result.asLValue(); @@ -3308,7 +3308,7 @@ Codegen::Reference &Codegen::Reference::operator =(const Reference &other) needsWriteBack = false; isArgOrEval = other.isArgOrEval; codegen = other.codegen; - isLiteral = other.isLiteral; + isReadonly = other.isReadonly; global = other.global; return *this; } diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h index dbce9fb2a5..9e6f4d666c 100644 --- a/src/qml/compiler/qv4codegen_p.h +++ b/src/qml/compiler/qv4codegen_p.h @@ -134,7 +134,7 @@ public: This } type = Invalid; - bool isLValue() const { return type <= LastLValue && !isLiteral; } + bool isLValue() const { return !isReadonly; } Reference(Codegen *cg, Type type = Invalid) : type(type), codegen(cg) {} Reference() @@ -189,6 +189,7 @@ public: static Reference fromConst(Codegen *cg, QV4::ReturnedValue constant) { Reference r(cg, Const); r.constant = constant; + r.isReadonly = true; return r; } static Reference fromClosure(Codegen *cg, int functionId) { @@ -210,6 +211,7 @@ public: } static Reference fromThis(Codegen *cg) { Reference r(cg, This); + r.isReadonly = true; return r; } @@ -245,7 +247,7 @@ public: mutable int tempIndex = -1; mutable bool needsWriteBack = false; mutable bool isArgOrEval = false; - bool isLiteral = false; + bool isReadonly = false; bool global = false; Codegen *codegen; -- cgit v1.2.3