Bug 219275
Summary: | block scope + const + hoisted function using the const = ReferenceError | ||
---|---|---|---|
Product: | WebKit | Reporter: | Jakub G (dailymotion) <jakub.g.opensource> |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | Normal | CC: | ashvayka, fpizlo, ross.kirsling, webkit-bug-importer, ysuzuki |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari 14 | ||
Hardware: | All | ||
OS: | iOS 12 |
Jakub G (dailymotion)
Open the following test page:
> https://jg-testpage.netlify.app/safari/const-inside-if.html
Its contents for reference:
```
<script>
if (true) {
const MY_CONST = 'MY_CONST';
function myFunction() {
console.log(MY_CONST);
}
myFunction();
}
</script>
```
Expected:
> see "MY_CONST" logged
Actual:
> ReferenceError
Other browsers' behavior:
> "MY_CONST" is logged in latest Chrome, Firefox, EdgeLegacy 18
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Jakub G (dailymotion)
I repro the issue on all stable versions of Safari from 14.0 down to 10.1 (didn't test more)
Jakub G (dailymotion)
Just a small update: it seems to work fine in Safari in strict mode, but not in sloppy mode.
https://jg-testpage.netlify.app/safari/const-inside-if.html
https://jg-testpage.netlify.app/safari/const-inside-if-strict.html
Chrome 50+: OK both strict/sloppy mode
Firefox 50+: OK both strict/sloppy mode
Safari: OK strict mode, KO in sloppy mode
Radar WebKit Bug Importer
<rdar://problem/71849401>
Ross Kirsling
Thanks for the report -- Annex B.3.3 non-conformance has been deprioritized for a long time, but I think there is intention to correct this in the near future.
*** This bug has been marked as a duplicate of bug 163209 ***