Bug 258683 - Function defined within a `with` statement, but called from outside it - cannot access variables exposed by `with`
Summary: Function defined within a `with` statement, but called from outside it - cann...
Status: RESOLVED DUPLICATE of bug 163209
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 17
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-06-29 10:29 PDT by Joe
Modified: 2023-09-24 13:59 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***