Closed malwarebin closed 1 year ago
Thanks for this. I'm always excited to learn about JS-Interpreter bugs.
Here's a minimal testcase:
function myFunc() {
myFunc = 42;
}
myFunc();
alert(myFunc);
Browser output: 42 JS-Interpreter output: [object Function]
This will be fixed immediately. Investigating...
There are two bugs here:
alert((function foo() { foo = 42; return foo; })())
should return the function object in nonstrict mode, and throw TypeError: Assignment to constant variable
in strict mode, but in fact returns 42
.
alert((function foo(foo) { foo = 42; return foo;})())
and
alert((function foo() { var foo = 42; return foo;})())
should both return 42 in either strict or nonstrict mode.
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: