Bug 258683

Summary: Function defined within a `with` statement, but called from outside it - cannot access variables exposed by `with`
Product: WebKit Reporter: Joe <niseg98160>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: ashvayka, mark.lam, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Safari 17   
Hardware: All   
OS: All   

Description Joe 2023-06-29 10:29:09 PDT
`with` is deprecated, but there is still a bunch of legacy code that uses it.

This code works fine in Firefox and Chrome but throws "Can't find variable: foo" in Safari:

```js
let obj = {foo:"bar"};
with(obj) {
  function test() {
    console.log(foo);
  }
}
test();
```

Perchance.org, for example, uses `with` as part of its DSL, and so a subset of 'generators' are broken for Safari users.

Possibly related: https://bugs.webkit.org/show_bug.cgi?id=231166
Comment 1 Radar WebKit Bug Importer 2023-07-06 10:30:21 PDT
<rdar://problem/111857202>
Comment 2 Alexey Shvayka 2023-09-24 13:59:13 PDT
Thank you for reporting!

This bug arises because block-level function declarations in global code, which are subject to currently unimplemented legacy Annex B hoisting, always receive top-level scope instead of lexical one.

https://bugs.webkit.org/show_bug.cgi?id=163209 implements Annex B function hoisting for global code, fixing this issue.

*** This bug has been marked as a duplicate of bug 163209 ***