From 59a90975bb7aa2dbbfe0986f19da1053275c6fef Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 17 Aug 2018 15:25:40 +0200 Subject: 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 --- src/qml/compiler/qv4compilerscanfunctions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') 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; -- cgit v1.2.3