jerryscript-project / jerryscript

Ultra-lightweight JavaScript engine for the Internet of Things.
https://jerryscript.net
Apache License 2.0
6.91k stars 669 forks source link

Variable Scope Problem #4985

Open YiWen-y opened 2 years ago

YiWen-y commented 2 years ago
Version

Version: 3.0.0 (fea10bb7)

Test case
var foo = function() {
    var y = 200;
    try {
        throw {}
    } catch ({
        x = function(){print(y);}
    }) {
        let y = 300;
        x();
    }
};
foo();
Execution steps
/.jsvu/jerry Testcase.js
Output
300
Expected behavior
200
Description

The correct output of the test case should be 200 while jerryscript yields 300. The reason I think is that jerryscript fails to deal with the scope of the global and local variables y, where jerryscript may treat the local variable y at line 8 as the global variable, leading to output 300 at line 6.