hermes icon indicating copy to clipboard operation
hermes copied to clipboard

Bug in scoped function promotion (non-strict mode)

Open trossimel-sc opened this issue 1 year ago • 3 comments

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?

trossimel-sc avatar Jul 09 '24 08:07 trossimel-sc

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.

avp avatar Jul 09 '24 22:07 avp

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.

tmikov avatar Jul 11 '24 18:07 tmikov

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

trossimel-sc avatar Jul 12 '24 07:07 trossimel-sc