Bug 179698 - Sloppy mode function declaration in block unable to access lexical variable
Summary: Sloppy mode function declaration in block unable to access lexical variable
Status: RESOLVED DUPLICATE of bug 163209
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-11-14 15:18 PST by Adam Klein
Modified: 2023-09-21 23:47 PDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Klein 2017-11-14 15:18:19 PST
Test case:

{
  let a = 42;
  function f() { return a }
  print(f())
}

This throws "ReferenceError: Can't find variable: a". If I run this in strict mode, it works as expected (printing 42).
Comment 1 Saam Barati 2017-11-16 17:15:31 PST
(In reply to Adam Klein from comment #0)
> Test case:
> 
> {
>   let a = 42;
>   function f() { return a }
>   print(f())
> }
> 
> This throws "ReferenceError: Can't find variable: a". If I run this in
> strict mode, it works as expected (printing 42).

We don't support this in global scope. We do support it inside functions and I believe eval. We still need to implement it for the global scope.

e.g, replace outer {} with function (and maybe eval) and it works.
Comment 2 Shu-yu Guo 2023-06-05 10:35:49 PDT
Friendly ping. It's been a while, would be good to get this fixed.
Comment 3 Radar WebKit Bug Importer 2023-06-07 07:48:26 PDT
<rdar://problem/110394639>
Comment 4 Alexey Shvayka 2023-09-21 23:47:20 PDT

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