Bug 231166
Summary: | "Can't find variable" that's let-declared within `with` statement when executing function that's declared within same `with` statement | ||
---|---|---|---|
Product: | WebKit | Reporter: | yanahij531 |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | Normal | CC: | ashvayka, fpizlo, kevin_neal, webkit-bug-importer, ysuzuki |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari 15 | ||
Hardware: | Unspecified | ||
OS: | Unspecified |
yanahij531
In Firefox and Chrome the following code works fine, but Safari throws an error saying that the variable `a` cannot be found.
```
with({}) {
let a = 1;
function foo() {
console.log(a);
}
foo();
}
```
https://jsbin.com/hiwihiyaxi/edit?html,console
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Kevin Neal
Thanks for filing. I was able to reproduce the bug in Safari. The appropriate engineers have been notified.
Radar WebKit Bug Importer
<rdar://problem/83892140>
Alexey Shvayka
Thank you for reporting!
This bug arises because block-level function declarations in global code, which are subject to currently unimplemented legacy Annex B hoisting, always receive top-level scope instead of lexical one.
https://bugs.webkit.org/show_bug.cgi?id=163209 implements Annex B function hoisting for global code, fixing this issue.
*** This bug has been marked as a duplicate of bug 163209 ***