Skip to content
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

Fix function hoisting behaviour (non-strict mode) #1547

Open
wants to merge 6 commits into
base: static_h
Choose a base branch
from

Commits on Oct 9, 2024

  1. Fix function hoisting behaviour (non-strict mode)

    Hermes currently has divergent function hoisting behavior compared to QuickJS, V8, and JSC in non-strict mode. The following code prints Error1; Error1 instead of Error; Error1
    
    ```
    {
        function test1(a) {
            if(a == "a") {
                test1("b");
                return;
            }
            print ('Error');
        }
    
        callback1 = test1;
    }
    
    {
        function test1(a) {
            if(a == "a") {
                test1("b");
                return;
            }
            print ('Error1');
        }
    
        callback2 = test1;
    }
    
    callback1("a");
    callback2("a");
    ```
    
    This happens as scoped function promoted to global scope are treated as global function, like for `var`.
    New approach:
    - Creating two declaration associated with each promoted function identifier and storing the function code into two pointers, one global and one scoped. Each declaration has one pointer associated.
    - Each identifier which is not a declaration is resolved into either the global or scoped declaration of the promoted function
    
    Test 262 results:
    - 100% on test/statements, 98.53% overall. **Nothing changed in the results** before and after the change.
    
    ---
    trossimel-sc committed Oct 9, 2024
    Configuration menu
    Copy the full SHA
    abbc968 View commit details
    Browse the repository at this point in the history

Commits on Oct 21, 2024

  1. Configuration menu
    Copy the full SHA
    0566853 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a770056 View commit details
    Browse the repository at this point in the history
  3. improve the code

    trossimel-sc committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    524df94 View commit details
    Browse the repository at this point in the history
  4. improve the comments

    trossimel-sc committed Oct 21, 2024
    Configuration menu
    Copy the full SHA
    940dd9f View commit details
    Browse the repository at this point in the history

Commits on Oct 27, 2024

  1. address suggestion

    trossimel-sc committed Oct 27, 2024
    Configuration menu
    Copy the full SHA
    fbbed67 View commit details
    Browse the repository at this point in the history