WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
244981
Can't find variable but only when Inspector is closed
https://bugs.webkit.org/show_bug.cgi?id=244981
Summary
Can't find variable but only when Inspector is closed
Eryk Napierała
Reported
2022-09-09 08:10:04 PDT
Created
attachment 462231
[details]
Video demonstrating how the error disappears after opening Inspector The code below throws an error `ReferenceError: Can't find variable: methodFactory`. ``` (() => { function methodFactory() {} class BrokenClass { classMethod = methodFactory((() => {})) } new BrokenClass(); })(); ``` It happens only when the page loads normally, without the developer tools open. Once you open the inspector and refresh, the error disappears. It's also impossible to reproduce the issue by pasting the code into the developer console. The only way to see it is to load the page directly and observe the error after. Here you can find an example, for convenience I've added an error handler so it prints out the message to HTML.
https://9wu2z2.sse.codesandbox.io
Tested on Safari 15.5 and 15.6.
Attachments
Video demonstrating how the error disappears after opening Inspector
(1.67 MB, video/mp4)
2022-09-09 08:10 PDT
,
Eryk Napierała
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Eryk Napierała
Comment 1
2022-09-09 08:16:39 PDT
FYI: when you remove additional parentheses around the arrow function from this line, the error stops occurring. ``` methodFactory((() => {})) ``` Same, when you remove the class instance creation (the last line of IIFE body).
Alexey Proskuryakov
Comment 2
2022-09-09 19:03:10 PDT
I cannot reproduce this error with Safari 15.6.1 on macOS, but not Sith Safari Technology Preview 152, suggesting that the issue is already fixed in WebKit.
Eryk Napierała
Comment 3
2022-09-10 08:30:44 PDT
Indeed, I cannot see this error occurring anymore in TP, checked on r151, WebKit 17615.1.1.2. Sorry for not checking before! Just out of curiosity, what was that about? Some parser edge-case, that's why after removing parentheses it was not breaking anymore? And why did it behave differently depending on whether the Inspector was open?
Mark Lam
Comment 4
2022-09-10 09:51:37 PDT
(In reply to Eryk Napierała from
comment #3
)
> Just out of curiosity, what was that about? Some parser edge-case, that's > why after removing parentheses it was not breaking anymore? And why did it > behave differently depending on whether the Inspector was open?
Unfortunately, we don't know which change resolved this issue. So, we won't be able to explain what happened. As for the difference in behavior with the Inspector open, running with the Inspector (as it works today) open results in slightly different bytecode being generated to support debugging, and also more aggressively capturing of closures. Perhaps the more aggressive capturing of closures may have perturbed the scoping of variables and hidden the bug? Still, this is only speculation. We won't know what the real issue is unless we spend time to investigate the issue. At this point, that might not be worthwhile given that the issue appears to be resolved, and there are other bugs / features of higher priority. If you do encounter this issue again, please do file a new bug, and we'll investigate. Thanks.
Eryk Napierała
Comment 5
2022-09-10 10:10:52 PDT
Sure thing. Thank you for the transparency, I totally get it. Thanks!
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug