robertkrimen / otto

A JavaScript interpreter in Go (golang)
http://godoc.org/github.com/robertkrimen/otto
MIT License
8.01k stars 584 forks source link

Value of json expression is `undefined` #513

Open kennethklee opened 8 months ago

kennethklee commented 8 months ago

When running this, value, _ = vm.Run("{}"), the resultant value is undefined instead of an Object.

Other types work:

value, _ = vm.Run("1")
// value.toString() is 1
value, _ = vm.Run("true")
// value.toString() is true
value, _ = vm.Run("[1, 2, 3]")
// value.toString() is 1, 2, 3

As an extension, an error is returned when using { "a": 1 }. Error: (anonymous): Line 1:5 Unexpected token :

kennethklee commented 8 months ago

I think this is related to #430