diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-08 14:34:58 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-11 07:17:12 +0000 |
commit | 01a1ad296c2b8325476abd6d28c8cc2463c42eb6 (patch) | |
tree | 4acaaf72782e634615e74c2da52227206cd16a42 /src/qml/compiler/qv4compilerscanfunctions.cpp | |
parent | 4cf7e80c5740912804383e4d866ba12b2520d0e6 (diff) |
Support destructuring inside catch()
Change-Id: Ib60b56ac6a7111446e01235564a4cf92ad8ad025
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index f7100a1d1a..4dbd11ef1c 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -387,8 +387,19 @@ bool ScanFunctions::visit(Catch *ast) enterEnvironment(ast, ContextType::Block); _context->name = QLatin1String("CatchBlock"); _context->isCatchBlock = true; - _context->catchedVariable = ast->name.toString(); - _context->addLocalVar(ast->name.toString(), Context::MemberType::VariableDefinition, VariableScope::Let); + QString caughtVar = ast->patternElement->bindingIdentifier; + if (caughtVar.isEmpty()) + caughtVar = QStringLiteral("@caught"); + _context->addLocalVar(caughtVar, Context::MemberType::VariableDefinition, VariableScope::Let); + + _context->caughtVariable = caughtVar; + if (_context->isStrict && + (caughtVar == QLatin1String("eval") || caughtVar == QLatin1String("arguments"))) { + _cg->throwSyntaxError(ast->identifierToken, QStringLiteral("Catch variable name may not be eval or arguments in strict mode")); + return false; + } + Node::accept(ast->patternElement, this); + // skip the block statement Node::accept(ast->statement->statements, this); return false; } @@ -567,7 +578,7 @@ void ScanFunctions::calcEscapingVariables() } if (c->contextType == ContextType::Block && c->isCatchBlock) { c->requiresExecutionContext = true; - auto m = c->members.find(c->catchedVariable); + auto m = c->members.find(c->caughtVariable); m->canEscape = true; } if (allVarsEscape) { |