Bug 226335 - Redeclaring an argument of the async function makes it `undefined`
Summary: Redeclaring an argument of the async function makes it `undefined`
Status: RESOLVED DUPLICATE of bug 223533
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 14
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-27 09:10 PDT by kotkov
Modified: 2023-10-15 11:59 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***