diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-08-30 12:58:55 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-08-31 06:08:41 +0000 |
commit | ee565b3db656b5b9bfd57d98d53b898c1a62e1f0 (patch) | |
tree | 857b0f3c09144e68ee0d6cfdf25a227df2f76c8b /src/qml/compiler/qv4codegen.cpp | |
parent | ebf9365b5c7ec1e4828be88beeb930b4de52f35b (diff) |
Correctly create methods for functions in object literals
Methods behave slightly different than normal functions as they have
a home object and define how super property access is being done. To
implement this correctly, we need to create these methods during object
initialization time.
Change-Id: Ib3f670c8790b882c6472de786938ca4f0b73f66f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 412d787d11..b09deb1eaf 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -2450,7 +2450,7 @@ bool Codegen::visit(ObjectPattern *ast) for (; it; it = it->next) { PatternProperty *p = it->property; AST::ComputedPropertyName *cname = AST::cast<AST::ComputedPropertyName *>(p->name); - if (cname || p->type == PatternProperty::Getter || p->type == PatternProperty::Setter) + if (cname || p->type != PatternProperty::Literal) break; QString name = p->name->asString(); uint arrayIndex = QV4::String::toArrayIndex(name); @@ -2477,7 +2477,9 @@ bool Codegen::visit(ObjectPattern *ast) PatternProperty *p = it->property; AST::ComputedPropertyName *cname = AST::cast<AST::ComputedPropertyName *>(p->name); ObjectLiteralArgument argType = ObjectLiteralArgument::Value; - if (p->type == PatternProperty::Getter) + if (p->type == PatternProperty::Method) + argType = ObjectLiteralArgument::Method; + else if (p->type == PatternProperty::Getter) argType = ObjectLiteralArgument::Getter; else if (p->type == PatternProperty::Setter) argType = ObjectLiteralArgument::Setter; @@ -2508,10 +2510,20 @@ bool Codegen::visit(ObjectPattern *ast) push(Reference::fromAccumulator(this)); { RegisterScope innerScope(this); - Reference value = expression(p->initializer); - if (hasError) - return false; - value.loadInAccumulator(); + if (p->type != PatternProperty::Literal) { + // need to get the closure id for the method + FunctionExpression *f = p->initializer->asFunctionDefinition(); + Q_ASSERT(f); + int function = defineFunction(f->name.toString(), f, f->formals, f->body); + if (hasError) + return false; + Reference::fromConst(this, Encode(function)).loadInAccumulator(); + } else { + Reference value = expression(p->initializer); + if (hasError) + return false; + value.loadInAccumulator(); + } } push(Reference::fromAccumulator(this)); } |