njs icon indicating copy to clipboard operation
njs copied to clipboard

implicit var declarations.

Open xeioex opened this issue 6 years ago • 2 comments

To support expressions like: https://github.com/v8/v8/blob/master/benchmarks/crypto.js#L1668 and https://github.com/v8/v8/blob/master/benchmarks/earley-boyer.js#L4677.

xeioex avatar Aug 22 '19 16:08 xeioex

@xeioex @drsm

What's the difference between these two lines and the below?

"use strict";
a = "b"; // throw ReferrenceError 

Need to be more specific.

hongzhidao avatar Aug 26 '19 02:08 hongzhidao

@hongzhidao @xeioex

Actually we have a bug (global scope in accumulative mode): 1.

// njs
>> var get = () => a;
undefined
>> var set = () => a = 1;
undefined
>> a
ReferenceError: "a" is not defined in shell:1
    at main (native)

>> get() // ok
ReferenceError: "a" is not defined in shell:1
    at anonymous (native)
    at main (native)

>> set() // ok
ReferenceError: "a" is not defined in shell:1
    at anonymous (native)
    at main (native)

>> var a;
undefined
>> a
undefined
>> get() // fail
ReferenceError: "a" is not defined in shell:1
    at anonymous (native)
    at main (native)

>> set() // fail
ReferenceError: "a" is not defined in shell:1
    at anonymous (native)
    at main (native)
//  node --use-strict
> var get = () => a;
undefined
> var set = () => a = 1;
undefined
> a
Thrown:
ReferenceError: a is not defined
> get()
Thrown:
ReferenceError: a is not defined
    at get (repl:1:17)
> set()
Thrown:
ReferenceError: a is not defined
    at set (repl:1:19)
> var a;
undefined
> get()
undefined
> set()
1
> get()
1
  1. implicit vars (should be optional IMO)
// node
> var get = () => a;
undefined
> var set = () => a = 1;
undefined
> a
Thrown:
ReferenceError: a is not defined
> get()
Thrown:
ReferenceError: a is not defined
    at get (repl:1:17)
> set()
1
> a
1
> get()
1
> 

closely related to #132

drsm avatar Aug 26 '19 11:08 drsm