aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compilerscanfunctions.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-08-17 15:25:40 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-20 12:58:10 +0000
commit59a90975bb7aa2dbbfe0986f19da1053275c6fef (patch)
treed2addd57c71e2ea91788d145722c405e8c1c2f1a /src/qml/compiler/qv4compilerscanfunctions.cpp
parent88edd5be4fad814825a9c9a831cb5e03c8f2deea (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>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions.cpp2
1 files changed, 1 insertions, 1 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;