<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>265526</bug_id>
          
          <creation_ts>2023-11-29 08:45:49 -0800</creation_ts>
          <short_desc>Incorrect `with` statement behavior - function call breaks out of `with` &apos;scope&apos;</short_desc>
          <delta_ts>2024-01-23 14:01:14 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>Safari 17</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>163209</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Joe">niseg98160</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ashvayka</cc>
    
    <cc>karlcow</cc>
    
    <cc>mark.lam</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1995607</commentid>
    <comment_count>0</comment_count>
    <who name="Joe">niseg98160</who>
    <bug_when>2023-11-29 08:45:49 -0800</bug_when>
    <thetext>(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 &quot;ReferenceError: Can&apos;t find variable: abc&quot;.

```
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 &quot;Please use Firefox or Chrome&quot;. I&apos;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&apos;s not easy), but if the `with` behavior could be brought into line with other engines that would be excellent.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1995609</commentid>
    <comment_count>1</comment_count>
    <who name="Joe">niseg98160</who>
    <bug_when>2023-11-29 08:53:07 -0800</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1995798</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-11-29 19:08:53 -0800</bug_when>
    <thetext>it&apos;s working for me with and without the debugger paused. 
So there is something else going on.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1997390</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-12-06 08:46:13 -0800</bug_when>
    <thetext>&lt;rdar://problem/119258532&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2006919</commentid>
    <comment_count>4</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2024-01-23 10:43:37 -0800</bug_when>
    <thetext>Hi Joe, can you tell me what website(s) are impacted by this, or if you don&apos;t want to disclose that publicly, can you email me the details?  That will help us prioritize this accordingly.  Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2006992</commentid>
    <comment_count>5</comment_count>
    <who name="Alexey Shvayka">ashvayka</who>
    <bug_when>2024-01-23 14:01:14 -0800</bug_when>
    <thetext>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)
&gt; One weird thing I noticed: If I pause the debugger, and then run the code in
&gt; the console, it works fine. If the debugger is not paused and I run the
&gt; 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 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>