diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-09-18 21:37:35 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-20 14:27:31 +0200 |
commit | 4d0812e4bda7d978ef2054e2f067ee15071a7cef (patch) | |
tree | 10cdabb63c820674cbf020c85a1ab8ffe699d127 /src/qml/compiler/qqmlcodegenerator.cpp | |
parent | 6c461e9c8c5816776f98ebc2c28180e990cfce03 (diff) |
[new compiler] Fix crash with empty function bodies
Change defineFunction back to taking AST::SourceElements for the body (how it
was originally)
Then in the new compiler, do the same "function->body ? function->body->elements
: 0" dance for function expressions and for binding expressions, synthesize the
AST::SourceElements.
Change-Id: Iaedb15925a6bb8482cde2b371a6e781477252435
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler/qqmlcodegenerator.cpp')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index 0802358d93..0f10b0fed7 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -1098,9 +1098,20 @@ void JSCodeGen::generateJSCodeForFunctionsAndBindings(const QString &fileName, P else name = QStringLiteral("%qml-expression-entry"); + AST::SourceElements *body; + if (function) + body = function->body ? function->body->elements : 0; + else { + // Synthesize source elements. + QQmlJS::MemoryPool *pool = output->jsParserEngine.pool(); + AST::SourceElement *element = new (pool) AST::StatementSourceElement(static_cast<AST::Statement*>(node)); + body = new (output->jsParserEngine.pool()) AST::SourceElements(element); + body = body->finish(); + } + defineFunction(name, node, function ? function->formals : 0, - function ? function->body->elements : node, function ? FunctionCode : QmlBinding); + body, function ? FunctionCode : QmlBinding); } |