-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A named function, existing as a variable in its own local scope, shadows the global declaration #251
Comments
Thanks for this. I'm always excited to learn about JS-Interpreter bugs. Here's a minimal testcase:
Browser output: 42 This will be fixed immediately. Investigating... |
There are two bugs here:
|
In the case of a function expression with a name (e.g. var x = function foo() {...}) create an intermediate scope that contains the read-only name. Resolves issue #251.
In the case of a function expression with a name (e.g. var x = function foo() {...}) create an intermediate scope that contains the read-only name. Resolves issue #251.
Tested the fix, it works perfectly. Thank you very much! JS-Interpreter and Blockly are two great projects, your efforts are much appreciated. If there is a way to send you both a beer or two, please let me know :) |
When a named function is called in JS-Interpreter, that very function is introduced in its own local scope as a variable with the same name.
That shadows the actual function declaration in the parent scope and code, which works in NodeJS and in any browser (tested in Chromium, Firefox and Chrome), does not work in JS-Interpreter (see the end of this issue for the actual code).
Debugging the code in a browser shows that the function being called is not present in its local scope, unlike JS-Interpreter.
I skimmed the Function references at MDN but I could not find anything related to this function reassignment issue.
Problem code follows:
The text was updated successfully, but these errors were encountered: