WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED DUPLICATE of
bug 163209
265526
Incorrect `with` statement behavior - function call breaks out of `with` 'scope'
https://bugs.webkit.org/show_bug.cgi?id=265526
Summary
Incorrect `with` statement behavior - function call breaks out of `with` 'scope'
Joe
Reported
2023-11-29 08:45:49 PST
(Obligatory: The `with` statement has long been deprecated, but unfortunately since there is a lot of legacy code which relies on it, one cannot always avoid interacting with code that relies on `with`.) The following code works fine on all other browsers. Safari throws "ReferenceError: Can't find variable: abc". ``` with({abc:3}) { function foo() { console.log(abc); } foo(); } ``` I am managing a large-ish (~4M MAU) platform for which this has become an issue in certain situations, and currently I just have to tell users "Please use Firefox or Chrome". I'd like to eventually get my hands dirty and try to implement a hacky fix here (it involves interaction with user-land code, so it's not easy), but if the `with` behavior could be brought into line with other engines that would be excellent.
Attachments
Add attachment
proposed patch, testcase, etc.
Joe
Comment 1
2023-11-29 08:53:07 PST
One weird thing I noticed: If I pause the debugger, and then run the code in the console, it works fine. If the debugger is not paused and I run the code, then I get the ReferenceError that I mentioned in the previous message.
Karl Dubost
Comment 2
2023-11-29 19:08:53 PST
it's working for me with and without the debugger paused. So there is something else going on.
Radar WebKit Bug Importer
Comment 3
2023-12-06 08:46:13 PST
<
rdar://problem/119258532
>
Mark Lam
Comment 4
2024-01-23 10:43:37 PST
Hi Joe, can you tell me what website(s) are impacted by this, or if you don't want to disclose that publicly, can you email me the details? That will help us prioritize this accordingly. Thanks.
Alexey Shvayka
Comment 5
2024-01-23 14:01:14 PST
Thank you Joe for filing this so very nicely! The issue was fixed in
https://commits.webkit.org/268553@main
, please retry with the newest Safari Technology Preview. (In reply to Joe from
comment #1
)
> One weird thing I noticed: If I pause the debugger, and then run the code in > the console, it works fine. If the debugger is not paused and I run the > code, then I get the ReferenceError that I mentioned in the previous message.
This makes sense: before
https://bugs.webkit.org/show_bug.cgi?id=163209
was fixed, functions declared in global scope but inside a block (`with` statement block) were erroneously created in global scope. *** This bug has been marked as a duplicate of
bug 163209
***
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