Closed
Description
I know that (interface{})(nil)
gets externalized as a JavaScript null
, and js.Undefined
gets externalized as JavaScript undefined
.
I also know that, according to the conversion table, []byte
slices get externalized as Uint8Array
. But other slices, e.g., []string
, get externalized as Array
.
However, it seems that it's not always the case. Empty []byte
slices seemingly get externalized as JavaScript Array
rather than Uint8Array
.
$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", (interface{})(nil))'
null
$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", js.Undefined)'
undefined
$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", []byte{1, 2, 3})'
Uint8Array { '0': 1, '1': 2, '2': 3 }
$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", []byte{})'
[]
$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", ([]byte)(nil))'
[]
$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", []string{"hi", "bye"})'
[ 'hi', 'bye' ]
$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", []string{})'
[]
$ goexec -quiet -compiler=gopherjs 'js.Global.Get("console").Call("log", ([]string)(nil))'
[]
Is this intentional by design, or an accidental oversight?
I've run into this as part of goxjs/gl#18.