[Webkit-unassigned] [Bug 226335] New: Redeclaring an argument of the async function makes it `undefined`

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu May 27 09:10:33 PDT 2021


https://bugs.webkit.org/show_bug.cgi?id=226335

            Bug ID: 226335
           Summary: Redeclaring an argument of the async function makes it
                    `undefined`
           Product: WebKit
           Version: Safari 14
          Hardware: All
                OS: All
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: kotkov at apache.org

Consider the following JavaScript code example:

function foo(x) {
    console.log(x);
    var x = 2;
    console.log(x);
}
foo(1);

async function bar(x) {
    console.log(x);
    var x = 2;
    console.log(x);
}
bar(1);

Running this example in stable Chromium or Firefox versions produces the following expected result:

1
2
1
2

Running this example in Safari produces the following *unexpected* result:

1
2
undefined
2

This issue reproduces in Safari 12.x, 13.x, 14.x on macOS and iOS.
This issue reproduces in Safari 14.1.1 on macOS 11.4.

Apparently, redeclaring the argument `x` of an async function with `var x` in the function's body causes the initial argument to lose its value and become `undefined`. As shown in the above example, this behavior is specific to async functions and doesn't reproduce in non-async functions.

Redeclaring function arguments in this way is a common technique used by code minifiers such as uglify-js, as that sometimes allows reusing shorter variable names.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20210527/1f21bc04/attachment-0001.htm>


More information about the webkit-unassigned mailing list