facebook / hermes

A JavaScript engine optimized for running React Native.
https://hermesengine.dev/
MIT License
9.77k stars 627 forks source link

Bug in scoped function promotion (non-strict mode) #1455

Open trossimel-sc opened 3 months ago

trossimel-sc commented 3 months ago

Bug Description

I noticed a different behaviour between Hermes and other JS engines (tried with QuickJS, JSC and V8) when running the following script

if(true) {
    function test(a) {
        if(a == "a") {
            test("b");
            return;
        }
        print ('Error');
    }

    callback1 = test;
}
if(true) {

    function test(a) {
        if(a == "a") {
            test("b");
            return;
        }
        print ('Error1');
    }

    callback2 = test;
}

callback1("a");
callback2("a");

The Expected Behavior

In Hermes the output is Error1; Error1, while in QuickJS the output is Error; Error1. Is this behaviour expected?

avp commented 3 months ago

Thanks for the report. Looks like we're resolving the test() call in the first test() function incorrectly. We'll figure out how to solve this.

tmikov commented 2 months ago

I hope this isn't code that is actually used anywhere. It isn't even valid in strict mode, which is hopefully the default everywhere.

trossimel-sc commented 2 months ago

@tmikov it's just being used for testing this behaviour