Bug 226335
Summary: | Redeclaring an argument of the async function makes it `undefined` | ||
---|---|---|---|
Product: | WebKit | Reporter: | kotkov |
Component: | JavaScriptCore | Assignee: | 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 |
kotkov
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.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/78818618>
Alexey Shvayka
*** This bug has been marked as a duplicate of bug 223533 ***