diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-17 15:25:40 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-20 12:58:10 +0000 |
commit | 59a90975bb7aa2dbbfe0986f19da1053275c6fef (patch) | |
tree | d2addd57c71e2ea91788d145722c405e8c1c2f1a | |
parent | 88edd5be4fad814825a9c9a831cb5e03c8f2deea (diff) |
Fix function name bindings for function declarations
For function expressions such as
var foo = function foo() {
return foo;
}
it is important to have a separate binding for "foo" within the scope of
the function. However for function declarations this does not apply:
function foo() {
foo = 2;
}
foo()
console.log(foo) // should print 2
Therefore we should enter the ThisFunctionName type of binding only for
function expressions or (generally) for the case where the name is not
intended to be entered into the surrounding environment at
defineFunction() time.
This is covered implicitly in
language/module-code/eval-gtbndng-indirect-update-dflt.js
Change-Id: I1e5114a93ac7db9e5fcea04b1b3e1de4ad7bff6d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/ecmascripttests/TestExpectations | 1 |
2 files changed, 1 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index 7a8622dc02..06335b3aa0 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -611,7 +611,7 @@ bool ScanFunctions::enterFunction(Node *ast, const QString &name, FormalParamete } - if (!name.isEmpty() && (!formals || !formals->containsName(name))) + if (!enterName && (!name.isEmpty() && (!formals || !formals->containsName(name)))) _context->addLocalVar(name, Context::ThisFunctionName, VariableScope::Var); _context->formals = formals; diff --git a/tests/auto/qml/ecmascripttests/TestExpectations b/tests/auto/qml/ecmascripttests/TestExpectations index cabb6e9b72..136855e5c5 100644 --- a/tests/auto/qml/ecmascripttests/TestExpectations +++ b/tests/auto/qml/ecmascripttests/TestExpectations @@ -1939,7 +1939,6 @@ language/global-code/script-decl-var.js fails language/identifiers/other_id_continue.js fails language/identifiers/other_id_start-escaped.js fails language/identifiers/other_id_start.js fails -language/module-code/eval-gtbndng-indirect-update-dflt.js strictFails language/module-code/instn-iee-bndng-cls.js strictFails language/module-code/instn-iee-bndng-const.js strictFails language/module-code/instn-iee-bndng-let.js strictFails |