Bug 182414
| Summary: | Async arrow function with var declaration has incorrect shadowing | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Adam Klein <adamk> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | Normal | CC: | ashvayka, gskachkov, lharker, mark.lam, matsaa, theodorejb, webkit-bug-importer, ysuzuki |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Local Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Adam Klein
The following code, run in the shell, should print "7", but prints "undefined":
(async (v) => { print(v); var v; })(7)
Without "async", this gets the right answer.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
GSkachkov
Hmm, the same for common async function
```
(async function (v) { print(v); var v; })(7);
```
GSkachkov
Yeah and the same for generator and async generators
Yusuke Suzuki
Hm, shoud it print 7? Why doesn’t “var” hide?
GSkachkov
(In reply to Yusuke Suzuki from comment #3)
> Hm, shoud it print 7? Why doesn’t “var” hide?
I cann't find this rule in current spec but it was in ES5, there is a exist old tests:
```
https://github.com/tc39/test262/blob/master/test/language/function-code/S10.2.1_A5.2_T1.js
https://github.com/tc39/test262/blob/master/test/language/function-code/S10.2.1_A5.1_T2.js
```
Adam Klein
See step 27 of https://tc39.github.io/ecma262/#sec-functiondeclarationinstantiation. Basically, if a var-declared name has the same name as a parameter (and there aren't any parameter expressions, i.e., default parameter values or destructuring), the var declaration is ignored.
Mats Åhlberg
When running code through uglify-js it generates this type of code which breaks.
var b=async (t,a,r)=> {
console.log(a);
var a = a;
console.log(t);
console.log(a);
console.log(r);
return { t, a, r };
};
b(1, 2, 3);
replacing the var a = 1; with a=a works.
the first console log says undefined when the var is left.
the code works in firefox and chrome.
so is this a bug in webkit or the other browsers?
Radar WebKit Bug Importer
<rdar://problem/113883888>
Alexey Shvayka
*** This bug has been marked as a duplicate of bug 223533 ***