Bug 175254
Summary: | ReferenceError when accessing closed over let/const inside an eval | ||
---|---|---|---|
Product: | WebKit | Reporter: | Diogo Franco <diogomfranco> |
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
Status: | RESOLVED FIXED | ||
Severity: | Normal | CC: | fpizlo, mark.lam, saam, ysuzuki |
Priority: | P2 | ||
Version: | Safari 10 | ||
Hardware: | All | ||
OS: | All |
Diogo Franco
This problem has affected me for quite a while, but I have managed to get a small reproducible snippet going.
```
eval("const loggers = new Map(); const defaultLogger = getDefaultLogger(); function getDefaultLogger() { return loggers.get('default'); }")
```
This crashes with a `ReferenceError` on accessing loggers inside the getDefaultLogger closure.
This error only happens inside an `eval`. Even changing the kind of `eval` to be `Function("the eval argument from above")()` instead avoids the error.
Changing the `loggers` declaration into a `var` also works around the issue.
This kind of code is probably impossible to find in the wild, but it affects developers working with webpack, as one of its debugging modes wraps each individual bundled module into an eval statement for faster source map updates. If the developer both enables the "eval" mode and skips converting ES2015 code to ES5 (because your local development browser, Safari in this case, ought to support it), you get mystery crashes on valid code.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Yusuke Suzuki
Thank you. It seems that this issue is fixed :)
Safari TP does not pose this issue.