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: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-14 15:18 PST by Adam Klein
Modified: 2017-11-16 17:15 PST (History)
3 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.