Bug 226335

Summary: Redeclaring an argument of the async function makes it `undefined`
Product: WebKit Reporter: kotkov
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: ashvayka, fpizlo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: All   
OS: All   

Description kotkov 2021-05-27 09:10:33 PDT
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.
Comment 1 Radar WebKit Bug Importer 2021-06-03 09:11:19 PDT
<rdar://problem/78818618>
Comment 2 Alexey Shvayka 2023-10-15 11:59:27 PDT

*** This bug has been marked as a duplicate of bug 223533 ***