From dfa4ee60f5f625ae7ca6415cba0383d5c8b4268d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 4 Apr 2019 01:29:41 +0900 Subject: [PATCH 1/9] Add syscall/js --- build/build.go | 3 + compiler/natives/fs_vfsdata.go | 23 ++- compiler/natives/src/syscall/js/js.go | 267 +++++++++++++++++++++++++ tests/syscalljs_test.go | 275 ++++++++++++++++++++++++++ 4 files changed, 564 insertions(+), 4 deletions(-) create mode 100644 compiler/natives/src/syscall/js/js.go create mode 100644 tests/syscalljs_test.go diff --git a/build/build.go b/build/build.go index f2513ba5b..9170f2ce8 100644 --- a/build/build.go +++ b/build/build.go @@ -139,6 +139,9 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build if installSuffix != "" { bctx.InstallSuffix += "_" + installSuffix } + case "syscall/js": + // There are no buildable files in this package, but we need to use files in the virtual directory. + mode |= build.FindOnly case "math/big": // Use pure Go version of math/big; we don't want non-Go assembly versions. bctx.BuildTags = append(bctx.BuildTags, "math_big_pure_go") diff --git a/compiler/natives/fs_vfsdata.go b/compiler/natives/fs_vfsdata.go index 749606e01..8880abaa2 100644 --- a/compiler/natives/fs_vfsdata.go +++ b/compiler/natives/fs_vfsdata.go @@ -21,7 +21,7 @@ var FS = func() http.FileSystem { fs := vfsgen۰FS{ "/": &vfsgen۰DirInfo{ name: "/", - modTime: time.Date(2019, 4, 10, 21, 27, 44, 478007813, time.UTC), + modTime: time.Date(2019, 4, 11, 0, 32, 11, 450815925, time.UTC), }, "/src": &vfsgen۰DirInfo{ name: "src", @@ -544,7 +544,18 @@ var FS = func() http.FileSystem { }, "/src/syscall": &vfsgen۰DirInfo{ name: "syscall", - modTime: time.Date(2019, 4, 10, 21, 27, 44, 476613264, time.UTC), + modTime: time.Date(2019, 4, 11, 0, 32, 11, 442033261, time.UTC), + }, + "/src/syscall/js": &vfsgen۰DirInfo{ + name: "js", + modTime: time.Date(2019, 4, 11, 0, 32, 11, 442146311, time.UTC), + }, + "/src/syscall/js/js.go": &vfsgen۰CompressedFileInfo{ + name: "js.go", + modTime: time.Date(2019, 4, 11, 0, 32, 11, 442253390, time.UTC), + uncompressedSize: 5073, + + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x58\x4f\x6f\xdb\xb8\x12\x3f\x4b\x9f\x62\xaa\x43\x41\x35\x82\xf2\xfa\xe7\xe5\x15\x2e\x7c\xe8\x5b\x6c\x8b\x16\xdb\x66\xb1\xe9\xee\x1e\x82\x60\x43\xcb\x94\xc3\x44\xa6\x0c\x89\x52\x6d\x18\xfe\xee\x8b\x19\x52\x14\xa5\xc8\x6e\x80\xdd\x1c\x1c\x7a\xe6\x37\x7f\x38\x1c\xce\x0c\x7d\x7e\x0e\x67\x8b\x46\x16\x4b\xb8\xaf\xc3\x70\xc3\xb3\x07\xbe\x12\xb4\x96\xeb\x4d\x59\x69\x60\x61\x10\x55\x22\x2f\x44\xa6\xa3\x30\x88\x1a\x55\xf3\x5c\x44\x61\x18\x44\x2b\xa9\xef\x9a\x45\x9a\x95\xeb\xf3\x55\xb9\xb9\x13\xd5\x7d\xdd\x2f\xee\xeb\x28\x8c\xc3\x50\xef\x36\x02\xbe\xe1\x87\x54\x3a\x0c\xb3\x52\xd5\xa4\x12\x49\xbf\xab\xa5\xc8\xa5\x12\x4b\x03\x98\x83\x2c\x35\x37\xac\xaf\x4d\x51\x98\xd5\xff\xcb\xb2\x10\x5c\x75\xe4\xf5\x42\x54\x66\x7d\xa5\x2b\xa9\x56\x76\xbd\x5b\x2f\x4a\x2b\x70\xb9\xb8\x17\x99\x36\xeb\x0f\x8d\xca\xb4\x2c\x15\x7a\x92\x37\x2a\x03\xa6\xc9\x56\x0c\x46\x9a\xc5\x50\xd3\x02\xf6\x61\x50\x7f\x97\x3a\xbb\x03\x8d\xeb\x8c\xd7\xc6\x6d\xe7\xe3\x2c\x0c\x82\x4a\xe8\xa6\x52\x10\x35\x1d\x31\xf2\x90\xe8\xb2\x0f\x52\x4d\x51\xf8\x7c\xbb\x11\x1f\xb2\x30\xa4\xa1\x16\xdc\xe1\x50\x0f\x52\x7c\x8c\xf1\xdd\xc7\x98\x4d\x0c\x30\x14\x91\x01\x86\x28\x3e\xc6\x44\xca\xc7\x94\x44\xf1\x31\x5d\x04\x7d\x54\x6e\x69\x51\x18\x2c\x45\xce\x9b\x82\x74\x6c\xb8\x92\x19\x8b\x16\x7c\x09\x78\xe8\x51\x1c\x06\x87\xf0\x60\xe3\xfe\xb1\x28\x17\xbc\x60\x31\xfc\xc1\x8b\x46\x60\x84\xad\x32\xfa\xbe\x6f\x67\x70\x5f\xa7\x06\xd4\x0b\x61\x44\x4f\x89\x28\xe9\x81\xdd\x41\xfd\xc0\x88\xc3\x91\x28\xa5\x27\xee\x11\xf3\xa0\xc9\xe8\xec\x09\xed\xf4\xb2\x9c\xf8\x31\xfc\x26\x0a\xc1\x6b\xc1\x62\xc4\xe4\xa9\xb1\x31\xb7\x4e\x3a\x38\x62\x2f\x73\x96\x2b\xc0\xaf\x4c\xdf\xc9\xda\x98\x4f\x80\x57\xab\x1a\xae\x6f\xe8\x5b\x8c\xd7\x41\x54\x39\xcf\xc4\xfe\x10\x1b\x0f\x7a\x7f\xf1\xeb\x3e\x0c\x8c\x27\x33\xeb\x7e\x18\x04\x81\xd9\xc2\x17\xfe\x40\xe7\xc2\x7a\x13\x2f\xee\xeb\xd4\x1c\xa7\xb3\xd3\x93\x06\xc6\x80\x14\x05\x2d\xa1\x66\x73\x58\xf3\x07\xc1\xac\x57\x09\x14\x42\x31\xe4\xc4\x31\xa1\xf2\xb2\x02\x99\x00\x47\x60\xc5\xd5\x4a\x18\xe5\x46\x85\xd1\x71\x2d\x6f\x60\x6e\x5d\xe4\x07\x62\x98\x4f\xbb\x97\x5c\x31\xc3\x44\x3f\x0f\x09\x90\x10\x69\x3f\xc4\x49\x18\x04\x87\xc4\xe6\x09\x1d\xc5\xcf\x55\x55\x56\xc7\xcf\xc2\x02\x62\xf3\x6f\x70\x7b\xbb\xe4\xfc\xcc\x5b\x7e\x95\x55\x72\xa3\x41\x20\x68\x06\x11\x9c\x81\x48\x3f\x0a\xcd\xa2\xb5\xa8\x6b\xbe\x12\x51\x9c\x76\xf7\xdf\x59\x36\xe7\xd9\x5b\x6e\xbd\x98\x22\xa8\xe5\x15\xd6\x2d\xb9\x84\xfe\xcf\x43\x04\x52\xd5\x9a\xab\x4c\x5c\xe6\x23\xc6\x4a\x68\xd2\x4d\x35\xce\x63\x74\x25\x49\x2a\xa9\x4d\x52\xc9\xbc\xbf\x05\xf0\x6c\x8e\xf9\x4d\xa1\x96\x4b\x98\xf7\x9c\xf4\x27\x5e\x14\x2c\x12\x2d\x2f\xa2\x04\x22\xd6\xdd\x46\xb6\x8d\x61\x0f\x36\x0c\xdb\x77\x70\x88\xf1\x0a\xfa\x7e\x3d\x49\x49\x02\x3b\x5f\x0f\x74\xf2\x65\x0e\x3b\xa7\x74\xb0\xa7\xa3\x6a\x6f\x87\xbe\x85\x00\x32\x07\x86\xd1\x2e\x73\xa4\xcc\xe7\x73\xbf\x96\x1a\x08\x74\xa6\xff\xf3\x0e\xce\xcf\x87\x35\x38\x04\x38\x58\x2d\x5b\x92\xc6\x1a\x3b\x12\x7b\xe9\xc4\xa8\x87\xf4\x12\x23\xbb\x5d\xed\x1d\x89\xbf\x72\xe2\x5d\xe3\x39\xaa\xc1\x16\xe6\x91\x82\xd7\x9e\x7d\x6a\x56\x47\xe5\x6d\xd1\x1e\xc9\xbf\x71\xf2\xb6\xc1\x1d\x97\x37\x05\x7d\x24\xff\xdf\x5e\xde\x34\xc5\xa3\xf2\xae\x8c\x8f\x34\xfc\xcf\x69\x70\xed\xd3\xe8\xb0\xfc\x0b\xc7\xef\x6e\x47\x7c\x3b\x28\xf6\x94\x1a\x97\x39\xdb\x0e\x8b\x9c\xab\xca\xb6\xd1\x6e\xb1\xaa\x6c\x53\x72\x2b\x76\x4d\xd7\xd4\xbc\xbe\xdb\x6c\x2d\x1d\x7d\xf1\xc9\xa6\x00\x7b\x9d\x6a\xf9\xbe\xaa\xf8\xee\x28\x44\x49\xbf\x1b\xda\xaa\x6d\x58\x98\x0a\x09\xfa\x4a\x1f\x6f\xe9\xf3\xe5\x05\xfd\x7b\xfd\x8a\xfe\x5d\xbc\x49\xa0\x21\x40\x63\x10\x8d\x85\x34\x16\xd3\x58\x50\x5e\x94\x9c\x08\xb4\x20\x31\x9a\x97\xd2\x5f\x4b\x8a\x45\x62\x2b\x56\x02\x6b\xbe\xb9\x36\xeb\x1b\x2f\x4a\x09\x5c\xfb\x5f\x3d\x8f\x5d\x0f\x93\xcb\xf4\x93\x6a\xcb\x07\xc1\xb6\xf1\x61\xa2\x03\xdf\x4a\xd5\xf2\x42\x2e\xb1\x54\xcf\xe0\x16\xce\xc0\x4e\x6f\x29\x1d\x19\x9e\xbf\xab\x7e\x83\x63\x63\x2d\xd8\xde\x84\xa9\xcf\x62\x8a\x8b\xad\x4b\x2d\xdd\xf4\xd9\x1c\x5a\xd2\xc2\xe2\x77\x96\xf4\x6c\xee\x5f\x16\x2a\x57\xc6\x8d\xe7\xa4\x8b\xea\xf4\x3e\xa2\x75\x8a\xa0\x28\x31\x82\x07\x32\xdd\x6d\xae\x4d\xdb\xd4\x18\x75\xde\x64\xa5\x6a\x45\xa5\xdf\x57\xab\x9a\xd9\x8e\x36\xc8\xa6\xc1\x57\xb4\xab\xc4\xf7\xf7\xb6\xa7\x0d\x78\xfb\x43\x48\x7d\xec\x2f\xea\x8c\x13\x9d\xac\x45\x5a\x97\xb3\xbc\x5a\x61\x81\xeb\x94\xcd\x81\x6f\x36\x42\x2d\x99\x25\x24\xe8\xea\xc0\x75\xcb\x98\x88\x22\xd5\xc2\xb5\x3b\x70\xb2\x97\xa6\xe9\xf4\x9d\x78\x42\x8c\xcd\x6d\x83\xe7\xcf\x87\xe4\xee\x92\x9e\x8e\x3d\x3a\x33\x8a\xbd\xcc\x61\x53\x95\x9b\xde\x2a\xb6\xc8\x75\xec\x8c\x3b\xe6\x71\x43\xd1\x7d\x6d\xc7\x13\x32\x30\x23\x19\x51\xe9\x1d\x35\xdd\x35\x9c\x41\x04\xb2\x06\x55\x6a\xe0\xd0\xd5\x9b\x04\x56\xa5\x26\x40\x67\x61\x98\x8f\x8f\x32\x1e\xb3\xc3\x04\x33\x79\x94\x16\x71\x9a\xa6\xf1\x54\x0e\x7f\xc0\x0b\xc8\xe2\xee\x22\x3e\x31\xc6\xa6\x66\x9f\x0e\x25\x69\x3e\x9e\xc7\xd6\xf0\x84\x4b\x18\xdf\x8d\xcd\x87\x13\x43\x2a\x2a\x21\xe8\xe4\xbe\x3e\xa9\xa5\xd8\x32\x89\x55\xe9\x07\x3a\x2c\xf2\x88\x16\x8c\x8d\x54\xfa\x5f\x8c\xcb\x27\x75\x22\x2a\x64\x70\xd2\x91\x6e\x3c\x61\xba\xa3\x75\x75\xc7\x8a\xf7\x13\x4c\x57\xf8\xda\x04\x74\x3c\x2e\x18\xbe\x4e\x42\xfd\xe3\x0b\xf7\xb4\x9b\x65\xac\x4d\xef\x7c\x74\x1e\xe4\xd6\x93\x33\xf8\xf3\x15\x2d\x26\xde\x33\xed\x04\xfa\x17\xa1\x56\xfa\xae\x3f\x54\x2f\xf6\x1d\x6b\x42\xea\xab\xf8\xfe\x83\x38\x4d\xed\x04\xa5\x9e\xbc\x8d\x2b\x2f\xeb\x13\x18\xcd\x04\x38\x68\xa7\x6d\x4a\x98\x04\xb6\x53\x2e\x5e\x09\xed\xe5\xfc\x09\x0d\x16\x75\x4c\xcd\xe3\x07\xbf\x17\x22\xff\x39\x30\x12\xfc\x56\x35\xfa\x6e\xc7\x1e\xa5\xe5\x44\xcf\xf2\x84\x28\x9f\xcc\xef\x1a\xbd\x08\x51\xfd\xd9\xd9\x25\x74\x6c\x2e\x48\xff\x1c\xe9\x27\x9a\xa3\xaf\xa1\x1e\x72\x99\xb3\xba\x90\x99\x18\x46\xc6\x53\xd1\x0f\x5d\x06\x37\x9b\x9b\xc5\x78\xf8\xa2\xc6\xf9\xd6\x0e\x21\x38\xdf\xd0\x02\xe7\x99\xeb\x9b\xa6\x63\x35\x8e\xd7\x38\xa6\x9b\x7b\xec\xf2\xe2\x8d\x37\xba\xf4\x8e\xec\x27\xa6\x18\x72\x24\x3e\x4c\x8d\x32\x91\xbf\xc5\x99\x6d\x23\x75\xb3\xd9\x94\x95\x16\x4b\xb3\x85\xe1\xef\x0c\x4c\xc3\x8b\x5e\x68\xf4\x68\xd7\x13\x8f\xf6\xfe\xed\x37\x7e\x7a\x7e\x11\xfa\xae\x5c\xda\x74\x31\x3f\x27\x01\xd0\x5e\xfc\xf7\xe8\x8b\x5e\xf6\xd4\xab\xb4\xde\xd5\x19\x2f\x8a\x73\xec\x97\xb8\x80\x32\xb7\xef\x52\x6b\x06\x3b\x65\xa9\x2c\x6d\xd0\x13\x9d\x97\x7f\x56\x38\x8b\x54\xfd\x21\xa3\x81\x51\x91\x08\x0f\xe1\xdf\x01\x00\x00\xff\xff\x6d\x98\xe3\x82\xd1\x13\x00\x00"), }, "/src/syscall/syscall.go": &vfsgen۰CompressedFileInfo{ name: "syscall.go", @@ -624,7 +635,7 @@ var FS = func() http.FileSystem { }, "/src/time": &vfsgen۰DirInfo{ name: "time", - modTime: time.Date(2019, 4, 10, 21, 38, 35, 793313431, time.UTC), + modTime: time.Date(2019, 4, 11, 0, 31, 39, 578263110, time.UTC), }, "/src/time/time.go": &vfsgen۰CompressedFileInfo{ name: "time.go", @@ -635,7 +646,7 @@ var FS = func() http.FileSystem { }, "/src/time/time_test.go": &vfsgen۰CompressedFileInfo{ name: "time_test.go", - modTime: time.Date(2019, 4, 10, 21, 38, 13, 208335917, time.UTC), + modTime: time.Date(2019, 4, 11, 0, 31, 39, 578375649, time.UTC), uncompressedSize: 147, compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\x8c\xc1\x0e\x82\x30\x10\x05\xcf\xec\x57\xbc\xf4\xd4\x6a\x02\x7f\xe2\x05\xee\xa6\xd6\x05\x56\xa0\x6d\xe8\x36\x1e\x8c\xff\x6e\x9a\x78\x9d\xc9\xcc\x30\xe0\xfa\xa8\xb2\x3f\xf1\x2a\x44\xd9\x87\xcd\x2f\x0c\x95\x83\xef\xca\x45\x89\xe4\xc8\xe9\x54\x58\xea\x4c\x03\x12\x17\x43\x8e\x68\xae\x31\x60\xe2\xa2\xe3\xce\x9c\xad\xe2\xf2\xb7\xfd\xe4\xf0\xa1\x4e\xfb\x71\x93\x6c\x4d\x3b\xf5\xb7\xf4\xb6\x0e\x52\x10\x93\xc2\x87\x50\x4f\xaf\x0c\x8e\xa9\x2e\x2b\xe6\x74\x42\x57\x46\xeb\x8d\xa3\x2f\xfd\x02\x00\x00\xff\xff\x49\x24\xa9\x3b\x93\x00\x00\x00"), @@ -843,6 +854,7 @@ var FS = func() http.FileSystem { fs["/src/sync/atomic/atomic_test.go"].(os.FileInfo), } fs["/src/syscall"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ + fs["/src/syscall/js"].(os.FileInfo), fs["/src/syscall/syscall.go"].(os.FileInfo), fs["/src/syscall/syscall_darwin.go"].(os.FileInfo), fs["/src/syscall/syscall_linux.go"].(os.FileInfo), @@ -850,6 +862,9 @@ var FS = func() http.FileSystem { fs["/src/syscall/syscall_unix.go"].(os.FileInfo), fs["/src/syscall/syscall_windows.go"].(os.FileInfo), } + fs["/src/syscall/js"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ + fs["/src/syscall/js/js.go"].(os.FileInfo), + } fs["/src/testing"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ fs["/src/testing/example.go"].(os.FileInfo), fs["/src/testing/ioutil.go"].(os.FileInfo), diff --git a/compiler/natives/src/syscall/js/js.go b/compiler/natives/src/syscall/js/js.go new file mode 100644 index 000000000..4998c4407 --- /dev/null +++ b/compiler/natives/src/syscall/js/js.go @@ -0,0 +1,267 @@ +// +build js + +package js + +import ( + "reflect" + "unsafe" + + "github.com/gopherjs/gopherjs/js" +) + +type Type int + +const ( + TypeUndefined Type = iota + TypeNull + TypeBoolean + TypeNumber + TypeString + TypeSymbol + TypeObject + TypeFunction +) + +func (t Type) String() string { + switch t { + case TypeUndefined: + return "undefined" + case TypeNull: + return "null" + case TypeBoolean: + return "boolean" + case TypeNumber: + return "number" + case TypeString: + return "string" + case TypeSymbol: + return "symbol" + case TypeObject: + return "object" + case TypeFunction: + return "function" + default: + panic("bad type") + } +} + +func Global() Value { + return Value{v: js.Global} +} + +func Null() Value { + return Value{v: nil} +} + +func Undefined() Value { + return Value{v: js.Undefined} +} + +type Func struct { + Value +} + +func (f Func) Release() { + f.Value = Null() +} + +func FuncOf(fn func(this Value, args []Value) interface{}) Func { + return Func{ + Value: Value{ + v: js.MakeFunc(func(this *js.Object, args []*js.Object) interface{} { + vargs := make([]Value, len(args)) + for i, a := range args { + vargs[i] = Value{a} + } + return fn(Value{this}, vargs) + }), + }, + } +} + +type Error struct { + Value +} + +func (e Error) Error() string { + return "JavaScript error: " + e.Get("message").String() +} + +type Value struct { + v *js.Object +} + +var ( + id *js.Object + instanceOf *js.Object + getValueType *js.Object +) + +func init() { + if js.Global != nil { + id = js.Global.Call("eval", "(function(x) { return x; })") + instanceOf = js.Global.Call("eval", "(function(x, y) { return x instanceof y; })") + getValueType = js.Global.Call("eval", `(function(x) { + if (typeof(x) === "undefined") { + return 0; // TypeUndefined + } + if (x === null) { + return 1; // TypeNull + } + if (typeof(x) === "boolean") { + return 2; // TypeBoolean + } + if (typeof(x) === "number") { + return 3; // TypeNumber + } + if (typeof(x) === "string") { + return 4; // TypeString + } + if (typeof(x) === "symbol") { + return 5; // TypeSymbol + } + if (typeof(x) === "function") { + return 7; // TypeFunction + } + return 6; // TypeObject +})`) + } +} + +func ValueOf(x interface{}) Value { + switch x := x.(type) { + case Value: + return x + case Func: + return x.Value + case TypedArray: + return x.Value + case nil: + return Null() + case bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, unsafe.Pointer, string, map[string]interface{}, []interface{}: + return Value{v: id.Invoke(x)} + default: + panic(`invalid arg: ` + reflect.TypeOf(x).String()) + } +} + +func (v Value) Bool() bool { + if vType := v.Type(); vType != TypeBoolean { + panic(&ValueError{"Value.Bool", vType}) + } + return v.v.Bool() +} + +func convertArgs(args []interface{}) []interface{} { + newArgs := []interface{}{} + for _, arg := range args { + v := ValueOf(arg) + newArgs = append(newArgs, v.v) + } + return newArgs +} + +func (v Value) Call(m string, args ...interface{}) Value { + if vType := v.Type(); vType != TypeObject && vType != TypeFunction { + panic(&ValueError{"Value.Call", vType}) + } + if propType := v.Get(m).Type(); propType != TypeFunction { + panic("js: Value.Call: property " + m + " is not a function, got " + propType.String()) + } + return Value{v: v.v.Call(m, convertArgs(args)...)} +} + +func (v Value) Float() float64 { + if vType := v.Type(); vType != TypeNumber { + panic(&ValueError{"Value.Float", vType}) + } + return v.v.Float() +} + +func (v Value) Get(p string) Value { + return Value{v: v.v.Get(p)} +} + +func (v Value) Index(i int) Value { + return Value{v: v.v.Index(i)} +} + +func (v Value) Int() int { + if vType := v.Type(); vType != TypeNumber { + panic(&ValueError{"Value.Int", vType}) + } + return v.v.Int() +} + +func (v Value) InstanceOf(t Value) bool { + return instanceOf.Invoke(v, t).Bool() +} + +func (v Value) Invoke(args ...interface{}) Value { + if vType := v.Type(); vType != TypeFunction { + panic(&ValueError{"Value.Invoke", vType}) + } + return Value{v: v.v.Invoke(convertArgs(args)...)} +} + +func (v Value) JSValue() Value { + return v +} + +func (v Value) Length() int { + return v.v.Length() +} + +func (v Value) New(args ...interface{}) Value { + return Value{v: v.v.New(convertArgs(args)...)} +} + +func (v Value) Set(p string, x interface{}) { + v.v.Set(p, x) +} + +func (v Value) SetIndex(i int, x interface{}) { + v.v.SetIndex(i, x) +} + +func (v Value) String() string { + return v.v.String() +} + +func (v Value) Truthy() bool { + return v.v.Bool() +} + +func (v Value) Type() Type { + return Type(getValueType.Invoke(v).Int()) +} + +type TypedArray struct { + Value +} + +func TypedArrayOf(slice interface{}) TypedArray { + switch slice := slice.(type) { + case []int8, []int16, []int32, []uint8, []uint16, []uint32, []float32, []float64: + return TypedArray{Value{v: id.Invoke(slice)}} + default: + panic("TypedArrayOf: not a supported slice") + } +} + +func (t *TypedArray) Release() { + t.Value = Null() +} + +type ValueError struct { + Method string + Type Type +} + +func (e *ValueError) Error() string { + return "syscall/js: call of " + e.Method + " on " + e.Type.String() +} + +type Wrapper interface { + JSValue() Value +} diff --git a/tests/syscalljs_test.go b/tests/syscalljs_test.go new file mode 100644 index 000000000..8dc139f0e --- /dev/null +++ b/tests/syscalljs_test.go @@ -0,0 +1,275 @@ +// +build js + +package tests + +import ( + "fmt" + "math" + "syscall/js" + "testing" +) + +func TestSyscallJSNull(t *testing.T) { + want := "null" + if got := js.Null().String(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestSyscallJSFuncOf(t *testing.T) { + c := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + return args[0].Int() + args[1].Int() + }) + defer c.Release() + + got := js.ValueOf(c).Invoke(1, 2).Int() + want := 3 + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestSyscallJSFuncOfObject(t *testing.T) { + c := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + return args[0].Get("foo").String() + }) + defer c.Release() + + got := js.ValueOf(c).Invoke(js.Global().Call("eval", `({"foo": "bar"})`)).String() + want := "bar" + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestSyscallJSString(t *testing.T) { + obj := js.Global().Call("eval", "'Hello'") + got := obj.String() + if want := "Hello"; got != want { + t.Errorf("got %#v, want %#v", got, want) + } + + obj = js.Global().Call("eval", "123") + got = obj.String() + if want := "123"; got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestSyscallJSInt64(t *testing.T) { + var i int64 = math.MaxInt64 + got := js.ValueOf(i).String() + // js.Value keeps the value only in 53-bit precision. + if want := "9223372036854776000"; got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestSyscallJSInstanceOf(t *testing.T) { + arr := js.Global().Call("eval", "[]") + got := arr.InstanceOf(js.Global().Call("eval", "Array")) + want := true + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } + + got = arr.InstanceOf(js.Global().Call("eval", "Object")) + want = true + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } + + got = arr.InstanceOf(js.Global().Call("eval", "String")) + want = false + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } + + str := js.Global().Call("eval", "String").New() + got = str.InstanceOf(js.Global().Call("eval", "Array")) + want = false + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } + + got = str.InstanceOf(js.Global().Call("eval", "Object")) + want = true + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } + + got = str.InstanceOf(js.Global().Call("eval", "String")) + want = true + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestSyscallJSTypedArrayOf(t *testing.T) { + testTypedArrayOf(t, "[]int8", []int8{0, -42, 0}, -42) + testTypedArrayOf(t, "[]int16", []int16{0, -42, 0}, -42) + testTypedArrayOf(t, "[]int32", []int32{0, -42, 0}, -42) + testTypedArrayOf(t, "[]uint8", []uint8{0, 42, 0}, 42) + testTypedArrayOf(t, "[]uint16", []uint16{0, 42, 0}, 42) + testTypedArrayOf(t, "[]uint32", []uint32{0, 42, 0}, 42) + testTypedArrayOf(t, "[]float32", []float32{0, -42.5, 0}, -42.5) + testTypedArrayOf(t, "[]float64", []float64{0, -42.5, 0}, -42.5) +} + +func testTypedArrayOf(t *testing.T, name string, slice interface{}, want float64) { + t.Run(name, func(t *testing.T) { + a := js.TypedArrayOf(slice) + got := a.Index(1).Float() + a.Release() + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } + + a2 := js.TypedArrayOf(slice) + v := js.ValueOf(a2) + got = v.Index(1).Float() + a2.Release() + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } + }) +} + +func TestSyscallJSType(t *testing.T) { + if got, want := js.Undefined().Type(), js.TypeUndefined; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.Null().Type(), js.TypeNull; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.ValueOf(true).Type(), js.TypeBoolean; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.ValueOf(42).Type(), js.TypeNumber; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.ValueOf("test").Type(), js.TypeString; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.Global().Get("Symbol").Invoke("test").Type(), js.TypeSymbol; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.Global().Get("Array").New().Type(), js.TypeObject; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.Global().Get("Array").Type(), js.TypeFunction; got != want { + t.Errorf("got %s, want %s", got, want) + } +} + +func TestSyscallJSValueOf(t *testing.T) { + JSON := js.Global().Get("JSON") + for _, test := range []struct { + in interface{} + wantType js.Type + wantString string + }{ + {js.Value(js.ValueOf(42)), js.TypeNumber, "42"}, + {js.FuncOf(func(this js.Value, args []js.Value) interface{} { return nil }), js.TypeFunction, ""}, + {js.TypedArrayOf([]int8{1, 2, 3}), js.TypeObject, `{"0":1,"1":2,"2":3}`}, + {nil, js.TypeNull, "null"}, + {bool(true), js.TypeBoolean, "true"}, + {int(1), js.TypeNumber, "1"}, + {int8(2), js.TypeNumber, "2"}, + {int16(3), js.TypeNumber, "3"}, + {int32(4), js.TypeNumber, "4"}, + {int64(5), js.TypeNumber, "5"}, + {uint(6), js.TypeNumber, "6"}, + {uint8(7), js.TypeNumber, "7"}, + {uint16(8), js.TypeNumber, "8"}, + {uint32(9), js.TypeNumber, "9"}, + {uint64(10), js.TypeNumber, "10"}, + {float32(11), js.TypeNumber, "11"}, + {float64(12), js.TypeNumber, "12"}, + // FIXME this doesn't work {unsafe.Pointer(&x19), js.TypeNumber, ""}, + {string("hello"), js.TypeString, `"hello"`}, + {map[string]interface{}{"a": 1}, js.TypeObject, `{"a":1}`}, + {[]interface{}{1, 2, 3}, js.TypeObject, "[1,2,3]"}, + } { + t.Run(fmt.Sprintf("%T", test.in), func(t *testing.T) { + got := js.ValueOf(test.in) + if got.Type() != test.wantType { + t.Errorf("type: got %v want %v", got.Type(), test.wantType) + } + gotString := JSON.Call("stringify", got).String() + if test.wantString != "" && gotString != test.wantString { + t.Errorf("string: got %v want %v", gotString, test.wantString) + } + }) + } + + // Check unknown types panic + didPanic := false + func() { + defer func() { + if r := recover(); r != nil { + didPanic = true + } + }() + _ = js.ValueOf([]struct{}{}) + }() + if !didPanic { + t.Errorf("Unknown type didn't panic") + } +} + +func TestSyscallJSFuncObject(t *testing.T) { + got := "" + f := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + got = args[0].Get("foo").String() + this.Get("name").String() + return nil + }) + defer f.Release() + + obj := js.Global().Call("eval", `({})`) + obj.Set("func", f) + obj.Set("name", "baz") + arg := js.Global().Call("eval", `({"foo": "bar"})`) + obj.Call("func", arg) + + want := "barbaz" + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestSyscallJSValueOfFunc(t *testing.T) { + f := js.FuncOf(func(this js.Value, args []js.Value) interface{} { return nil }) + got := js.ValueOf(f).Type() + want := js.TypeFunction + if got != want { + t.Fail() + } +} + +func TestSyscallJSTruthy(t *testing.T) { + for _, test := range []struct { + in interface{} + want bool + }{ + {false, false}, + {true, true}, + {nil, false}, + {js.Undefined(), false}, + {0, false}, + {1, true}, + {0.0, false}, + {"", false}, + {"a", true}, + {map[string]interface{}{}, true}, + {[]interface{}{}, true}, + } { + t.Run(fmt.Sprintf("%%", test.in), func(t *testing.T) { + got := js.ValueOf(test.in).Truthy() + want := test.want + if got != want { + t.Errorf("got: %v, want: %v", got, want) + } + }) + } +} From 52d06cf8b2aa5581b3a63535b0b927bcfd628788 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 25 Apr 2019 01:20:19 +0900 Subject: [PATCH 2/9] Use the original tests --- build/build.go | 3 + compiler/gopherjspkg/fs_vfsdata.go | 2 +- compiler/natives/fs_vfsdata.go | 10 +- compiler/natives/src/syscall/js/js_test.go | 20 ++ tests/syscalljs_test.go | 275 --------------------- 5 files changed, 33 insertions(+), 277 deletions(-) create mode 100644 compiler/natives/src/syscall/js/js_test.go delete mode 100644 tests/syscalljs_test.go diff --git a/build/build.go b/build/build.go index 9170f2ce8..e142e82ec 100644 --- a/build/build.go +++ b/build/build.go @@ -173,6 +173,9 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build case "crypto/rand": pkg.GoFiles = []string{"rand.go", "util.go"} pkg.TestGoFiles = exclude(pkg.TestGoFiles, "rand_linux_test.go") // Don't want linux-specific tests (since linux-specific package files are excluded too). + case "syscall/js": + // Add Go files for tests explicitly since the files are excluded due to 'wasm' build tag. + pkg.XTestGoFiles = []string{"js_test.go"} } if len(pkg.CgoFiles) > 0 { diff --git a/compiler/gopherjspkg/fs_vfsdata.go b/compiler/gopherjspkg/fs_vfsdata.go index 8931d724b..c46530432 100644 --- a/compiler/gopherjspkg/fs_vfsdata.go +++ b/compiler/gopherjspkg/fs_vfsdata.go @@ -21,7 +21,7 @@ var FS = func() http.FileSystem { fs := vfsgen۰FS{ "/": &vfsgen۰DirInfo{ name: "/", - modTime: time.Date(2019, 4, 6, 11, 9, 42, 660657937, time.UTC), + modTime: time.Date(2019, 4, 24, 15, 56, 5, 751826141, time.UTC), }, "/js": &vfsgen۰DirInfo{ name: "js", diff --git a/compiler/natives/fs_vfsdata.go b/compiler/natives/fs_vfsdata.go index 8880abaa2..3bfbde263 100644 --- a/compiler/natives/fs_vfsdata.go +++ b/compiler/natives/fs_vfsdata.go @@ -548,7 +548,7 @@ var FS = func() http.FileSystem { }, "/src/syscall/js": &vfsgen۰DirInfo{ name: "js", - modTime: time.Date(2019, 4, 11, 0, 32, 11, 442146311, time.UTC), + modTime: time.Date(2019, 4, 24, 16, 16, 8, 197108888, time.UTC), }, "/src/syscall/js/js.go": &vfsgen۰CompressedFileInfo{ name: "js.go", @@ -557,6 +557,13 @@ var FS = func() http.FileSystem { compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x58\x4f\x6f\xdb\xb8\x12\x3f\x4b\x9f\x62\xaa\x43\x41\x35\x82\xf2\xfa\xe7\xe5\x15\x2e\x7c\xe8\x5b\x6c\x8b\x16\xdb\x66\xb1\xe9\xee\x1e\x82\x60\x43\xcb\x94\xc3\x44\xa6\x0c\x89\x52\x6d\x18\xfe\xee\x8b\x19\x52\x14\xa5\xc8\x6e\x80\xdd\x1c\x1c\x7a\xe6\x37\x7f\x38\x1c\xce\x0c\x7d\x7e\x0e\x67\x8b\x46\x16\x4b\xb8\xaf\xc3\x70\xc3\xb3\x07\xbe\x12\xb4\x96\xeb\x4d\x59\x69\x60\x61\x10\x55\x22\x2f\x44\xa6\xa3\x30\x88\x1a\x55\xf3\x5c\x44\x61\x18\x44\x2b\xa9\xef\x9a\x45\x9a\x95\xeb\xf3\x55\xb9\xb9\x13\xd5\x7d\xdd\x2f\xee\xeb\x28\x8c\xc3\x50\xef\x36\x02\xbe\xe1\x87\x54\x3a\x0c\xb3\x52\xd5\xa4\x12\x49\xbf\xab\xa5\xc8\xa5\x12\x4b\x03\x98\x83\x2c\x35\x37\xac\xaf\x4d\x51\x98\xd5\xff\xcb\xb2\x10\x5c\x75\xe4\xf5\x42\x54\x66\x7d\xa5\x2b\xa9\x56\x76\xbd\x5b\x2f\x4a\x2b\x70\xb9\xb8\x17\x99\x36\xeb\x0f\x8d\xca\xb4\x2c\x15\x7a\x92\x37\x2a\x03\xa6\xc9\x56\x0c\x46\x9a\xc5\x50\xd3\x02\xf6\x61\x50\x7f\x97\x3a\xbb\x03\x8d\xeb\x8c\xd7\xc6\x6d\xe7\xe3\x2c\x0c\x82\x4a\xe8\xa6\x52\x10\x35\x1d\x31\xf2\x90\xe8\xb2\x0f\x52\x4d\x51\xf8\x7c\xbb\x11\x1f\xb2\x30\xa4\xa1\x16\xdc\xe1\x50\x0f\x52\x7c\x8c\xf1\xdd\xc7\x98\x4d\x0c\x30\x14\x91\x01\x86\x28\x3e\xc6\x44\xca\xc7\x94\x44\xf1\x31\x5d\x04\x7d\x54\x6e\x69\x51\x18\x2c\x45\xce\x9b\x82\x74\x6c\xb8\x92\x19\x8b\x16\x7c\x09\x78\xe8\x51\x1c\x06\x87\xf0\x60\xe3\xfe\xb1\x28\x17\xbc\x60\x31\xfc\xc1\x8b\x46\x60\x84\xad\x32\xfa\xbe\x6f\x67\x70\x5f\xa7\x06\xd4\x0b\x61\x44\x4f\x89\x28\xe9\x81\xdd\x41\xfd\xc0\x88\xc3\x91\x28\xa5\x27\xee\x11\xf3\xa0\xc9\xe8\xec\x09\xed\xf4\xb2\x9c\xf8\x31\xfc\x26\x0a\xc1\x6b\xc1\x62\xc4\xe4\xa9\xb1\x31\xb7\x4e\x3a\x38\x62\x2f\x73\x96\x2b\xc0\xaf\x4c\xdf\xc9\xda\x98\x4f\x80\x57\xab\x1a\xae\x6f\xe8\x5b\x8c\xd7\x41\x54\x39\xcf\xc4\xfe\x10\x1b\x0f\x7a\x7f\xf1\xeb\x3e\x0c\x8c\x27\x33\xeb\x7e\x18\x04\x81\xd9\xc2\x17\xfe\x40\xe7\xc2\x7a\x13\x2f\xee\xeb\xd4\x1c\xa7\xb3\xd3\x93\x06\xc6\x80\x14\x05\x2d\xa1\x66\x73\x58\xf3\x07\xc1\xac\x57\x09\x14\x42\x31\xe4\xc4\x31\xa1\xf2\xb2\x02\x99\x00\x47\x60\xc5\xd5\x4a\x18\xe5\x46\x85\xd1\x71\x2d\x6f\x60\x6e\x5d\xe4\x07\x62\x98\x4f\xbb\x97\x5c\x31\xc3\x44\x3f\x0f\x09\x90\x10\x69\x3f\xc4\x49\x18\x04\x87\xc4\xe6\x09\x1d\xc5\xcf\x55\x55\x56\xc7\xcf\xc2\x02\x62\xf3\x6f\x70\x7b\xbb\xe4\xfc\xcc\x5b\x7e\x95\x55\x72\xa3\x41\x20\x68\x06\x11\x9c\x81\x48\x3f\x0a\xcd\xa2\xb5\xa8\x6b\xbe\x12\x51\x9c\x76\xf7\xdf\x59\x36\xe7\xd9\x5b\x6e\xbd\x98\x22\xa8\xe5\x15\xd6\x2d\xb9\x84\xfe\xcf\x43\x04\x52\xd5\x9a\xab\x4c\x5c\xe6\x23\xc6\x4a\x68\xd2\x4d\x35\xce\x63\x74\x25\x49\x2a\xa9\x4d\x52\xc9\xbc\xbf\x05\xf0\x6c\x8e\xf9\x4d\xa1\x96\x4b\x98\xf7\x9c\xf4\x27\x5e\x14\x2c\x12\x2d\x2f\xa2\x04\x22\xd6\xdd\x46\xb6\x8d\x61\x0f\x36\x0c\xdb\x77\x70\x88\xf1\x0a\xfa\x7e\x3d\x49\x49\x02\x3b\x5f\x0f\x74\xf2\x65\x0e\x3b\xa7\x74\xb0\xa7\xa3\x6a\x6f\x87\xbe\x85\x00\x32\x07\x86\xd1\x2e\x73\xa4\xcc\xe7\x73\xbf\x96\x1a\x08\x74\xa6\xff\xf3\x0e\xce\xcf\x87\x35\x38\x04\x38\x58\x2d\x5b\x92\xc6\x1a\x3b\x12\x7b\xe9\xc4\xa8\x87\xf4\x12\x23\xbb\x5d\xed\x1d\x89\xbf\x72\xe2\x5d\xe3\x39\xaa\xc1\x16\xe6\x91\x82\xd7\x9e\x7d\x6a\x56\x47\xe5\x6d\xd1\x1e\xc9\xbf\x71\xf2\xb6\xc1\x1d\x97\x37\x05\x7d\x24\xff\xdf\x5e\xde\x34\xc5\xa3\xf2\xae\x8c\x8f\x34\xfc\xcf\x69\x70\xed\xd3\xe8\xb0\xfc\x0b\xc7\xef\x6e\x47\x7c\x3b\x28\xf6\x94\x1a\x97\x39\xdb\x0e\x8b\x9c\xab\xca\xb6\xd1\x6e\xb1\xaa\x6c\x53\x72\x2b\x76\x4d\xd7\xd4\xbc\xbe\xdb\x6c\x2d\x1d\x7d\xf1\xc9\xa6\x00\x7b\x9d\x6a\xf9\xbe\xaa\xf8\xee\x28\x44\x49\xbf\x1b\xda\xaa\x6d\x58\x98\x0a\x09\xfa\x4a\x1f\x6f\xe9\xf3\xe5\x05\xfd\x7b\xfd\x8a\xfe\x5d\xbc\x49\xa0\x21\x40\x63\x10\x8d\x85\x34\x16\xd3\x58\x50\x5e\x94\x9c\x08\xb4\x20\x31\x9a\x97\xd2\x5f\x4b\x8a\x45\x62\x2b\x56\x02\x6b\xbe\xb9\x36\xeb\x1b\x2f\x4a\x09\x5c\xfb\x5f\x3d\x8f\x5d\x0f\x93\xcb\xf4\x93\x6a\xcb\x07\xc1\xb6\xf1\x61\xa2\x03\xdf\x4a\xd5\xf2\x42\x2e\xb1\x54\xcf\xe0\x16\xce\xc0\x4e\x6f\x29\x1d\x19\x9e\xbf\xab\x7e\x83\x63\x63\x2d\xd8\xde\x84\xa9\xcf\x62\x8a\x8b\xad\x4b\x2d\xdd\xf4\xd9\x1c\x5a\xd2\xc2\xe2\x77\x96\xf4\x6c\xee\x5f\x16\x2a\x57\xc6\x8d\xe7\xa4\x8b\xea\xf4\x3e\xa2\x75\x8a\xa0\x28\x31\x82\x07\x32\xdd\x6d\xae\x4d\xdb\xd4\x18\x75\xde\x64\xa5\x6a\x45\xa5\xdf\x57\xab\x9a\xd9\x8e\x36\xc8\xa6\xc1\x57\xb4\xab\xc4\xf7\xf7\xb6\xa7\x0d\x78\xfb\x43\x48\x7d\xec\x2f\xea\x8c\x13\x9d\xac\x45\x5a\x97\xb3\xbc\x5a\x61\x81\xeb\x94\xcd\x81\x6f\x36\x42\x2d\x99\x25\x24\xe8\xea\xc0\x75\xcb\x98\x88\x22\xd5\xc2\xb5\x3b\x70\xb2\x97\xa6\xe9\xf4\x9d\x78\x42\x8c\xcd\x6d\x83\xe7\xcf\x87\xe4\xee\x92\x9e\x8e\x3d\x3a\x33\x8a\xbd\xcc\x61\x53\x95\x9b\xde\x2a\xb6\xc8\x75\xec\x8c\x3b\xe6\x71\x43\xd1\x7d\x6d\xc7\x13\x32\x30\x23\x19\x51\xe9\x1d\x35\xdd\x35\x9c\x41\x04\xb2\x06\x55\x6a\xe0\xd0\xd5\x9b\x04\x56\xa5\x26\x40\x67\x61\x98\x8f\x8f\x32\x1e\xb3\xc3\x04\x33\x79\x94\x16\x71\x9a\xa6\xf1\x54\x0e\x7f\xc0\x0b\xc8\xe2\xee\x22\x3e\x31\xc6\xa6\x66\x9f\x0e\x25\x69\x3e\x9e\xc7\xd6\xf0\x84\x4b\x18\xdf\x8d\xcd\x87\x13\x43\x2a\x2a\x21\xe8\xe4\xbe\x3e\xa9\xa5\xd8\x32\x89\x55\xe9\x07\x3a\x2c\xf2\x88\x16\x8c\x8d\x54\xfa\x5f\x8c\xcb\x27\x75\x22\x2a\x64\x70\xd2\x91\x6e\x3c\x61\xba\xa3\x75\x75\xc7\x8a\xf7\x13\x4c\x57\xf8\xda\x04\x74\x3c\x2e\x18\xbe\x4e\x42\xfd\xe3\x0b\xf7\xb4\x9b\x65\xac\x4d\xef\x7c\x74\x1e\xe4\xd6\x93\x33\xf8\xf3\x15\x2d\x26\xde\x33\xed\x04\xfa\x17\xa1\x56\xfa\xae\x3f\x54\x2f\xf6\x1d\x6b\x42\xea\xab\xf8\xfe\x83\x38\x4d\xed\x04\xa5\x9e\xbc\x8d\x2b\x2f\xeb\x13\x18\xcd\x04\x38\x68\xa7\x6d\x4a\x98\x04\xb6\x53\x2e\x5e\x09\xed\xe5\xfc\x09\x0d\x16\x75\x4c\xcd\xe3\x07\xbf\x17\x22\xff\x39\x30\x12\xfc\x56\x35\xfa\x6e\xc7\x1e\xa5\xe5\x44\xcf\xf2\x84\x28\x9f\xcc\xef\x1a\xbd\x08\x51\xfd\xd9\xd9\x25\x74\x6c\x2e\x48\xff\x1c\xe9\x27\x9a\xa3\xaf\xa1\x1e\x72\x99\xb3\xba\x90\x99\x18\x46\xc6\x53\xd1\x0f\x5d\x06\x37\x9b\x9b\xc5\x78\xf8\xa2\xc6\xf9\xd6\x0e\x21\x38\xdf\xd0\x02\xe7\x99\xeb\x9b\xa6\x63\x35\x8e\xd7\x38\xa6\x9b\x7b\xec\xf2\xe2\x8d\x37\xba\xf4\x8e\xec\x27\xa6\x18\x72\x24\x3e\x4c\x8d\x32\x91\xbf\xc5\x99\x6d\x23\x75\xb3\xd9\x94\x95\x16\x4b\xb3\x85\xe1\xef\x0c\x4c\xc3\x8b\x5e\x68\xf4\x68\xd7\x13\x8f\xf6\xfe\xed\x37\x7e\x7a\x7e\x11\xfa\xae\x5c\xda\x74\x31\x3f\x27\x01\xd0\x5e\xfc\xf7\xe8\x8b\x5e\xf6\xd4\xab\xb4\xde\xd5\x19\x2f\x8a\x73\xec\x97\xb8\x80\x32\xb7\xef\x52\x6b\x06\x3b\x65\xa9\x2c\x6d\xd0\x13\x9d\x97\x7f\x56\x38\x8b\x54\xfd\x21\xa3\x81\x51\x91\x08\x0f\xe1\xdf\x01\x00\x00\xff\xff\x6d\x98\xe3\x82\xd1\x13\x00\x00"), }, + "/src/syscall/js/js_test.go": &vfsgen۰CompressedFileInfo{ + name: "js_test.go", + modTime: time.Date(2019, 4, 24, 16, 16, 8, 196455338, time.UTC), + uncompressedSize: 377, + + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\xcc\xb1\x0e\x82\x30\x10\xc6\xf1\x99\xef\x29\x2e\x4c\x14\xc5\x82\x31\x4c\xdd\x9c\x9c\x65\x37\x80\x95\x14\xa4\x25\xf4\x70\x31\xbe\xbb\x31\xd1\xc9\x94\xf5\x7e\xdf\xfd\xa5\xa4\x4d\xb3\x98\xfb\x95\x7a\x0f\x4c\x75\x3b\xd4\x9d\xa6\xde\x5f\x58\x7b\x06\xcc\x38\xb9\x99\x29\x41\x14\x7f\x0e\xc6\x76\x31\x04\x70\x5b\x6c\x4b\x95\xf6\x7c\xb2\x7c\x74\xf6\xa1\x67\x6f\x9c\x4d\x98\xd2\xef\x6a\x57\x09\x7a\x22\xe2\xff\xc9\x96\x72\x11\x80\x22\x04\x59\x50\x0a\xa5\xf6\xc1\x5e\xf6\x53\x29\xe9\x3c\x98\x89\xd8\xb9\xac\x31\x1d\xd9\x65\x6c\xf4\xec\x11\xc9\x34\x54\x3d\xac\x56\xc3\x5a\x28\x55\xae\xbe\x96\xb9\x48\x25\x5e\x78\x07\x00\x00\xff\xff\x00\x23\x1d\xb3\x79\x01\x00\x00"), + }, "/src/syscall/syscall.go": &vfsgen۰CompressedFileInfo{ name: "syscall.go", modTime: time.Date(2019, 3, 5, 14, 33, 26, 82012629, time.UTC), @@ -864,6 +871,7 @@ var FS = func() http.FileSystem { } fs["/src/syscall/js"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ fs["/src/syscall/js/js.go"].(os.FileInfo), + fs["/src/syscall/js/js_test.go"].(os.FileInfo), } fs["/src/testing"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ fs["/src/testing/example.go"].(os.FileInfo), diff --git a/compiler/natives/src/syscall/js/js_test.go b/compiler/natives/src/syscall/js/js_test.go new file mode 100644 index 000000000..47cfe9c4d --- /dev/null +++ b/compiler/natives/src/syscall/js/js_test.go @@ -0,0 +1,20 @@ +// +build js + +package js_test + +import ( + "testing" +) + +func TestIntConversion(t *testing.T) { + testIntConversion(t, 0) + testIntConversion(t, 1) + testIntConversion(t, -1) + testIntConversion(t, 1<<20) + testIntConversion(t, -1<<20) + // Skip too-big numbers + // testIntConversion(t, 1<<40) + // testIntConversion(t, -1<<40) + // testIntConversion(t, 1<<60) + // testIntConversion(t, -1<<60) +} diff --git a/tests/syscalljs_test.go b/tests/syscalljs_test.go deleted file mode 100644 index 8dc139f0e..000000000 --- a/tests/syscalljs_test.go +++ /dev/null @@ -1,275 +0,0 @@ -// +build js - -package tests - -import ( - "fmt" - "math" - "syscall/js" - "testing" -) - -func TestSyscallJSNull(t *testing.T) { - want := "null" - if got := js.Null().String(); got != want { - t.Errorf("got %#v, want %#v", got, want) - } -} - -func TestSyscallJSFuncOf(t *testing.T) { - c := js.FuncOf(func(this js.Value, args []js.Value) interface{} { - return args[0].Int() + args[1].Int() - }) - defer c.Release() - - got := js.ValueOf(c).Invoke(1, 2).Int() - want := 3 - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } -} - -func TestSyscallJSFuncOfObject(t *testing.T) { - c := js.FuncOf(func(this js.Value, args []js.Value) interface{} { - return args[0].Get("foo").String() - }) - defer c.Release() - - got := js.ValueOf(c).Invoke(js.Global().Call("eval", `({"foo": "bar"})`)).String() - want := "bar" - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } -} - -func TestSyscallJSString(t *testing.T) { - obj := js.Global().Call("eval", "'Hello'") - got := obj.String() - if want := "Hello"; got != want { - t.Errorf("got %#v, want %#v", got, want) - } - - obj = js.Global().Call("eval", "123") - got = obj.String() - if want := "123"; got != want { - t.Errorf("got %#v, want %#v", got, want) - } -} - -func TestSyscallJSInt64(t *testing.T) { - var i int64 = math.MaxInt64 - got := js.ValueOf(i).String() - // js.Value keeps the value only in 53-bit precision. - if want := "9223372036854776000"; got != want { - t.Errorf("got %#v, want %#v", got, want) - } -} - -func TestSyscallJSInstanceOf(t *testing.T) { - arr := js.Global().Call("eval", "[]") - got := arr.InstanceOf(js.Global().Call("eval", "Array")) - want := true - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } - - got = arr.InstanceOf(js.Global().Call("eval", "Object")) - want = true - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } - - got = arr.InstanceOf(js.Global().Call("eval", "String")) - want = false - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } - - str := js.Global().Call("eval", "String").New() - got = str.InstanceOf(js.Global().Call("eval", "Array")) - want = false - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } - - got = str.InstanceOf(js.Global().Call("eval", "Object")) - want = true - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } - - got = str.InstanceOf(js.Global().Call("eval", "String")) - want = true - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } -} - -func TestSyscallJSTypedArrayOf(t *testing.T) { - testTypedArrayOf(t, "[]int8", []int8{0, -42, 0}, -42) - testTypedArrayOf(t, "[]int16", []int16{0, -42, 0}, -42) - testTypedArrayOf(t, "[]int32", []int32{0, -42, 0}, -42) - testTypedArrayOf(t, "[]uint8", []uint8{0, 42, 0}, 42) - testTypedArrayOf(t, "[]uint16", []uint16{0, 42, 0}, 42) - testTypedArrayOf(t, "[]uint32", []uint32{0, 42, 0}, 42) - testTypedArrayOf(t, "[]float32", []float32{0, -42.5, 0}, -42.5) - testTypedArrayOf(t, "[]float64", []float64{0, -42.5, 0}, -42.5) -} - -func testTypedArrayOf(t *testing.T, name string, slice interface{}, want float64) { - t.Run(name, func(t *testing.T) { - a := js.TypedArrayOf(slice) - got := a.Index(1).Float() - a.Release() - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } - - a2 := js.TypedArrayOf(slice) - v := js.ValueOf(a2) - got = v.Index(1).Float() - a2.Release() - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } - }) -} - -func TestSyscallJSType(t *testing.T) { - if got, want := js.Undefined().Type(), js.TypeUndefined; got != want { - t.Errorf("got %s, want %s", got, want) - } - if got, want := js.Null().Type(), js.TypeNull; got != want { - t.Errorf("got %s, want %s", got, want) - } - if got, want := js.ValueOf(true).Type(), js.TypeBoolean; got != want { - t.Errorf("got %s, want %s", got, want) - } - if got, want := js.ValueOf(42).Type(), js.TypeNumber; got != want { - t.Errorf("got %s, want %s", got, want) - } - if got, want := js.ValueOf("test").Type(), js.TypeString; got != want { - t.Errorf("got %s, want %s", got, want) - } - if got, want := js.Global().Get("Symbol").Invoke("test").Type(), js.TypeSymbol; got != want { - t.Errorf("got %s, want %s", got, want) - } - if got, want := js.Global().Get("Array").New().Type(), js.TypeObject; got != want { - t.Errorf("got %s, want %s", got, want) - } - if got, want := js.Global().Get("Array").Type(), js.TypeFunction; got != want { - t.Errorf("got %s, want %s", got, want) - } -} - -func TestSyscallJSValueOf(t *testing.T) { - JSON := js.Global().Get("JSON") - for _, test := range []struct { - in interface{} - wantType js.Type - wantString string - }{ - {js.Value(js.ValueOf(42)), js.TypeNumber, "42"}, - {js.FuncOf(func(this js.Value, args []js.Value) interface{} { return nil }), js.TypeFunction, ""}, - {js.TypedArrayOf([]int8{1, 2, 3}), js.TypeObject, `{"0":1,"1":2,"2":3}`}, - {nil, js.TypeNull, "null"}, - {bool(true), js.TypeBoolean, "true"}, - {int(1), js.TypeNumber, "1"}, - {int8(2), js.TypeNumber, "2"}, - {int16(3), js.TypeNumber, "3"}, - {int32(4), js.TypeNumber, "4"}, - {int64(5), js.TypeNumber, "5"}, - {uint(6), js.TypeNumber, "6"}, - {uint8(7), js.TypeNumber, "7"}, - {uint16(8), js.TypeNumber, "8"}, - {uint32(9), js.TypeNumber, "9"}, - {uint64(10), js.TypeNumber, "10"}, - {float32(11), js.TypeNumber, "11"}, - {float64(12), js.TypeNumber, "12"}, - // FIXME this doesn't work {unsafe.Pointer(&x19), js.TypeNumber, ""}, - {string("hello"), js.TypeString, `"hello"`}, - {map[string]interface{}{"a": 1}, js.TypeObject, `{"a":1}`}, - {[]interface{}{1, 2, 3}, js.TypeObject, "[1,2,3]"}, - } { - t.Run(fmt.Sprintf("%T", test.in), func(t *testing.T) { - got := js.ValueOf(test.in) - if got.Type() != test.wantType { - t.Errorf("type: got %v want %v", got.Type(), test.wantType) - } - gotString := JSON.Call("stringify", got).String() - if test.wantString != "" && gotString != test.wantString { - t.Errorf("string: got %v want %v", gotString, test.wantString) - } - }) - } - - // Check unknown types panic - didPanic := false - func() { - defer func() { - if r := recover(); r != nil { - didPanic = true - } - }() - _ = js.ValueOf([]struct{}{}) - }() - if !didPanic { - t.Errorf("Unknown type didn't panic") - } -} - -func TestSyscallJSFuncObject(t *testing.T) { - got := "" - f := js.FuncOf(func(this js.Value, args []js.Value) interface{} { - got = args[0].Get("foo").String() + this.Get("name").String() - return nil - }) - defer f.Release() - - obj := js.Global().Call("eval", `({})`) - obj.Set("func", f) - obj.Set("name", "baz") - arg := js.Global().Call("eval", `({"foo": "bar"})`) - obj.Call("func", arg) - - want := "barbaz" - if got != want { - t.Errorf("got %#v, want %#v", got, want) - } -} - -func TestSyscallJSValueOfFunc(t *testing.T) { - f := js.FuncOf(func(this js.Value, args []js.Value) interface{} { return nil }) - got := js.ValueOf(f).Type() - want := js.TypeFunction - if got != want { - t.Fail() - } -} - -func TestSyscallJSTruthy(t *testing.T) { - for _, test := range []struct { - in interface{} - want bool - }{ - {false, false}, - {true, true}, - {nil, false}, - {js.Undefined(), false}, - {0, false}, - {1, true}, - {0.0, false}, - {"", false}, - {"a", true}, - {map[string]interface{}{}, true}, - {[]interface{}{}, true}, - } { - t.Run(fmt.Sprintf("%%", test.in), func(t *testing.T) { - got := js.ValueOf(test.in).Truthy() - want := test.want - if got != want { - t.Errorf("got: %v, want: %v", got, want) - } - }) - } -} From fecd56c505cecebb73ec7635c29a7e5df8c0be8f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 25 Apr 2019 01:42:33 +0900 Subject: [PATCH 3/9] Add syscall/js test on CircleCI --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index a0944f476..4a56ed59c 100644 --- a/circle.yml +++ b/circle.yml @@ -26,6 +26,6 @@ jobs: - run: for d in */; do echo ./$d...; done | grep -v ./doc | grep -v ./tests | grep -v ./node | xargs go vet # All subdirectories except "doc", "tests", "node*". - run: diff -u <(echo -n) <(go list ./compiler/natives/src/...) # All those packages should have // +build js. - run: gopherjs install -v net/http # Should build successfully (can't run tests, since only client is supported). - - run: ulimit -s 10000 && gopherjs test --minify -v --short github.com/gopherjs/gopherjs/tests/... $(go list std | grep -v -x -f .std_test_pkg_exclusions) + - run: ulimit -s 10000 && gopherjs test --minify -v --short github.com/gopherjs/gopherjs/tests/... $(go list std | grep -v -x -f .std_test_pkg_exclusions) syscall/js - run: go test -v -race ./... - run: gopherjs test -v fmt # No minification should work. From 859138e5f0c8963c65a0c2fedddfbf873462a056 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 25 Apr 2019 02:40:30 +0900 Subject: [PATCH 4/9] Copy the original js_test.go --- build/build.go | 3 - compiler/gopherjspkg/fs_vfsdata.go | 2 +- compiler/natives/fs_vfsdata.go | 10 +- compiler/natives/src/syscall/js/js_test.go | 367 ++++++++++++++++++++- tool.go | 9 +- 5 files changed, 378 insertions(+), 13 deletions(-) diff --git a/build/build.go b/build/build.go index e142e82ec..9170f2ce8 100644 --- a/build/build.go +++ b/build/build.go @@ -173,9 +173,6 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build case "crypto/rand": pkg.GoFiles = []string{"rand.go", "util.go"} pkg.TestGoFiles = exclude(pkg.TestGoFiles, "rand_linux_test.go") // Don't want linux-specific tests (since linux-specific package files are excluded too). - case "syscall/js": - // Add Go files for tests explicitly since the files are excluded due to 'wasm' build tag. - pkg.XTestGoFiles = []string{"js_test.go"} } if len(pkg.CgoFiles) > 0 { diff --git a/compiler/gopherjspkg/fs_vfsdata.go b/compiler/gopherjspkg/fs_vfsdata.go index c46530432..563d24a83 100644 --- a/compiler/gopherjspkg/fs_vfsdata.go +++ b/compiler/gopherjspkg/fs_vfsdata.go @@ -21,7 +21,7 @@ var FS = func() http.FileSystem { fs := vfsgen۰FS{ "/": &vfsgen۰DirInfo{ name: "/", - modTime: time.Date(2019, 4, 24, 15, 56, 5, 751826141, time.UTC), + modTime: time.Date(2019, 4, 24, 17, 37, 54, 745979914, time.UTC), }, "/js": &vfsgen۰DirInfo{ name: "js", diff --git a/compiler/natives/fs_vfsdata.go b/compiler/natives/fs_vfsdata.go index 3bfbde263..3ede4ad80 100644 --- a/compiler/natives/fs_vfsdata.go +++ b/compiler/natives/fs_vfsdata.go @@ -21,7 +21,7 @@ var FS = func() http.FileSystem { fs := vfsgen۰FS{ "/": &vfsgen۰DirInfo{ name: "/", - modTime: time.Date(2019, 4, 11, 0, 32, 11, 450815925, time.UTC), + modTime: time.Date(2019, 4, 24, 16, 42, 24, 967092015, time.UTC), }, "/src": &vfsgen۰DirInfo{ name: "src", @@ -548,7 +548,7 @@ var FS = func() http.FileSystem { }, "/src/syscall/js": &vfsgen۰DirInfo{ name: "js", - modTime: time.Date(2019, 4, 24, 16, 16, 8, 197108888, time.UTC), + modTime: time.Date(2019, 4, 24, 17, 34, 20, 576847746, time.UTC), }, "/src/syscall/js/js.go": &vfsgen۰CompressedFileInfo{ name: "js.go", @@ -559,10 +559,10 @@ var FS = func() http.FileSystem { }, "/src/syscall/js/js_test.go": &vfsgen۰CompressedFileInfo{ name: "js_test.go", - modTime: time.Date(2019, 4, 24, 16, 16, 8, 196455338, time.UTC), - uncompressedSize: 377, + modTime: time.Date(2019, 4, 24, 17, 34, 20, 576447471, time.UTC), + uncompressedSize: 10611, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\xcc\xb1\x0e\x82\x30\x10\xc6\xf1\x99\xef\x29\x2e\x4c\x14\xc5\x82\x31\x4c\xdd\x9c\x9c\x65\x37\x80\x95\x14\xa4\x25\xf4\x70\x31\xbe\xbb\x31\xd1\xc9\x94\xf5\x7e\xdf\xfd\xa5\xa4\x4d\xb3\x98\xfb\x95\x7a\x0f\x4c\x75\x3b\xd4\x9d\xa6\xde\x5f\x58\x7b\x06\xcc\x38\xb9\x99\x29\x41\x14\x7f\x0e\xc6\x76\x31\x04\x70\x5b\x6c\x4b\x95\xf6\x7c\xb2\x7c\x74\xf6\xa1\x67\x6f\x9c\x4d\x98\xd2\xef\x6a\x57\x09\x7a\x22\xe2\xff\xc9\x96\x72\x11\x80\x22\x04\x59\x50\x0a\xa5\xf6\xc1\x5e\xf6\x53\x29\xe9\x3c\x98\x89\xd8\xb9\xac\x31\x1d\xd9\x65\x6c\xf4\xec\x11\xc9\x34\x54\x3d\xac\x56\xc3\x5a\x28\x55\xae\xbe\x96\xb9\x48\x25\x5e\x78\x07\x00\x00\xff\xff\x00\x23\x1d\xb3\x79\x01\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x5a\x5f\x73\xdb\x36\x12\x7f\x16\x3f\xc5\x96\x69\xe7\xc4\x2b\x45\x4a\xb2\xe2\xa9\x95\xe8\xc1\x49\x13\xd7\x37\x1d\xbb\x13\xbb\xf7\xd0\x5c\x26\x85\xc8\x95\x44\x9b\x04\x54\x00\x94\xad\xb8\xfa\xee\x37\xf8\x43\x8a\x92\x48\x5b\x49\x94\xfa\xc5\x02\xb0\x7f\x7e\xd8\x5d\x2c\x16\x20\xc2\x10\xae\x67\x89\x80\x49\x92\x22\x24\x02\x22\x36\x4f\x30\x86\x09\x67\x19\x7c\x7f\x76\xf9\xee\xf2\xf2\x3a\x14\x3c\x0a\xc5\x52\x44\x24\x4d\xc3\x1b\x11\xde\x88\x8f\x12\x85\x0c\xa6\xcc\x71\xc2\x10\x5e\xb3\xf9\x92\x27\xd3\x99\x84\x7e\xb7\xf7\x13\x5c\xcf\x10\xce\x18\x9c\xe6\x72\xc6\xb8\x08\xe0\x34\x4d\x41\x0f\x0b\xe0\x28\x90\x2f\x30\x0e\x14\xdb\xef\x02\x81\x4d\x40\x2a\xe5\x82\xe5\x3c\x42\x88\x58\xac\x31\x4c\xd9\x02\x39\xc5\x18\xc6\x4b\x20\xf0\xea\xea\xe7\x8e\x90\xcb\x14\x15\x57\x9a\x44\x48\x05\x82\x9c\x11\x09\x11\xa1\x30\x46\x98\xb0\x9c\xc6\x90\x50\x90\x33\x84\x5f\xcf\x5f\xbf\xb9\xb8\x7a\xa3\xe7\x13\x68\x7c\x3f\x8e\xf3\x24\x8d\xe1\x46\xe8\xd6\x35\x03\x9e\x6b\x52\x25\x05\x85\x14\x43\x27\x0c\xd5\x48\x07\xce\xa9\x90\x24\x4d\xe1\x82\xc5\x68\x7a\x4e\xe3\x18\xc2\x39\x91\xb3\x50\xb2\x70\xca\xc2\x2c\x11\x51\x78\x47\x44\x06\x92\xc1\x92\xe5\x1c\xbe\xff\xed\xf4\xfa\x17\x68\x0b\x66\x20\xb9\x53\xa6\xa5\xba\x1a\xdc\x24\xa1\xb1\x12\x04\xaa\xff\xe3\x8d\xf8\xa8\x58\x3f\xe2\x3d\x46\xae\x17\x18\x0d\x67\x97\x97\x57\xa3\x1b\x01\x67\x97\xa7\xef\x5e\xff\x32\xd2\xb2\xad\x0c\x8b\xeb\x0a\x11\x3a\x8a\x47\x4d\x51\xc9\x9f\x61\x3a\x37\x4a\x7c\x20\x34\x5e\xf7\xf1\x9c\xba\x30\x61\x1c\x62\x94\x24\x49\x45\xe0\x38\x73\x12\xdd\x92\x29\x82\xf5\x99\xe3\x24\xd9\x9c\x71\x09\x6d\xa7\xe5\x4e\x32\xe9\x3a\x2d\x37\x23\x72\xa6\xfe\xaf\x3d\xac\x5a\x8a\x3a\xa1\x53\xd7\xf1\x1c\x67\x41\x38\xc4\x79\x96\x2d\x05\x8c\xe0\x46\x04\x67\x29\x1b\x93\xb4\xed\x05\xaf\x49\x9a\xb6\x5d\x5c\x90\xd4\xf5\xe1\xcf\xf6\x83\xd3\x12\x2c\xc3\x57\x8c\xa5\x43\x90\x3c\x47\xdf\x74\x5c\x49\x9e\xd0\xe9\x10\x5c\x32\x8e\xfe\x97\xf7\xfa\x47\x03\xd7\x8e\x9c\x53\x39\x84\x41\xdf\xb6\xde\xa6\x8c\xe8\x76\xd0\xeb\x1f\xd9\xbe\x53\xce\xc9\x72\x08\xef\x07\x3d\x5f\x11\xc2\xe0\xe8\x83\x1d\xf9\x99\x48\x1c\x02\xc5\x3b\x50\xbf\xda\x9e\xef\xb4\x48\x1c\x0f\x61\x92\xd3\x48\x26\x8c\xb6\x89\x0f\x63\x0f\x1e\x9c\x56\x8b\xa3\xcc\x39\x05\x02\x3f\xc2\xf8\x85\xd3\x5a\xf9\x4e\xeb\x13\x72\x36\x84\xae\x92\xa5\xd1\xfd\xa1\xdb\x6e\x57\x21\xbb\x20\x17\x43\xb8\x20\x17\xbe\xd3\xc2\x6c\x2e\x97\x97\xe3\x9b\x21\x3c\xac\x8a\x66\x01\x49\x01\x39\xa7\x93\x84\x26\x72\x39\x84\xe2\x97\xe2\xc7\xe9\xba\xbf\x53\x19\x60\xe3\x9b\x8b\x3c\x1b\x23\xef\x1a\xe0\xa6\xd1\xee\x7a\x66\x4c\x19\x0e\x09\x7d\x4b\x52\x61\x67\x66\x7b\xda\x13\xd5\xe5\xf9\xce\xca\xfb\xd3\x73\x1c\x35\x43\xb8\x46\x21\xd5\x70\x5b\xc2\xbf\xad\xb3\x82\x6b\x3d\xdd\x3b\x42\x25\x0c\x47\xda\x03\x4e\x8b\xa9\x9f\xc6\x7b\xc1\x19\xca\xb6\x5b\xb8\xc8\xf5\x9c\x56\x32\x81\x29\xd3\xc4\x2c\xd0\xc2\xbc\x17\xba\xe3\xbb\x11\x68\x29\xca\x78\x32\x78\xc3\x39\xe3\x93\xb6\xab\x46\x7e\x78\xb6\xf0\xcd\xd8\x0f\xcf\x16\xae\xaf\xa8\x4d\xdb\x73\x5a\x2b\xa7\x65\x15\x5d\x29\x45\x4c\xce\x90\x6b\x4d\x25\xc5\x5a\x5f\x15\xd1\x9a\xd0\x3b\x0c\x8a\x64\xd2\x30\x63\x25\xb2\x61\x64\x53\x89\x20\x19\xc2\x82\xa4\x39\x02\x65\x12\xf0\xaf\x9c\x68\x83\xad\x9c\x55\xc5\xfe\x26\xb0\x9b\x3d\x50\x09\xf8\x06\x47\x18\x09\xdb\xae\xb0\x72\x0f\xee\x0c\xab\x6d\x1f\x77\x14\xc0\x0e\x85\xa5\xc6\x25\x85\x8a\x3a\xa7\x94\x63\xfb\xba\xc5\x18\xfd\xdc\xda\x7d\xd0\xd7\x06\xdf\x95\x7b\x4e\xe5\x5e\xc6\x3e\xff\xbc\x39\x9e\xdb\x69\x56\x83\xe3\x9c\xca\xe6\xc8\x18\xf4\x1b\x02\xa2\x06\xa0\x12\x74\xf0\x50\x50\x7a\xf6\x89\x03\x8d\xe7\x20\x10\x6a\x22\x40\x0b\xaf\x73\xbf\x19\xd8\xd7\xf7\x0d\xf8\x55\x8a\xdf\xc1\xde\xdd\x17\x78\xb7\xce\xa1\xaf\x19\x5d\x20\x17\x6a\x77\xd9\x71\xad\xdc\x25\x31\x52\x6a\x07\x7a\x4d\x03\x9d\xc6\x91\xde\xcb\x97\xfd\x46\x79\x1d\x3b\xea\xb4\x54\xc9\x70\x9b\xcc\x41\x32\x06\xe3\x64\x0a\x09\x95\x38\x45\x55\x8a\x5d\xcf\x70\xa9\xea\x12\x65\xbe\xb1\x2a\xb7\xb2\x79\x92\x62\x0c\x77\x89\x9c\xc1\x51\x7f\x9c\x48\x40\xba\x48\x38\xa3\x19\x52\x69\x8a\x8b\x33\x36\x9f\x21\xff\xcf\x95\xaa\xcb\x18\xb5\x25\x1b\x66\x81\xd6\xd3\x04\x73\xa0\x60\x36\x8d\x77\x9e\x22\xe8\xbd\x7c\x79\xfc\x94\x00\x45\x50\xf8\xa6\x86\xa8\xe2\x1b\xeb\xd9\x84\x4a\xed\xa5\x75\xa8\xdc\x88\xe0\xbf\x2a\x9a\x2e\x27\x6d\x1d\xa4\x87\x08\xf2\x6a\xb8\xe8\x6a\xe6\xb1\x0c\xa0\xaa\x9c\x86\x2c\xa0\x79\xb7\xf3\x80\x11\x78\xf0\x4c\x60\x74\xed\x93\x0b\x2c\xaa\x03\x01\xa9\xc9\x07\x56\x41\x5d\x46\x28\x86\xbe\x64\x9b\xbe\x1c\xdf\x60\x54\xe3\x8a\x1a\x04\xba\xb6\xab\x47\x50\x0c\xed\xbf\x23\x85\x21\x9c\x52\x60\x5a\xbb\x5e\x4c\x89\x14\x30\xe7\x4c\x32\xb9\x9c\x23\x88\x19\xcb\xd3\x18\xec\x6a\xd4\x9c\x81\xd3\xd2\xe3\x36\x3e\xcb\x42\x5b\x83\x30\xd3\x70\x6d\xab\x94\xa3\xb4\xed\x30\x6c\x54\xe6\xae\x2a\x25\xad\x11\x3c\x1b\x55\x46\xcd\x68\x04\x6c\x6b\x42\x16\xae\x86\x23\xd4\x31\x67\x03\xf4\xae\x71\xdf\x72\xf6\x09\x69\x93\x89\x9f\x00\xd6\x2e\x8a\x75\x68\x7b\xf0\x00\x29\x4a\x50\xbb\x76\x15\xef\x0b\x60\xc1\x24\xc1\x34\x86\x11\x3c\x7f\x61\xbb\x83\x09\x47\xfc\x84\x6d\xe6\xbd\x00\x5b\xdc\xb3\x17\xb0\xf2\xcc\xf4\x8a\x25\xf6\x7c\x73\xfd\x68\xb3\x69\x51\xeb\x5d\x41\x93\x7e\x37\xd2\x44\x5f\xb3\xd8\xaf\x97\x73\x8c\x75\x84\x5c\x4e\xea\xb7\x86\x4d\x0a\x1f\xdc\xf7\x1f\x12\x2a\x7f\x72\x7d\x30\x3f\x1e\xba\x3e\x74\xd4\x09\xa7\xbb\xd2\x3f\xbc\xc7\xd8\x7a\xc7\x05\x5f\xef\xf8\xb3\x18\x8f\xfa\x05\xe3\x51\x7f\x7f\xc6\xbc\x44\x9a\x17\x50\x0b\xbe\xa7\xd8\x2c\xd2\xbc\x84\xba\x2f\xa3\x45\x9a\x97\x50\xf7\x61\x9c\xa8\x2c\x61\x39\xed\x6f\x3b\xcb\xe0\x79\x39\xcf\xe0\xf9\x13\x02\x8e\x07\x6b\x01\xc7\x83\x7a\x01\xd5\xcd\xa7\xd1\xf9\x3e\x50\x95\x1e\xcc\x09\xd3\x07\x91\x26\x11\xea\xfd\x98\x4f\x48\x84\x0f\x2b\x1b\x5c\x56\x91\x09\x95\xe0\x5d\x4e\xdb\x8a\xcd\xd7\x27\xd9\xdd\x60\x6a\x11\xbb\xa6\x36\xd4\x6a\xd9\x9e\xd3\x6a\xd9\x70\x27\xc1\x39\x8d\xf1\xbe\xdd\x2b\xd3\xb5\xe2\x0c\xde\x61\x8a\x44\xa0\x6e\xd9\xb5\x51\x4d\xe0\x9f\x11\xff\x2a\x85\xaf\xbc\x8d\x45\x70\x41\x2e\x9a\xf7\xbb\xca\x76\x9b\x11\x39\x0b\x14\xb1\xe7\x39\xad\x9a\xcd\xe6\x82\x5c\x54\xf6\xbe\x43\xec\xc5\xbf\xd3\x18\x27\x09\xc5\x78\x17\x5f\x75\x3f\xb4\x97\x2a\x37\x22\x58\x33\x78\x5e\x65\xa3\x50\x09\x73\x73\x14\xfe\xfe\x7b\x03\xbb\x16\xa1\xf7\x8f\xc7\xe9\xee\x97\x9f\x6a\xc9\x36\x67\x59\x1d\x04\xbc\x9f\x63\x24\x31\xde\xcd\xc1\x17\x79\x5a\x73\x0f\xb0\x3d\xb3\x9e\xeb\x03\x4d\x52\x6f\x77\xa4\x6f\x26\xad\xc5\xd4\xcd\xd7\x0c\xd4\x4d\xb5\x57\x4e\xa2\x99\xa6\xbf\x4d\xb3\x33\x47\xd5\xff\xc8\xf4\x7e\x45\x3a\x95\xb3\xda\xfd\xbb\x26\x7a\x2a\x7b\x75\x60\x39\xd7\xa5\xca\xd1\xbe\x61\x74\x54\x53\xfe\xab\xf5\xf4\x05\x20\xca\x85\xb8\x59\x60\x0e\xfa\xfb\x62\xd1\x19\x6f\xeb\xe6\x01\x9b\xf0\x34\xa1\x28\x39\xfa\x3e\x9c\x9c\x34\x16\x7a\xbb\xc0\xfb\xdb\xc0\x4f\x4e\xf6\x05\xae\xf5\x6c\x02\xd7\xfb\xff\x0e\xe8\x05\xe1\x90\xa8\xcc\x78\x3c\x80\x11\x0c\xba\x35\xe8\x4c\xe1\x40\xe2\xd8\xf5\x21\xf1\x61\x07\xd5\x67\x9b\xf3\x71\x15\xcd\x35\xcb\xa0\xeb\x7a\x87\xd0\xbf\x19\x5b\x0b\x76\x8b\x5f\x64\x17\xed\x35\x85\x59\x01\xd2\x52\x0e\x62\x9d\x8d\xf4\x82\x77\x8f\xc5\xfd\x4e\xa1\x5a\xc4\x8f\xe2\x1b\xf4\x6b\x56\xe1\x57\xda\x4a\x48\x42\x23\xac\x2b\xb4\xca\xe8\x7d\x12\x57\xb9\x00\xac\xce\xe1\x08\x4a\xe6\xa0\xa2\xa2\x49\x88\xe7\xeb\xfb\xd5\xaf\x3f\x03\x7d\x01\x84\xb7\xb6\x68\xd6\x28\xf4\xd5\xf0\xe1\x4e\xad\xaa\xa8\x68\x72\xf6\x1a\xe7\xe6\xa6\xa5\x2b\x91\xb6\xe7\x17\x45\x49\x39\xf4\x24\x2c\x51\xa0\x12\x4f\xdb\xa6\xdc\x3f\xb6\xd5\xa9\xde\x43\x6b\x2a\x4a\x15\xe5\xe3\x1d\x85\xf6\x56\xfe\x5b\xe9\xec\xd6\xcc\x30\x1b\x23\xff\x56\xfa\xd4\x12\xfd\x47\x15\xda\x22\x69\x5b\xa9\xb9\x88\x3d\xb4\xd2\xcd\xa5\x73\xb5\xcc\xc6\xfa\x3b\x83\xcd\x95\x4d\x50\x34\xd9\xb7\x85\xb2\x91\x8d\xb6\x01\x98\x63\xee\x3f\x03\x60\x4b\x75\x91\x5d\xbe\x46\xf9\xca\x71\xf4\x15\x87\xbd\x4c\x18\x41\x46\xe6\xef\xcd\x31\xe8\x43\xe5\xfc\x63\x88\x88\x4e\xd8\x23\x73\x2c\x2d\x87\xd6\x29\xa9\x5c\x8b\xdb\x59\x89\x6c\xc5\x95\x16\xa4\x8e\x6b\xe5\x8f\xe2\xcc\xd8\x5d\x6d\x14\x3c\xa4\x5a\x93\x7d\x46\x71\x56\x26\xd1\xed\xfd\x69\x7d\xd1\x51\x60\x31\x33\x7f\x70\xef\xdd\x21\x14\xbf\x97\xee\x10\x06\xfd\xd5\xca\xab\xb9\x97\xb8\x2f\xee\x75\x96\x3b\x57\xd6\x9f\x89\xa5\x6a\xba\x3f\x90\x33\x8d\xa8\xbe\xb4\x58\x94\x88\x35\xa2\xc5\xe3\xe7\x11\x73\xa3\x5e\xb2\x40\x22\xf4\xdd\xd5\x26\x43\xcd\x05\x51\x4e\xa3\x3a\xef\x45\x6a\xf6\x19\xb9\xc5\x76\x34\x23\x54\x1d\x92\xf3\x48\x3e\x28\xe3\x44\x63\x6b\x4c\xcb\x6a\xce\xc1\xb3\x44\x94\xba\x95\x8b\xa7\x02\xde\x7f\x28\x3a\xbc\xea\xb1\x5a\x83\xae\x78\x9b\x4f\xc5\xfb\xee\x87\x7a\xab\xee\x5d\x84\xa8\x25\xd5\x8a\xe0\x65\xa7\x44\xfa\xb0\x5a\x7f\x5a\xa6\x49\xaa\x8f\xc3\xad\x18\x27\xc8\x21\x1a\x57\x4f\xda\xbb\xb5\xa4\x40\x79\x9d\x64\xc8\x72\x75\xdc\x8c\xc6\x3e\x74\xad\x96\x97\x9d\xa8\xa6\x30\x2c\x96\x64\x8d\x11\x49\x9a\x62\xac\x66\xa9\xeb\x80\x03\xd9\x2e\x1a\xf7\x0f\x20\xa5\x00\x57\x7c\x89\x2e\x8d\x35\xe8\x2b\x73\x2a\x9b\x16\xd6\xea\x6f\x5c\x4c\x58\x32\xd5\x6d\xd3\xb4\xd7\x6c\xdc\xb5\x9f\xa3\x71\x49\x7e\x88\xb3\xc1\x77\x16\xfe\xc6\x0a\x28\xef\x2b\x55\xe4\x1b\x82\xcd\x88\x7f\x73\x4f\xb2\x79\x8a\xd6\x6e\xe5\x4a\x8b\xc6\x85\x35\xb5\x8b\xbe\xda\xb6\x93\x4c\x06\xbf\xf1\x84\xca\x94\xb6\xdd\x71\x2e\x25\xa3\x10\xa5\x49\x74\x6b\xf0\xb4\xaa\x36\x82\x30\x04\x6e\x1a\xfa\x89\x4c\x39\x87\x44\x7f\xcb\x01\xcb\x7e\x97\xa4\x69\x71\x19\x6d\x45\x01\x99\x92\x84\xd6\x44\xf9\xce\x5e\x12\xb3\x28\xcf\x50\x7f\x2b\x34\x11\x3e\x45\xf9\x26\x45\xd5\xf5\x6a\x79\xae\x0e\x54\x6e\xb6\x7c\xa5\x15\x95\x24\x24\x8e\xdf\x2c\x90\xca\x5f\x13\x21\x91\x22\x57\x44\x5a\xb1\x5e\x13\xfa\x6a\xc9\x3c\x7f\x31\x2f\x65\x66\x52\xce\xc5\x30\x0c\x63\x5c\x60\xca\xe6\xc8\x83\x8c\x7d\x4a\xd2\x94\x04\x8c\x4f\x43\xa4\x9d\xdf\xaf\xc2\x98\x45\x22\x3c\x4b\x99\x10\x84\x2f\xc3\x6b\x9e\xcb\xd9\x72\x93\x5b\x48\x12\xdd\xb2\x05\xf2\x49\xca\xee\x82\x88\x65\xe1\x5f\xb9\x5a\x51\x8c\x8a\xb0\x77\xf2\xd3\xd1\xc9\xc9\xf3\x7e\x48\xd2\xb4\xa3\xd7\xd3\xb2\xa3\xaf\xf6\x45\x27\xa1\x9d\x1b\xb2\x20\x22\xe2\xc9\x5c\x16\x84\x47\xcf\x8a\x1f\x6b\x1d\xc3\x30\xbc\xbb\xbb\x0b\x30\xca\x48\x47\x3b\x8d\x12\x25\x9c\xa4\x06\xa5\xea\xee\x1f\xf7\xc3\xe7\x41\x2f\x7c\x26\x30\xea\x9c\x04\xfd\x4a\xf1\xad\x01\x3f\xf5\xa2\x63\xc2\x38\x7c\xf4\xe1\x16\xf5\x29\x87\x13\x3a\x45\x78\xff\xc1\xec\xae\x2a\x36\xd6\xaf\x1a\x7c\xa8\x7e\x4c\xb7\x2d\xf3\xe5\xb7\xf2\x51\xc5\x36\x4c\x39\x60\x1b\x3f\x13\x89\xae\xaf\x85\x95\xcf\x63\x5c\x5f\x45\x92\xdb\x75\x55\xe6\x97\xc6\xb6\xad\x96\x3d\x2f\xdb\xbf\x30\x2c\xc3\x4b\x00\xe1\x58\xa1\x2b\x9e\xd2\x28\x15\xeb\x77\x34\xaa\x55\xbc\x90\x51\xbf\x2b\x6f\x67\xb4\xfe\x30\xd4\x2f\xc8\xcc\x16\x5a\x15\xe9\x03\x2e\xb0\x88\xe1\xe5\xbf\x38\xae\x5f\xd3\x00\xe3\x5b\x2f\x67\x02\x05\x60\xfd\xfa\x46\x29\xda\x7a\x6f\xa3\x94\x6d\x6f\x1c\x95\x13\xf6\x2d\x2e\xbd\xc0\xba\xa7\xe6\xc3\x57\x25\xb5\xfc\x20\x86\x50\x97\x5e\x6e\x71\x59\x73\x81\x6a\xdf\x2d\x40\x99\xbf\x1f\xfd\x94\xdd\x0c\xe0\x0b\x4e\x9d\xb5\xb7\xae\x87\x57\x51\xad\xfb\xbf\x91\xfc\xe2\x58\xf8\x0d\x44\x6f\x9c\x72\x0f\x22\x7f\xe5\xfc\x3f\x00\x00\xff\xff\x76\x69\x89\xce\x73\x29\x00\x00"), }, "/src/syscall/syscall.go": &vfsgen۰CompressedFileInfo{ name: "syscall.go", diff --git a/compiler/natives/src/syscall/js/js_test.go b/compiler/natives/src/syscall/js/js_test.go index 47cfe9c4d..f7e87884b 100644 --- a/compiler/natives/src/syscall/js/js_test.go +++ b/compiler/natives/src/syscall/js/js_test.go @@ -1,20 +1,385 @@ +// This file is copied from $GOROOT/src/syscall/js/js_test.go + +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + // +build js +// To run these tests: +// +// - Install Node +// - Add /path/to/go/misc/wasm to your $PATH (so that "go test" can find +// "go_js_wasm_exec"). +// - GOOS=js GOARCH=wasm go test +// +// See -exec in "go help test", and "go help run" for details. + package js_test import ( + "fmt" + "math" + "syscall/js" "testing" ) +var dummys = js.Global().Call("eval", `({ + someBool: true, + someString: "abc\u1234", + someInt: 42, + someFloat: 42.123, + someArray: [41, 42, 43], + someDate: new Date(), + add: function(a, b) { + return a + b; + }, + zero: 0, + stringZero: "0", + NaN: NaN, + emptyObj: {}, + emptyArray: [], + Infinity: Infinity, + NegInfinity: -Infinity, + objNumber0: new Number(0), + objBooleanFalse: new Boolean(false), +})`) + +func TestBool(t *testing.T) { + want := true + o := dummys.Get("someBool") + if got := o.Bool(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + dummys.Set("otherBool", want) + if got := dummys.Get("otherBool").Bool(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if dummys.Get("someBool") != dummys.Get("someBool") { + t.Errorf("same value not equal") + } +} + +func TestString(t *testing.T) { + want := "abc\u1234" + o := dummys.Get("someString") + if got := o.String(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + dummys.Set("otherString", want) + if got := dummys.Get("otherString").String(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if dummys.Get("someString") != dummys.Get("someString") { + t.Errorf("same value not equal") + } + + wantInt := "42" + o = dummys.Get("someInt") + if got := o.String(); got != wantInt { + t.Errorf("got %#v, want %#v", got, wantInt) + } +} + +func TestInt(t *testing.T) { + want := 42 + o := dummys.Get("someInt") + if got := o.Int(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + dummys.Set("otherInt", want) + if got := dummys.Get("otherInt").Int(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if dummys.Get("someInt") != dummys.Get("someInt") { + t.Errorf("same value not equal") + } + if got := dummys.Get("zero").Int(); got != 0 { + t.Errorf("got %#v, want %#v", got, 0) + } +} + func TestIntConversion(t *testing.T) { testIntConversion(t, 0) testIntConversion(t, 1) testIntConversion(t, -1) testIntConversion(t, 1<<20) testIntConversion(t, -1<<20) - // Skip too-big numbers + + // Skip too big integers. They cannot be compiled with 32bit environment, and GopherJS is one of them. // testIntConversion(t, 1<<40) // testIntConversion(t, -1<<40) // testIntConversion(t, 1<<60) // testIntConversion(t, -1<<60) } + +func testIntConversion(t *testing.T, want int) { + if got := js.ValueOf(want).Int(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestFloat(t *testing.T) { + want := 42.123 + o := dummys.Get("someFloat") + if got := o.Float(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + dummys.Set("otherFloat", want) + if got := dummys.Get("otherFloat").Float(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if dummys.Get("someFloat") != dummys.Get("someFloat") { + t.Errorf("same value not equal") + } +} + +func TestObject(t *testing.T) { + if dummys.Get("someArray") != dummys.Get("someArray") { + t.Errorf("same value not equal") + } + + // An object and its prototype should not be equal. + proto := js.Global().Get("Object").Get("prototype") + o := js.Global().Call("eval", "new Object()") + if proto == o { + t.Errorf("object equals to its prototype") + } +} + +func TestFrozenObject(t *testing.T) { + o := js.Global().Call("eval", "(function () { let o = new Object(); o.field = 5; Object.freeze(o); return o; })()") + want := 5 + if got := o.Get("field").Int(); want != got { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestTypedArrayOf(t *testing.T) { + testTypedArrayOf(t, "[]int8", []int8{0, -42, 0}, -42) + testTypedArrayOf(t, "[]int16", []int16{0, -42, 0}, -42) + testTypedArrayOf(t, "[]int32", []int32{0, -42, 0}, -42) + testTypedArrayOf(t, "[]uint8", []uint8{0, 42, 0}, 42) + testTypedArrayOf(t, "[]uint16", []uint16{0, 42, 0}, 42) + testTypedArrayOf(t, "[]uint32", []uint32{0, 42, 0}, 42) + testTypedArrayOf(t, "[]float32", []float32{0, -42.5, 0}, -42.5) + testTypedArrayOf(t, "[]float64", []float64{0, -42.5, 0}, -42.5) +} + +func testTypedArrayOf(t *testing.T, name string, slice interface{}, want float64) { + t.Run(name, func(t *testing.T) { + a := js.TypedArrayOf(slice) + got := a.Index(1).Float() + a.Release() + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } + }) +} + +func TestNaN(t *testing.T) { + want := js.ValueOf(math.NaN()) + got := dummys.Get("NaN") + if got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestUndefined(t *testing.T) { + dummys.Set("test", js.Undefined()) + if dummys == js.Undefined() || dummys.Get("test") != js.Undefined() || dummys.Get("xyz") != js.Undefined() { + t.Errorf("js.Undefined expected") + } +} + +func TestNull(t *testing.T) { + dummys.Set("test1", nil) + dummys.Set("test2", js.Null()) + if dummys == js.Null() || dummys.Get("test1") != js.Null() || dummys.Get("test2") != js.Null() { + t.Errorf("js.Null expected") + } +} + +func TestLength(t *testing.T) { + if got := dummys.Get("someArray").Length(); got != 3 { + t.Errorf("got %#v, want %#v", got, 3) + } +} + +func TestIndex(t *testing.T) { + if got := dummys.Get("someArray").Index(1).Int(); got != 42 { + t.Errorf("got %#v, want %#v", got, 42) + } +} + +func TestSetIndex(t *testing.T) { + dummys.Get("someArray").SetIndex(2, 99) + if got := dummys.Get("someArray").Index(2).Int(); got != 99 { + t.Errorf("got %#v, want %#v", got, 99) + } +} + +func TestCall(t *testing.T) { + var i int64 = 40 + if got := dummys.Call("add", i, 2).Int(); got != 42 { + t.Errorf("got %#v, want %#v", got, 42) + } + if got := dummys.Call("add", js.Global().Call("eval", "40"), 2).Int(); got != 42 { + t.Errorf("got %#v, want %#v", got, 42) + } +} + +func TestInvoke(t *testing.T) { + var i int64 = 40 + if got := dummys.Get("add").Invoke(i, 2).Int(); got != 42 { + t.Errorf("got %#v, want %#v", got, 42) + } +} + +func TestNew(t *testing.T) { + if got := js.Global().Get("Array").New(42).Length(); got != 42 { + t.Errorf("got %#v, want %#v", got, 42) + } +} + +func TestInstanceOf(t *testing.T) { + someArray := js.Global().Get("Array").New() + if got, want := someArray.InstanceOf(js.Global().Get("Array")), true; got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if got, want := someArray.InstanceOf(js.Global().Get("Function")), false; got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} + +func TestType(t *testing.T) { + if got, want := js.Undefined().Type(), js.TypeUndefined; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.Null().Type(), js.TypeNull; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.ValueOf(true).Type(), js.TypeBoolean; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.ValueOf(0).Type(), js.TypeNumber; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.ValueOf(42).Type(), js.TypeNumber; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.ValueOf("test").Type(), js.TypeString; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.Global().Get("Symbol").Invoke("test").Type(), js.TypeSymbol; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.Global().Get("Array").New().Type(), js.TypeObject; got != want { + t.Errorf("got %s, want %s", got, want) + } + if got, want := js.Global().Get("Array").Type(), js.TypeFunction; got != want { + t.Errorf("got %s, want %s", got, want) + } +} + +type object = map[string]interface{} +type array = []interface{} + +func TestValueOf(t *testing.T) { + a := js.ValueOf(array{0, array{0, 42, 0}, 0}) + if got := a.Index(1).Index(1).Int(); got != 42 { + t.Errorf("got %v, want %v", got, 42) + } + + o := js.ValueOf(object{"x": object{"y": 42}}) + if got := o.Get("x").Get("y").Int(); got != 42 { + t.Errorf("got %v, want %v", got, 42) + } +} + +func TestZeroValue(t *testing.T) { + var v js.Value + if v != js.Undefined() { + t.Error("zero js.Value is not js.Undefined()") + } +} + +func TestFuncOf(t *testing.T) { + c := make(chan struct{}) + cb := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + if got := args[0].Int(); got != 42 { + t.Errorf("got %#v, want %#v", got, 42) + } + c <- struct{}{} + return nil + }) + defer cb.Release() + js.Global().Call("setTimeout", cb, 0, 42) + <-c +} + +func TestInvokeFunction(t *testing.T) { + called := false + cb := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + cb2 := js.FuncOf(func(this js.Value, args []js.Value) interface{} { + called = true + return 42 + }) + defer cb2.Release() + return cb2.Invoke() + }) + defer cb.Release() + if got := cb.Invoke().Int(); got != 42 { + t.Errorf("got %#v, want %#v", got, 42) + } + if !called { + t.Error("function not called") + } +} + +func ExampleFuncOf() { + var cb js.Func + cb = js.FuncOf(func(this js.Value, args []js.Value) interface{} { + fmt.Println("button clicked") + cb.Release() // release the function if the button will not be clicked again + return nil + }) + js.Global().Get("document").Call("getElementById", "myButton").Call("addEventListener", "click", cb) +} + +// See +// - https://developer.mozilla.org/en-US/docs/Glossary/Truthy +// - https://stackoverflow.com/questions/19839952/all-falsey-values-in-javascript/19839953#19839953 +// - http://www.ecma-international.org/ecma-262/5.1/#sec-9.2 +func TestTruthy(t *testing.T) { + want := true + for _, key := range []string{ + "someBool", "someString", "someInt", "someFloat", "someArray", "someDate", + "stringZero", // "0" is truthy + "add", // functions are truthy + "emptyObj", "emptyArray", "Infinity", "NegInfinity", + // All objects are truthy, even if they're Number(0) or Boolean(false). + "objNumber0", "objBooleanFalse", + } { + if got := dummys.Get(key).Truthy(); got != want { + t.Errorf("%s: got %#v, want %#v", key, got, want) + } + } + + want = false + if got := dummys.Get("zero").Truthy(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if got := dummys.Get("NaN").Truthy(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if got := js.ValueOf("").Truthy(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if got := js.Null().Truthy(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } + if got := js.Undefined().Truthy(); got != want { + t.Errorf("got %#v, want %#v", got, want) + } +} diff --git a/tool.go b/tool.go index 4c580a139..e3bb7dd79 100644 --- a/tool.go +++ b/tool.go @@ -326,9 +326,12 @@ func main() { var exitErr error for _, pkg := range pkgs { - if len(pkg.TestGoFiles) == 0 && len(pkg.XTestGoFiles) == 0 { - fmt.Printf("? \t%s\t[no test files]\n", pkg.ImportPath) - continue + // syscall/js doesn't have a buildable file originally, but has Go files in compiler/natives. + if pkg.Package.ImportPath != "syscall/js" { + if len(pkg.TestGoFiles) == 0 && len(pkg.XTestGoFiles) == 0 { + fmt.Printf("? \t%s\t[no test files]\n", pkg.ImportPath) + continue + } } s := gbuild.NewSession(options) From 3f13a79a8434dc245a9556881aa8d6476a9fcb06 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 26 Apr 2019 00:14:35 +0900 Subject: [PATCH 5/9] Move js_test.go to tests/syscalljs/js_test.go --- circle.yml | 2 +- compiler/gopherjspkg/fs_vfsdata.go | 2 +- compiler/natives/fs_vfsdata.go | 10 +--------- .../src/syscall/js => tests/syscalljs}/js_test.go | 4 ++++ 4 files changed, 7 insertions(+), 11 deletions(-) rename {compiler/natives/src/syscall/js => tests/syscalljs}/js_test.go (99%) diff --git a/circle.yml b/circle.yml index 4a56ed59c..a0944f476 100644 --- a/circle.yml +++ b/circle.yml @@ -26,6 +26,6 @@ jobs: - run: for d in */; do echo ./$d...; done | grep -v ./doc | grep -v ./tests | grep -v ./node | xargs go vet # All subdirectories except "doc", "tests", "node*". - run: diff -u <(echo -n) <(go list ./compiler/natives/src/...) # All those packages should have // +build js. - run: gopherjs install -v net/http # Should build successfully (can't run tests, since only client is supported). - - run: ulimit -s 10000 && gopherjs test --minify -v --short github.com/gopherjs/gopherjs/tests/... $(go list std | grep -v -x -f .std_test_pkg_exclusions) syscall/js + - run: ulimit -s 10000 && gopherjs test --minify -v --short github.com/gopherjs/gopherjs/tests/... $(go list std | grep -v -x -f .std_test_pkg_exclusions) - run: go test -v -race ./... - run: gopherjs test -v fmt # No minification should work. diff --git a/compiler/gopherjspkg/fs_vfsdata.go b/compiler/gopherjspkg/fs_vfsdata.go index 563d24a83..cbabd2a7d 100644 --- a/compiler/gopherjspkg/fs_vfsdata.go +++ b/compiler/gopherjspkg/fs_vfsdata.go @@ -21,7 +21,7 @@ var FS = func() http.FileSystem { fs := vfsgen۰FS{ "/": &vfsgen۰DirInfo{ name: "/", - modTime: time.Date(2019, 4, 24, 17, 37, 54, 745979914, time.UTC), + modTime: time.Date(2019, 4, 25, 14, 57, 55, 762548316, time.UTC), }, "/js": &vfsgen۰DirInfo{ name: "js", diff --git a/compiler/natives/fs_vfsdata.go b/compiler/natives/fs_vfsdata.go index 3ede4ad80..0bf9992a0 100644 --- a/compiler/natives/fs_vfsdata.go +++ b/compiler/natives/fs_vfsdata.go @@ -548,7 +548,7 @@ var FS = func() http.FileSystem { }, "/src/syscall/js": &vfsgen۰DirInfo{ name: "js", - modTime: time.Date(2019, 4, 24, 17, 34, 20, 576847746, time.UTC), + modTime: time.Date(2019, 4, 25, 15, 5, 54, 254191414, time.UTC), }, "/src/syscall/js/js.go": &vfsgen۰CompressedFileInfo{ name: "js.go", @@ -557,13 +557,6 @@ var FS = func() http.FileSystem { compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x58\x4f\x6f\xdb\xb8\x12\x3f\x4b\x9f\x62\xaa\x43\x41\x35\x82\xf2\xfa\xe7\xe5\x15\x2e\x7c\xe8\x5b\x6c\x8b\x16\xdb\x66\xb1\xe9\xee\x1e\x82\x60\x43\xcb\x94\xc3\x44\xa6\x0c\x89\x52\x6d\x18\xfe\xee\x8b\x19\x52\x14\xa5\xc8\x6e\x80\xdd\x1c\x1c\x7a\xe6\x37\x7f\x38\x1c\xce\x0c\x7d\x7e\x0e\x67\x8b\x46\x16\x4b\xb8\xaf\xc3\x70\xc3\xb3\x07\xbe\x12\xb4\x96\xeb\x4d\x59\x69\x60\x61\x10\x55\x22\x2f\x44\xa6\xa3\x30\x88\x1a\x55\xf3\x5c\x44\x61\x18\x44\x2b\xa9\xef\x9a\x45\x9a\x95\xeb\xf3\x55\xb9\xb9\x13\xd5\x7d\xdd\x2f\xee\xeb\x28\x8c\xc3\x50\xef\x36\x02\xbe\xe1\x87\x54\x3a\x0c\xb3\x52\xd5\xa4\x12\x49\xbf\xab\xa5\xc8\xa5\x12\x4b\x03\x98\x83\x2c\x35\x37\xac\xaf\x4d\x51\x98\xd5\xff\xcb\xb2\x10\x5c\x75\xe4\xf5\x42\x54\x66\x7d\xa5\x2b\xa9\x56\x76\xbd\x5b\x2f\x4a\x2b\x70\xb9\xb8\x17\x99\x36\xeb\x0f\x8d\xca\xb4\x2c\x15\x7a\x92\x37\x2a\x03\xa6\xc9\x56\x0c\x46\x9a\xc5\x50\xd3\x02\xf6\x61\x50\x7f\x97\x3a\xbb\x03\x8d\xeb\x8c\xd7\xc6\x6d\xe7\xe3\x2c\x0c\x82\x4a\xe8\xa6\x52\x10\x35\x1d\x31\xf2\x90\xe8\xb2\x0f\x52\x4d\x51\xf8\x7c\xbb\x11\x1f\xb2\x30\xa4\xa1\x16\xdc\xe1\x50\x0f\x52\x7c\x8c\xf1\xdd\xc7\x98\x4d\x0c\x30\x14\x91\x01\x86\x28\x3e\xc6\x44\xca\xc7\x94\x44\xf1\x31\x5d\x04\x7d\x54\x6e\x69\x51\x18\x2c\x45\xce\x9b\x82\x74\x6c\xb8\x92\x19\x8b\x16\x7c\x09\x78\xe8\x51\x1c\x06\x87\xf0\x60\xe3\xfe\xb1\x28\x17\xbc\x60\x31\xfc\xc1\x8b\x46\x60\x84\xad\x32\xfa\xbe\x6f\x67\x70\x5f\xa7\x06\xd4\x0b\x61\x44\x4f\x89\x28\xe9\x81\xdd\x41\xfd\xc0\x88\xc3\x91\x28\xa5\x27\xee\x11\xf3\xa0\xc9\xe8\xec\x09\xed\xf4\xb2\x9c\xf8\x31\xfc\x26\x0a\xc1\x6b\xc1\x62\xc4\xe4\xa9\xb1\x31\xb7\x4e\x3a\x38\x62\x2f\x73\x96\x2b\xc0\xaf\x4c\xdf\xc9\xda\x98\x4f\x80\x57\xab\x1a\xae\x6f\xe8\x5b\x8c\xd7\x41\x54\x39\xcf\xc4\xfe\x10\x1b\x0f\x7a\x7f\xf1\xeb\x3e\x0c\x8c\x27\x33\xeb\x7e\x18\x04\x81\xd9\xc2\x17\xfe\x40\xe7\xc2\x7a\x13\x2f\xee\xeb\xd4\x1c\xa7\xb3\xd3\x93\x06\xc6\x80\x14\x05\x2d\xa1\x66\x73\x58\xf3\x07\xc1\xac\x57\x09\x14\x42\x31\xe4\xc4\x31\xa1\xf2\xb2\x02\x99\x00\x47\x60\xc5\xd5\x4a\x18\xe5\x46\x85\xd1\x71\x2d\x6f\x60\x6e\x5d\xe4\x07\x62\x98\x4f\xbb\x97\x5c\x31\xc3\x44\x3f\x0f\x09\x90\x10\x69\x3f\xc4\x49\x18\x04\x87\xc4\xe6\x09\x1d\xc5\xcf\x55\x55\x56\xc7\xcf\xc2\x02\x62\xf3\x6f\x70\x7b\xbb\xe4\xfc\xcc\x5b\x7e\x95\x55\x72\xa3\x41\x20\x68\x06\x11\x9c\x81\x48\x3f\x0a\xcd\xa2\xb5\xa8\x6b\xbe\x12\x51\x9c\x76\xf7\xdf\x59\x36\xe7\xd9\x5b\x6e\xbd\x98\x22\xa8\xe5\x15\xd6\x2d\xb9\x84\xfe\xcf\x43\x04\x52\xd5\x9a\xab\x4c\x5c\xe6\x23\xc6\x4a\x68\xd2\x4d\x35\xce\x63\x74\x25\x49\x2a\xa9\x4d\x52\xc9\xbc\xbf\x05\xf0\x6c\x8e\xf9\x4d\xa1\x96\x4b\x98\xf7\x9c\xf4\x27\x5e\x14\x2c\x12\x2d\x2f\xa2\x04\x22\xd6\xdd\x46\xb6\x8d\x61\x0f\x36\x0c\xdb\x77\x70\x88\xf1\x0a\xfa\x7e\x3d\x49\x49\x02\x3b\x5f\x0f\x74\xf2\x65\x0e\x3b\xa7\x74\xb0\xa7\xa3\x6a\x6f\x87\xbe\x85\x00\x32\x07\x86\xd1\x2e\x73\xa4\xcc\xe7\x73\xbf\x96\x1a\x08\x74\xa6\xff\xf3\x0e\xce\xcf\x87\x35\x38\x04\x38\x58\x2d\x5b\x92\xc6\x1a\x3b\x12\x7b\xe9\xc4\xa8\x87\xf4\x12\x23\xbb\x5d\xed\x1d\x89\xbf\x72\xe2\x5d\xe3\x39\xaa\xc1\x16\xe6\x91\x82\xd7\x9e\x7d\x6a\x56\x47\xe5\x6d\xd1\x1e\xc9\xbf\x71\xf2\xb6\xc1\x1d\x97\x37\x05\x7d\x24\xff\xdf\x5e\xde\x34\xc5\xa3\xf2\xae\x8c\x8f\x34\xfc\xcf\x69\x70\xed\xd3\xe8\xb0\xfc\x0b\xc7\xef\x6e\x47\x7c\x3b\x28\xf6\x94\x1a\x97\x39\xdb\x0e\x8b\x9c\xab\xca\xb6\xd1\x6e\xb1\xaa\x6c\x53\x72\x2b\x76\x4d\xd7\xd4\xbc\xbe\xdb\x6c\x2d\x1d\x7d\xf1\xc9\xa6\x00\x7b\x9d\x6a\xf9\xbe\xaa\xf8\xee\x28\x44\x49\xbf\x1b\xda\xaa\x6d\x58\x98\x0a\x09\xfa\x4a\x1f\x6f\xe9\xf3\xe5\x05\xfd\x7b\xfd\x8a\xfe\x5d\xbc\x49\xa0\x21\x40\x63\x10\x8d\x85\x34\x16\xd3\x58\x50\x5e\x94\x9c\x08\xb4\x20\x31\x9a\x97\xd2\x5f\x4b\x8a\x45\x62\x2b\x56\x02\x6b\xbe\xb9\x36\xeb\x1b\x2f\x4a\x09\x5c\xfb\x5f\x3d\x8f\x5d\x0f\x93\xcb\xf4\x93\x6a\xcb\x07\xc1\xb6\xf1\x61\xa2\x03\xdf\x4a\xd5\xf2\x42\x2e\xb1\x54\xcf\xe0\x16\xce\xc0\x4e\x6f\x29\x1d\x19\x9e\xbf\xab\x7e\x83\x63\x63\x2d\xd8\xde\x84\xa9\xcf\x62\x8a\x8b\xad\x4b\x2d\xdd\xf4\xd9\x1c\x5a\xd2\xc2\xe2\x77\x96\xf4\x6c\xee\x5f\x16\x2a\x57\xc6\x8d\xe7\xa4\x8b\xea\xf4\x3e\xa2\x75\x8a\xa0\x28\x31\x82\x07\x32\xdd\x6d\xae\x4d\xdb\xd4\x18\x75\xde\x64\xa5\x6a\x45\xa5\xdf\x57\xab\x9a\xd9\x8e\x36\xc8\xa6\xc1\x57\xb4\xab\xc4\xf7\xf7\xb6\xa7\x0d\x78\xfb\x43\x48\x7d\xec\x2f\xea\x8c\x13\x9d\xac\x45\x5a\x97\xb3\xbc\x5a\x61\x81\xeb\x94\xcd\x81\x6f\x36\x42\x2d\x99\x25\x24\xe8\xea\xc0\x75\xcb\x98\x88\x22\xd5\xc2\xb5\x3b\x70\xb2\x97\xa6\xe9\xf4\x9d\x78\x42\x8c\xcd\x6d\x83\xe7\xcf\x87\xe4\xee\x92\x9e\x8e\x3d\x3a\x33\x8a\xbd\xcc\x61\x53\x95\x9b\xde\x2a\xb6\xc8\x75\xec\x8c\x3b\xe6\x71\x43\xd1\x7d\x6d\xc7\x13\x32\x30\x23\x19\x51\xe9\x1d\x35\xdd\x35\x9c\x41\x04\xb2\x06\x55\x6a\xe0\xd0\xd5\x9b\x04\x56\xa5\x26\x40\x67\x61\x98\x8f\x8f\x32\x1e\xb3\xc3\x04\x33\x79\x94\x16\x71\x9a\xa6\xf1\x54\x0e\x7f\xc0\x0b\xc8\xe2\xee\x22\x3e\x31\xc6\xa6\x66\x9f\x0e\x25\x69\x3e\x9e\xc7\xd6\xf0\x84\x4b\x18\xdf\x8d\xcd\x87\x13\x43\x2a\x2a\x21\xe8\xe4\xbe\x3e\xa9\xa5\xd8\x32\x89\x55\xe9\x07\x3a\x2c\xf2\x88\x16\x8c\x8d\x54\xfa\x5f\x8c\xcb\x27\x75\x22\x2a\x64\x70\xd2\x91\x6e\x3c\x61\xba\xa3\x75\x75\xc7\x8a\xf7\x13\x4c\x57\xf8\xda\x04\x74\x3c\x2e\x18\xbe\x4e\x42\xfd\xe3\x0b\xf7\xb4\x9b\x65\xac\x4d\xef\x7c\x74\x1e\xe4\xd6\x93\x33\xf8\xf3\x15\x2d\x26\xde\x33\xed\x04\xfa\x17\xa1\x56\xfa\xae\x3f\x54\x2f\xf6\x1d\x6b\x42\xea\xab\xf8\xfe\x83\x38\x4d\xed\x04\xa5\x9e\xbc\x8d\x2b\x2f\xeb\x13\x18\xcd\x04\x38\x68\xa7\x6d\x4a\x98\x04\xb6\x53\x2e\x5e\x09\xed\xe5\xfc\x09\x0d\x16\x75\x4c\xcd\xe3\x07\xbf\x17\x22\xff\x39\x30\x12\xfc\x56\x35\xfa\x6e\xc7\x1e\xa5\xe5\x44\xcf\xf2\x84\x28\x9f\xcc\xef\x1a\xbd\x08\x51\xfd\xd9\xd9\x25\x74\x6c\x2e\x48\xff\x1c\xe9\x27\x9a\xa3\xaf\xa1\x1e\x72\x99\xb3\xba\x90\x99\x18\x46\xc6\x53\xd1\x0f\x5d\x06\x37\x9b\x9b\xc5\x78\xf8\xa2\xc6\xf9\xd6\x0e\x21\x38\xdf\xd0\x02\xe7\x99\xeb\x9b\xa6\x63\x35\x8e\xd7\x38\xa6\x9b\x7b\xec\xf2\xe2\x8d\x37\xba\xf4\x8e\xec\x27\xa6\x18\x72\x24\x3e\x4c\x8d\x32\x91\xbf\xc5\x99\x6d\x23\x75\xb3\xd9\x94\x95\x16\x4b\xb3\x85\xe1\xef\x0c\x4c\xc3\x8b\x5e\x68\xf4\x68\xd7\x13\x8f\xf6\xfe\xed\x37\x7e\x7a\x7e\x11\xfa\xae\x5c\xda\x74\x31\x3f\x27\x01\xd0\x5e\xfc\xf7\xe8\x8b\x5e\xf6\xd4\xab\xb4\xde\xd5\x19\x2f\x8a\x73\xec\x97\xb8\x80\x32\xb7\xef\x52\x6b\x06\x3b\x65\xa9\x2c\x6d\xd0\x13\x9d\x97\x7f\x56\x38\x8b\x54\xfd\x21\xa3\x81\x51\x91\x08\x0f\xe1\xdf\x01\x00\x00\xff\xff\x6d\x98\xe3\x82\xd1\x13\x00\x00"), }, - "/src/syscall/js/js_test.go": &vfsgen۰CompressedFileInfo{ - name: "js_test.go", - modTime: time.Date(2019, 4, 24, 17, 34, 20, 576447471, time.UTC), - uncompressedSize: 10611, - - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xbc\x5a\x5f\x73\xdb\x36\x12\x7f\x16\x3f\xc5\x96\x69\xe7\xc4\x2b\x45\x4a\xb2\xe2\xa9\x95\xe8\xc1\x49\x13\xd7\x37\x1d\xbb\x13\xbb\xf7\xd0\x5c\x26\x85\xc8\x95\x44\x9b\x04\x54\x00\x94\xad\xb8\xfa\xee\x37\xf8\x43\x8a\x92\x48\x5b\x49\x94\xfa\xc5\x02\xb0\x7f\x7e\xd8\x5d\x2c\x16\x20\xc2\x10\xae\x67\x89\x80\x49\x92\x22\x24\x02\x22\x36\x4f\x30\x86\x09\x67\x19\x7c\x7f\x76\xf9\xee\xf2\xf2\x3a\x14\x3c\x0a\xc5\x52\x44\x24\x4d\xc3\x1b\x11\xde\x88\x8f\x12\x85\x0c\xa6\xcc\x71\xc2\x10\x5e\xb3\xf9\x92\x27\xd3\x99\x84\x7e\xb7\xf7\x13\x5c\xcf\x10\xce\x18\x9c\xe6\x72\xc6\xb8\x08\xe0\x34\x4d\x41\x0f\x0b\xe0\x28\x90\x2f\x30\x0e\x14\xdb\xef\x02\x81\x4d\x40\x2a\xe5\x82\xe5\x3c\x42\x88\x58\xac\x31\x4c\xd9\x02\x39\xc5\x18\xc6\x4b\x20\xf0\xea\xea\xe7\x8e\x90\xcb\x14\x15\x57\x9a\x44\x48\x05\x82\x9c\x11\x09\x11\xa1\x30\x46\x98\xb0\x9c\xc6\x90\x50\x90\x33\x84\x5f\xcf\x5f\xbf\xb9\xb8\x7a\xa3\xe7\x13\x68\x7c\x3f\x8e\xf3\x24\x8d\xe1\x46\xe8\xd6\x35\x03\x9e\x6b\x52\x25\x05\x85\x14\x43\x27\x0c\xd5\x48\x07\xce\xa9\x90\x24\x4d\xe1\x82\xc5\x68\x7a\x4e\xe3\x18\xc2\x39\x91\xb3\x50\xb2\x70\xca\xc2\x2c\x11\x51\x78\x47\x44\x06\x92\xc1\x92\xe5\x1c\xbe\xff\xed\xf4\xfa\x17\x68\x0b\x66\x20\xb9\x53\xa6\xa5\xba\x1a\xdc\x24\xa1\xb1\x12\x04\xaa\xff\xe3\x8d\xf8\xa8\x58\x3f\xe2\x3d\x46\xae\x17\x18\x0d\x67\x97\x97\x57\xa3\x1b\x01\x67\x97\xa7\xef\x5e\xff\x32\xd2\xb2\xad\x0c\x8b\xeb\x0a\x11\x3a\x8a\x47\x4d\x51\xc9\x9f\x61\x3a\x37\x4a\x7c\x20\x34\x5e\xf7\xf1\x9c\xba\x30\x61\x1c\x62\x94\x24\x49\x45\xe0\x38\x73\x12\xdd\x92\x29\x82\xf5\x99\xe3\x24\xd9\x9c\x71\x09\x6d\xa7\xe5\x4e\x32\xe9\x3a\x2d\x37\x23\x72\xa6\xfe\xaf\x3d\xac\x5a\x8a\x3a\xa1\x53\xd7\xf1\x1c\x67\x41\x38\xc4\x79\x96\x2d\x05\x8c\xe0\x46\x04\x67\x29\x1b\x93\xb4\xed\x05\xaf\x49\x9a\xb6\x5d\x5c\x90\xd4\xf5\xe1\xcf\xf6\x83\xd3\x12\x2c\xc3\x57\x8c\xa5\x43\x90\x3c\x47\xdf\x74\x5c\x49\x9e\xd0\xe9\x10\x5c\x32\x8e\xfe\x97\xf7\xfa\x47\x03\xd7\x8e\x9c\x53\x39\x84\x41\xdf\xb6\xde\xa6\x8c\xe8\x76\xd0\xeb\x1f\xd9\xbe\x53\xce\xc9\x72\x08\xef\x07\x3d\x5f\x11\xc2\xe0\xe8\x83\x1d\xf9\x99\x48\x1c\x02\xc5\x3b\x50\xbf\xda\x9e\xef\xb4\x48\x1c\x0f\x61\x92\xd3\x48\x26\x8c\xb6\x89\x0f\x63\x0f\x1e\x9c\x56\x8b\xa3\xcc\x39\x05\x02\x3f\xc2\xf8\x85\xd3\x5a\xf9\x4e\xeb\x13\x72\x36\x84\xae\x92\xa5\xd1\xfd\xa1\xdb\x6e\x57\x21\xbb\x20\x17\x43\xb8\x20\x17\xbe\xd3\xc2\x6c\x2e\x97\x97\xe3\x9b\x21\x3c\xac\x8a\x66\x01\x49\x01\x39\xa7\x93\x84\x26\x72\x39\x84\xe2\x97\xe2\xc7\xe9\xba\xbf\x53\x19\x60\xe3\x9b\x8b\x3c\x1b\x23\xef\x1a\xe0\xa6\xd1\xee\x7a\x66\x4c\x19\x0e\x09\x7d\x4b\x52\x61\x67\x66\x7b\xda\x13\xd5\xe5\xf9\xce\xca\xfb\xd3\x73\x1c\x35\x43\xb8\x46\x21\xd5\x70\x5b\xc2\xbf\xad\xb3\x82\x6b\x3d\xdd\x3b\x42\x25\x0c\x47\xda\x03\x4e\x8b\xa9\x9f\xc6\x7b\xc1\x19\xca\xb6\x5b\xb8\xc8\xf5\x9c\x56\x32\x81\x29\xd3\xc4\x2c\xd0\xc2\xbc\x17\xba\xe3\xbb\x11\x68\x29\xca\x78\x32\x78\xc3\x39\xe3\x93\xb6\xab\x46\x7e\x78\xb6\xf0\xcd\xd8\x0f\xcf\x16\xae\xaf\xa8\x4d\xdb\x73\x5a\x2b\xa7\x65\x15\x5d\x29\x45\x4c\xce\x90\x6b\x4d\x25\xc5\x5a\x5f\x15\xd1\x9a\xd0\x3b\x0c\x8a\x64\xd2\x30\x63\x25\xb2\x61\x64\x53\x89\x20\x19\xc2\x82\xa4\x39\x02\x65\x12\xf0\xaf\x9c\x68\x83\xad\x9c\x55\xc5\xfe\x26\xb0\x9b\x3d\x50\x09\xf8\x06\x47\x18\x09\xdb\xae\xb0\x72\x0f\xee\x0c\xab\x6d\x1f\x77\x14\xc0\x0e\x85\xa5\xc6\x25\x85\x8a\x3a\xa7\x94\x63\xfb\xba\xc5\x18\xfd\xdc\xda\x7d\xd0\xd7\x06\xdf\x95\x7b\x4e\xe5\x5e\xc6\x3e\xff\xbc\x39\x9e\xdb\x69\x56\x83\xe3\x9c\xca\xe6\xc8\x18\xf4\x1b\x02\xa2\x06\xa0\x12\x74\xf0\x50\x50\x7a\xf6\x89\x03\x8d\xe7\x20\x10\x6a\x22\x40\x0b\xaf\x73\xbf\x19\xd8\xd7\xf7\x0d\xf8\x55\x8a\xdf\xc1\xde\xdd\x17\x78\xb7\xce\xa1\xaf\x19\x5d\x20\x17\x6a\x77\xd9\x71\xad\xdc\x25\x31\x52\x6a\x07\x7a\x4d\x03\x9d\xc6\x91\xde\xcb\x97\xfd\x46\x79\x1d\x3b\xea\xb4\x54\xc9\x70\x9b\xcc\x41\x32\x06\xe3\x64\x0a\x09\x95\x38\x45\x55\x8a\x5d\xcf\x70\xa9\xea\x12\x65\xbe\xb1\x2a\xb7\xb2\x79\x92\x62\x0c\x77\x89\x9c\xc1\x51\x7f\x9c\x48\x40\xba\x48\x38\xa3\x19\x52\x69\x8a\x8b\x33\x36\x9f\x21\xff\xcf\x95\xaa\xcb\x18\xb5\x25\x1b\x66\x81\xd6\xd3\x04\x73\xa0\x60\x36\x8d\x77\x9e\x22\xe8\xbd\x7c\x79\xfc\x94\x00\x45\x50\xf8\xa6\x86\xa8\xe2\x1b\xeb\xd9\x84\x4a\xed\xa5\x75\xa8\xdc\x88\xe0\xbf\x2a\x9a\x2e\x27\x6d\x1d\xa4\x87\x08\xf2\x6a\xb8\xe8\x6a\xe6\xb1\x0c\xa0\xaa\x9c\x86\x2c\xa0\x79\xb7\xf3\x80\x11\x78\xf0\x4c\x60\x74\xed\x93\x0b\x2c\xaa\x03\x01\xa9\xc9\x07\x56\x41\x5d\x46\x28\x86\xbe\x64\x9b\xbe\x1c\xdf\x60\x54\xe3\x8a\x1a\x04\xba\xb6\xab\x47\x50\x0c\xed\xbf\x23\x85\x21\x9c\x52\x60\x5a\xbb\x5e\x4c\x89\x14\x30\xe7\x4c\x32\xb9\x9c\x23\x88\x19\xcb\xd3\x18\xec\x6a\xd4\x9c\x81\xd3\xd2\xe3\x36\x3e\xcb\x42\x5b\x83\x30\xd3\x70\x6d\xab\x94\xa3\xb4\xed\x30\x6c\x54\xe6\xae\x2a\x25\xad\x11\x3c\x1b\x55\x46\xcd\x68\x04\x6c\x6b\x42\x16\xae\x86\x23\xd4\x31\x67\x03\xf4\xae\x71\xdf\x72\xf6\x09\x69\x93\x89\x9f\x00\xd6\x2e\x8a\x75\x68\x7b\xf0\x00\x29\x4a\x50\xbb\x76\x15\xef\x0b\x60\xc1\x24\xc1\x34\x86\x11\x3c\x7f\x61\xbb\x83\x09\x47\xfc\x84\x6d\xe6\xbd\x00\x5b\xdc\xb3\x17\xb0\xf2\xcc\xf4\x8a\x25\xf6\x7c\x73\xfd\x68\xb3\x69\x51\xeb\x5d\x41\x93\x7e\x37\xd2\x44\x5f\xb3\xd8\xaf\x97\x73\x8c\x75\x84\x5c\x4e\xea\xb7\x86\x4d\x0a\x1f\xdc\xf7\x1f\x12\x2a\x7f\x72\x7d\x30\x3f\x1e\xba\x3e\x74\xd4\x09\xa7\xbb\xd2\x3f\xbc\xc7\xd8\x7a\xc7\x05\x5f\xef\xf8\xb3\x18\x8f\xfa\x05\xe3\x51\x7f\x7f\xc6\xbc\x44\x9a\x17\x50\x0b\xbe\xa7\xd8\x2c\xd2\xbc\x84\xba\x2f\xa3\x45\x9a\x97\x50\xf7\x61\x9c\xa8\x2c\x61\x39\xed\x6f\x3b\xcb\xe0\x79\x39\xcf\xe0\xf9\x13\x02\x8e\x07\x6b\x01\xc7\x83\x7a\x01\xd5\xcd\xa7\xd1\xf9\x3e\x50\x95\x1e\xcc\x09\xd3\x07\x91\x26\x11\xea\xfd\x98\x4f\x48\x84\x0f\x2b\x1b\x5c\x56\x91\x09\x95\xe0\x5d\x4e\xdb\x8a\xcd\xd7\x27\xd9\xdd\x60\x6a\x11\xbb\xa6\x36\xd4\x6a\xd9\x9e\xd3\x6a\xd9\x70\x27\xc1\x39\x8d\xf1\xbe\xdd\x2b\xd3\xb5\xe2\x0c\xde\x61\x8a\x44\xa0\x6e\xd9\xb5\x51\x4d\xe0\x9f\x11\xff\x2a\x85\xaf\xbc\x8d\x45\x70\x41\x2e\x9a\xf7\xbb\xca\x76\x9b\x11\x39\x0b\x14\xb1\xe7\x39\xad\x9a\xcd\xe6\x82\x5c\x54\xf6\xbe\x43\xec\xc5\xbf\xd3\x18\x27\x09\xc5\x78\x17\x5f\x75\x3f\xb4\x97\x2a\x37\x22\x58\x33\x78\x5e\x65\xa3\x50\x09\x73\x73\x14\xfe\xfe\x7b\x03\xbb\x16\xa1\xf7\x8f\xc7\xe9\xee\x97\x9f\x6a\xc9\x36\x67\x59\x1d\x04\xbc\x9f\x63\x24\x31\xde\xcd\xc1\x17\x79\x5a\x73\x0f\xb0\x3d\xb3\x9e\xeb\x03\x4d\x52\x6f\x77\xa4\x6f\x26\xad\xc5\xd4\xcd\xd7\x0c\xd4\x4d\xb5\x57\x4e\xa2\x99\xa6\xbf\x4d\xb3\x33\x47\xd5\xff\xc8\xf4\x7e\x45\x3a\x95\xb3\xda\xfd\xbb\x26\x7a\x2a\x7b\x75\x60\x39\xd7\xa5\xca\xd1\xbe\x61\x74\x54\x53\xfe\xab\xf5\xf4\x05\x20\xca\x85\xb8\x59\x60\x0e\xfa\xfb\x62\xd1\x19\x6f\xeb\xe6\x01\x9b\xf0\x34\xa1\x28\x39\xfa\x3e\x9c\x9c\x34\x16\x7a\xbb\xc0\xfb\xdb\xc0\x4f\x4e\xf6\x05\xae\xf5\x6c\x02\xd7\xfb\xff\x0e\xe8\x05\xe1\x90\xa8\xcc\x78\x3c\x80\x11\x0c\xba\x35\xe8\x4c\xe1\x40\xe2\xd8\xf5\x21\xf1\x61\x07\xd5\x67\x9b\xf3\x71\x15\xcd\x35\xcb\xa0\xeb\x7a\x87\xd0\xbf\x19\x5b\x0b\x76\x8b\x5f\x64\x17\xed\x35\x85\x59\x01\xd2\x52\x0e\x62\x9d\x8d\xf4\x82\x77\x8f\xc5\xfd\x4e\xa1\x5a\xc4\x8f\xe2\x1b\xf4\x6b\x56\xe1\x57\xda\x4a\x48\x42\x23\xac\x2b\xb4\xca\xe8\x7d\x12\x57\xb9\x00\xac\xce\xe1\x08\x4a\xe6\xa0\xa2\xa2\x49\x88\xe7\xeb\xfb\xd5\xaf\x3f\x03\x7d\x01\x84\xb7\xb6\x68\xd6\x28\xf4\xd5\xf0\xe1\x4e\xad\xaa\xa8\x68\x72\xf6\x1a\xe7\xe6\xa6\xa5\x2b\x91\xb6\xe7\x17\x45\x49\x39\xf4\x24\x2c\x51\xa0\x12\x4f\xdb\xa6\xdc\x3f\xb6\xd5\xa9\xde\x43\x6b\x2a\x4a\x15\xe5\xe3\x1d\x85\xf6\x56\xfe\x5b\xe9\xec\xd6\xcc\x30\x1b\x23\xff\x56\xfa\xd4\x12\xfd\x47\x15\xda\x22\x69\x5b\xa9\xb9\x88\x3d\xb4\xd2\xcd\xa5\x73\xb5\xcc\xc6\xfa\x3b\x83\xcd\x95\x4d\x50\x34\xd9\xb7\x85\xb2\x91\x8d\xb6\x01\x98\x63\xee\x3f\x03\x60\x4b\x75\x91\x5d\xbe\x46\xf9\xca\x71\xf4\x15\x87\xbd\x4c\x18\x41\x46\xe6\xef\xcd\x31\xe8\x43\xe5\xfc\x63\x88\x88\x4e\xd8\x23\x73\x2c\x2d\x87\xd6\x29\xa9\x5c\x8b\xdb\x59\x89\x6c\xc5\x95\x16\xa4\x8e\x6b\xe5\x8f\xe2\xcc\xd8\x5d\x6d\x14\x3c\xa4\x5a\x93\x7d\x46\x71\x56\x26\xd1\xed\xfd\x69\x7d\xd1\x51\x60\x31\x33\x7f\x70\xef\xdd\x21\x14\xbf\x97\xee\x10\x06\xfd\xd5\xca\xab\xb9\x97\xb8\x2f\xee\x75\x96\x3b\x57\xd6\x9f\x89\xa5\x6a\xba\x3f\x90\x33\x8d\xa8\xbe\xb4\x58\x94\x88\x35\xa2\xc5\xe3\xe7\x11\x73\xa3\x5e\xb2\x40\x22\xf4\xdd\xd5\x26\x43\xcd\x05\x51\x4e\xa3\x3a\xef\x45\x6a\xf6\x19\xb9\xc5\x76\x34\x23\x54\x1d\x92\xf3\x48\x3e\x28\xe3\x44\x63\x6b\x4c\xcb\x6a\xce\xc1\xb3\x44\x94\xba\x95\x8b\xa7\x02\xde\x7f\x28\x3a\xbc\xea\xb1\x5a\x83\xae\x78\x9b\x4f\xc5\xfb\xee\x87\x7a\xab\xee\x5d\x84\xa8\x25\xd5\x8a\xe0\x65\xa7\x44\xfa\xb0\x5a\x7f\x5a\xa6\x49\xaa\x8f\xc3\xad\x18\x27\xc8\x21\x1a\x57\x4f\xda\xbb\xb5\xa4\x40\x79\x9d\x64\xc8\x72\x75\xdc\x8c\xc6\x3e\x74\xad\x96\x97\x9d\xa8\xa6\x30\x2c\x96\x64\x8d\x11\x49\x9a\x62\xac\x66\xa9\xeb\x80\x03\xd9\x2e\x1a\xf7\x0f\x20\xa5\x00\x57\x7c\x89\x2e\x8d\x35\xe8\x2b\x73\x2a\x9b\x16\xd6\xea\x6f\x5c\x4c\x58\x32\xd5\x6d\xd3\xb4\xd7\x6c\xdc\xb5\x9f\xa3\x71\x49\x7e\x88\xb3\xc1\x77\x16\xfe\xc6\x0a\x28\xef\x2b\x55\xe4\x1b\x82\xcd\x88\x7f\x73\x4f\xb2\x79\x8a\xd6\x6e\xe5\x4a\x8b\xc6\x85\x35\xb5\x8b\xbe\xda\xb6\x93\x4c\x06\xbf\xf1\x84\xca\x94\xb6\xdd\x71\x2e\x25\xa3\x10\xa5\x49\x74\x6b\xf0\xb4\xaa\x36\x82\x30\x04\x6e\x1a\xfa\x89\x4c\x39\x87\x44\x7f\xcb\x01\xcb\x7e\x97\xa4\x69\x71\x19\x6d\x45\x01\x99\x92\x84\xd6\x44\xf9\xce\x5e\x12\xb3\x28\xcf\x50\x7f\x2b\x34\x11\x3e\x45\xf9\x26\x45\xd5\xf5\x6a\x79\xae\x0e\x54\x6e\xb6\x7c\xa5\x15\x95\x24\x24\x8e\xdf\x2c\x90\xca\x5f\x13\x21\x91\x22\x57\x44\x5a\xb1\x5e\x13\xfa\x6a\xc9\x3c\x7f\x31\x2f\x65\x66\x52\xce\xc5\x30\x0c\x63\x5c\x60\xca\xe6\xc8\x83\x8c\x7d\x4a\xd2\x94\x04\x8c\x4f\x43\xa4\x9d\xdf\xaf\xc2\x98\x45\x22\x3c\x4b\x99\x10\x84\x2f\xc3\x6b\x9e\xcb\xd9\x72\x93\x5b\x48\x12\xdd\xb2\x05\xf2\x49\xca\xee\x82\x88\x65\xe1\x5f\xb9\x5a\x51\x8c\x8a\xb0\x77\xf2\xd3\xd1\xc9\xc9\xf3\x7e\x48\xd2\xb4\xa3\xd7\xd3\xb2\xa3\xaf\xf6\x45\x27\xa1\x9d\x1b\xb2\x20\x22\xe2\xc9\x5c\x16\x84\x47\xcf\x8a\x1f\x6b\x1d\xc3\x30\xbc\xbb\xbb\x0b\x30\xca\x48\x47\x3b\x8d\x12\x25\x9c\xa4\x06\xa5\xea\xee\x1f\xf7\xc3\xe7\x41\x2f\x7c\x26\x30\xea\x9c\x04\xfd\x4a\xf1\xad\x01\x3f\xf5\xa2\x63\xc2\x38\x7c\xf4\xe1\x16\xf5\x29\x87\x13\x3a\x45\x78\xff\xc1\xec\xae\x2a\x36\xd6\xaf\x1a\x7c\xa8\x7e\x4c\xb7\x2d\xf3\xe5\xb7\xf2\x51\xc5\x36\x4c\x39\x60\x1b\x3f\x13\x89\xae\xaf\x85\x95\xcf\x63\x5c\x5f\x45\x92\xdb\x75\x55\xe6\x97\xc6\xb6\xad\x96\x3d\x2f\xdb\xbf\x30\x2c\xc3\x4b\x00\xe1\x58\xa1\x2b\x9e\xd2\x28\x15\xeb\x77\x34\xaa\x55\xbc\x90\x51\xbf\x2b\x6f\x67\xb4\xfe\x30\xd4\x2f\xc8\xcc\x16\x5a\x15\xe9\x03\x2e\xb0\x88\xe1\xe5\xbf\x38\xae\x5f\xd3\x00\xe3\x5b\x2f\x67\x02\x05\x60\xfd\xfa\x46\x29\xda\x7a\x6f\xa3\x94\x6d\x6f\x1c\x95\x13\xf6\x2d\x2e\xbd\xc0\xba\xa7\xe6\xc3\x57\x25\xb5\xfc\x20\x86\x50\x97\x5e\x6e\x71\x59\x73\x81\x6a\xdf\x2d\x40\x99\xbf\x1f\xfd\x94\xdd\x0c\xe0\x0b\x4e\x9d\xb5\xb7\xae\x87\x57\x51\xad\xfb\xbf\x91\xfc\xe2\x58\xf8\x0d\x44\x6f\x9c\x72\x0f\x22\x7f\xe5\xfc\x3f\x00\x00\xff\xff\x76\x69\x89\xce\x73\x29\x00\x00"), - }, "/src/syscall/syscall.go": &vfsgen۰CompressedFileInfo{ name: "syscall.go", modTime: time.Date(2019, 3, 5, 14, 33, 26, 82012629, time.UTC), @@ -871,7 +864,6 @@ var FS = func() http.FileSystem { } fs["/src/syscall/js"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ fs["/src/syscall/js/js.go"].(os.FileInfo), - fs["/src/syscall/js/js_test.go"].(os.FileInfo), } fs["/src/testing"].(*vfsgen۰DirInfo).entries = []os.FileInfo{ fs["/src/testing/example.go"].(os.FileInfo), diff --git a/compiler/natives/src/syscall/js/js_test.go b/tests/syscalljs/js_test.go similarity index 99% rename from compiler/natives/src/syscall/js/js_test.go rename to tests/syscalljs/js_test.go index f7e87884b..8ea5e3bd8 100644 --- a/compiler/natives/src/syscall/js/js_test.go +++ b/tests/syscalljs/js_test.go @@ -178,6 +178,8 @@ func testTypedArrayOf(t *testing.T, name string, slice interface{}, want float64 } func TestNaN(t *testing.T) { + t.Skip("NaN cannot be compared") + want := js.ValueOf(math.NaN()) got := dummys.Get("NaN") if got != want { @@ -298,6 +300,8 @@ func TestValueOf(t *testing.T) { } func TestZeroValue(t *testing.T) { + t.Skip("the initial value is nil on GopherJS") + var v js.Value if v != js.Undefined() { t.Error("zero js.Value is not js.Undefined()") From 1ff873a7771ea95fccc6816741226a154a383287 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 26 Apr 2019 00:18:22 +0900 Subject: [PATCH 6/9] Remove unused code --- tool.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tool.go b/tool.go index e3bb7dd79..4c580a139 100644 --- a/tool.go +++ b/tool.go @@ -326,12 +326,9 @@ func main() { var exitErr error for _, pkg := range pkgs { - // syscall/js doesn't have a buildable file originally, but has Go files in compiler/natives. - if pkg.Package.ImportPath != "syscall/js" { - if len(pkg.TestGoFiles) == 0 && len(pkg.XTestGoFiles) == 0 { - fmt.Printf("? \t%s\t[no test files]\n", pkg.ImportPath) - continue - } + if len(pkg.TestGoFiles) == 0 && len(pkg.XTestGoFiles) == 0 { + fmt.Printf("? \t%s\t[no test files]\n", pkg.ImportPath) + continue } s := gbuild.NewSession(options) From 60dbf5afc1bc1fea9024043adcbc4bf229a7e486 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 26 Apr 2019 00:24:40 +0900 Subject: [PATCH 7/9] gofmt --- tests/syscalljs/js_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/syscalljs/js_test.go b/tests/syscalljs/js_test.go index 8ea5e3bd8..c99489e3b 100644 --- a/tests/syscalljs/js_test.go +++ b/tests/syscalljs/js_test.go @@ -301,7 +301,7 @@ func TestValueOf(t *testing.T) { func TestZeroValue(t *testing.T) { t.Skip("the initial value is nil on GopherJS") - + var v js.Value if v != js.Undefined() { t.Error("zero js.Value is not js.Undefined()") From aad5bc4969892ff3f46c6485587054b461612ce7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 26 Apr 2019 01:23:31 +0900 Subject: [PATCH 8/9] Make the zero value js.Undefined --- compiler/gopherjspkg/fs_vfsdata.go | 2 +- compiler/natives/fs_vfsdata.go | 12 ++-- compiler/natives/src/syscall/js/js.go | 80 ++++++++++++++++----------- tests/syscalljs/js_test.go | 2 - 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/compiler/gopherjspkg/fs_vfsdata.go b/compiler/gopherjspkg/fs_vfsdata.go index cbabd2a7d..b21d6e838 100644 --- a/compiler/gopherjspkg/fs_vfsdata.go +++ b/compiler/gopherjspkg/fs_vfsdata.go @@ -21,7 +21,7 @@ var FS = func() http.FileSystem { fs := vfsgen۰FS{ "/": &vfsgen۰DirInfo{ name: "/", - modTime: time.Date(2019, 4, 25, 14, 57, 55, 762548316, time.UTC), + modTime: time.Date(2019, 4, 25, 16, 19, 34, 225618757, time.UTC), }, "/js": &vfsgen۰DirInfo{ name: "js", diff --git a/compiler/natives/fs_vfsdata.go b/compiler/natives/fs_vfsdata.go index 0bf9992a0..ab727bf90 100644 --- a/compiler/natives/fs_vfsdata.go +++ b/compiler/natives/fs_vfsdata.go @@ -131,11 +131,11 @@ var FS = func() http.FileSystem { }, "/src/encoding/gob": &vfsgen۰DirInfo{ name: "gob", - modTime: time.Date(2019, 4, 6, 11, 3, 15, 126398833, time.UTC), + modTime: time.Date(2019, 4, 25, 15, 24, 30, 246543308, time.UTC), }, "/src/encoding/gob/gob_test.go": &vfsgen۰CompressedFileInfo{ name: "gob_test.go", - modTime: time.Date(2019, 4, 6, 11, 3, 15, 126473498, time.UTC), + modTime: time.Date(2019, 4, 25, 15, 24, 30, 246620225, time.UTC), uncompressedSize: 2598, compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x56\x51\x6f\xdb\x3e\x0e\x7f\xb6\x3e\x05\x67\xdc\x0a\xa7\xe7\x39\x95\x93\xae\x9d\x81\x3e\xac\x5b\x77\xd8\x43\x3b\x60\x33\x70\xdb\x8a\x62\x70\x6c\x26\xd1\xea\x48\x3e\x49\x6e\x1a\x04\xf9\xee\x07\x4a\x76\x9c\xae\xff\x0d\x2b\xd0\x56\xa4\x7e\xfc\x91\xa2\x48\xca\xe3\x31\xfc\x7b\xd6\x8a\xba\x82\x9f\x86\xb1\xa6\x28\xef\x8b\x05\xc2\x42\xcd\x18\x13\xab\x46\x69\x0b\x11\x0b\xc2\xd9\xc6\xa2\x09\x59\x10\x6a\x9c\xd7\x58\x5a\x5a\x5a\x34\x56\xc8\x45\xc8\x46\x8c\x8d\xc7\x90\x7f\x7a\xff\x29\x83\x1c\x8d\xbd\x92\x55\xae\xae\x64\x05\xea\x01\xb5\x16\x15\x42\x59\x48\x98\x21\x68\x5c\xa9\x07\xac\x40\xc9\x12\xc1\x2e\x11\x66\xed\x02\xd6\xc2\x2e\xe1\xba\xd0\x1a\xe6\x02\xeb\x0a\x84\x81\xb9\x78\xc4\x2a\x61\xf3\x56\x96\x4f\x08\x23\x0b\xc7\x9d\xd7\x24\x1f\xc1\x96\x05\x76\xd3\x20\xe4\x29\x18\xab\xdb\xd2\x92\x26\xc8\x49\x10\x72\xc1\x82\x5d\xbf\x3f\x39\xdc\xff\x0a\xf3\x5a\x15\xf6\xf5\x94\x05\xc1\x77\x38\x16\xd2\x1e\x20\xf9\x21\xf2\x6d\x0c\x97\x31\xbc\x03\x70\x98\xe0\x1a\xba\x9f\x55\xd1\xdc\x7a\x1f\x77\xc7\x03\xd7\x75\x7a\xb0\x2d\xa4\xbd\xcb\x27\xa4\xf5\xc0\x27\x46\x7d\x7c\xc1\xb5\x90\xb6\xb1\x7a\x30\x39\xee\x3c\x95\x6a\xd5\xf4\x54\xb4\xae\xf1\x91\xa7\xe7\x77\xc3\x92\x40\x94\xb2\x1e\x74\x9b\x76\xac\x77\xb7\xe9\x61\x50\x57\xab\xc6\x6e\xae\x8b\xe6\xd0\xbd\x90\x16\xc6\x63\xb0\x0a\xca\x25\x96\xf7\x60\x97\x85\x85\x35\xdd\x4e\x89\xe2\x01\xa1\x00\xa9\xe4\x2b\x29\x6a\x32\x4a\x58\x10\xdc\xf4\x07\x3f\xbe\x9d\xdc\x0d\xdc\x5f\xac\x36\x9d\x3a\x1d\xce\xf4\x51\xda\xd7\x53\xe3\xb4\xe4\xc9\x21\x3f\x7f\xec\x08\xba\x03\x78\xf3\x9e\x75\x6f\xfa\xad\xd7\xdc\xde\x51\xbd\xb9\xbb\xec\x3d\xe7\xa9\xbb\xa5\x46\x40\x76\x01\x93\x84\x4f\xf9\xe9\x1b\x16\x20\x49\x69\x72\xc6\xcf\x29\x25\x76\xad\xbc\x7c\xc2\x82\x15\x16\x92\xf2\x9e\x5d\xc0\x34\x65\xc1\x5c\xc8\x05\x6a\x43\xe2\x29\x0b\x0c\xa7\x45\xe8\x1d\xf3\x90\x05\x26\x3d\x50\xa4\x21\x0b\x1e\x0a\xed\x82\xe5\x30\xe4\x1c\x2e\x7a\x21\xe2\xc9\x49\x0c\x3c\x39\x19\x0d\xc8\xf4\xaf\x90\x85\xd6\x1c\x0e\xd2\x45\xf2\xed\xc9\x1d\x5c\x80\xe1\x9d\xc4\x9d\x94\xee\xf1\xe9\x2f\xf8\xb4\xc3\xa7\x9d\xc4\x7b\x6b\xc2\xbb\xdb\x79\xdb\x39\x19\xea\x60\xaf\xf6\xb6\x47\x8d\x38\xd4\x39\x86\x23\x7c\xca\x90\xfe\x33\x43\xe7\x9d\xd0\x83\xca\x13\xd8\xb5\x62\x81\x75\xa9\x3d\xca\xb9\x6b\xa0\xac\xbb\x3e\x7e\x16\xb3\x20\xb8\xdc\x8b\xe7\x24\xbe\xeb\xc5\x57\xa7\x24\x5e\x67\xbf\x6f\xaf\x6d\xd8\x88\x30\xa3\xb8\x63\x08\x91\x56\xb8\x73\x36\x69\xf6\x6b\xcf\x6d\xa7\x19\xe4\x93\xed\xd7\x0c\x08\xfc\x3d\x83\xa3\xae\x14\x76\x31\xf0\x93\x7e\x0f\xfd\x56\x57\x16\x3b\x4f\xe6\x9d\x66\xcf\x5b\xb5\x73\x1f\x52\xdd\x85\x5d\x04\x21\x95\x5d\xe8\x0d\x7d\x1b\x67\x4f\xda\x78\xdb\xb9\x1d\xbc\xc4\xd0\x2d\x0e\x63\xea\xbb\x3d\xfb\x53\xb7\x6f\x5d\x29\x66\xbe\xce\x62\xff\xcf\x4b\xdc\x31\xec\xa7\xef\x07\xf1\x08\x76\x29\x0c\x34\x5a\xcd\x6a\x5c\x65\x7e\x33\xc8\x37\x0d\x5e\x69\xad\x74\x06\x95\xb1\xc9\xbf\x0c\x5a\x9a\xb3\x52\x59\x28\x80\xc6\xac\x15\x4a\x76\x58\x4a\x67\x61\x81\xe6\x61\xb5\xc2\x15\x4d\x6c\x88\xc6\x0b\x61\x97\xed\x2c\x29\xd5\x6a\xbc\x50\xcd\x12\xf5\x4f\x33\x2c\xba\x47\x21\x59\xa8\x6c\x7a\x7e\x96\x4d\x46\x8e\x8a\x06\x54\xf6\xe7\x09\xb5\xa5\x8a\xcf\x86\xaa\x8d\x5d\xc1\x0f\x8a\xd4\x1d\xaf\x1f\x62\x94\xe0\x7b\x8c\x9e\x8e\xb2\x11\x21\x6e\xfa\xda\x81\xa3\x61\x44\x6d\x79\x72\x1a\x43\x4a\x7f\x26\xc9\xa9\x63\xa2\x91\x95\x75\xb8\x3e\x9e\xad\xe1\x31\x18\xef\xc9\x0f\xaf\xcc\xed\xfb\xe9\xb5\x3d\x3b\x8b\xe1\xfc\x4d\x0c\x3c\x9d\x4c\xe9\x37\xe5\x93\xa9\xc3\x7e\xfe\x38\x54\x37\xbc\x82\x74\x22\x9c\x87\x7d\x24\xe1\x8d\x5a\x53\x92\xe9\x9d\xb3\x62\x85\x21\x6d\x7f\xcb\x9e\xce\xb8\x28\x5c\x62\x5d\xab\x18\x4c\x21\x6a\xa5\x43\x77\x9a\x7c\x38\x4d\x9e\x6e\x43\x77\xa1\xc2\x40\x9e\xba\x72\xdb\xb1\x60\x46\x3d\x26\x71\x1d\xb9\x67\x39\xb9\x6c\xe7\x73\xd4\x23\x16\xa0\xd6\xb4\x73\x83\xeb\x2b\x59\xaa\x0a\x75\x34\x1b\x25\x7e\x19\x59\x3e\x62\x81\x98\x03\x61\x5e\x5c\x00\x8d\x77\x6a\x51\x9b\xb8\xba\x88\x42\x74\xb0\x2c\x8c\x09\x31\x72\x6e\x68\x1c\xfc\xb0\x1c\x72\xee\xa9\x1d\xf3\x7b\xdc\x33\xfb\x65\x74\xf4\xe3\xb7\xdc\x1f\x0a\x5b\xd4\x51\x58\xe1\x33\x6e\x31\x87\x17\x7d\xd9\xbc\x47\x6c\xae\xfe\xd7\x16\x75\x64\x79\x0c\x8e\xee\x30\xb6\x79\x1f\x1c\xe0\x63\x83\xa5\xc5\x0a\x5e\x3e\xc0\x42\x59\x78\xf9\x10\xc6\x70\x4c\x46\x3e\x84\x1d\xa3\x0a\xbe\x44\x28\x66\x46\xd5\xad\xc5\x7a\x03\xa6\xd5\xfe\x5b\xa3\x7b\xde\x2a\xaa\x46\x5f\xfc\xee\x91\x4b\x5c\x2c\x96\x27\xfb\xa7\xf2\xe2\x59\x76\xe6\x51\xd8\x3d\x87\x60\x50\xda\x70\x7f\x84\x1f\x7f\x6d\xd7\x7b\xf7\xb6\x3b\x36\x7c\xdc\x50\x6f\x7e\x2e\x4a\x7c\xfe\x71\x33\x1e\x83\x3b\xb8\x90\x8b\xf1\x42\xcd\xa0\x6c\xb5\x46\x69\xeb\x0d\xb4\x06\xe9\x00\x66\x23\xcb\x04\x72\xaa\x0f\xb2\xf4\x6a\xa7\xfc\x6f\x21\xec\x7f\xb4\x6a\x1b\x28\x64\xe5\x98\xca\x42\x52\xbb\x9b\xb6\x2c\x11\x2b\x58\x2f\x51\x76\x0c\x94\x8c\xd6\xd0\x07\x57\x60\x93\x2f\xf7\xa2\x89\xc2\xd6\xd0\xdb\xe9\xb7\xc3\x11\xdb\xb1\xff\x07\x00\x00\xff\xff\x9b\x7c\x41\xd0\x26\x0a\x00\x00"), @@ -548,14 +548,14 @@ var FS = func() http.FileSystem { }, "/src/syscall/js": &vfsgen۰DirInfo{ name: "js", - modTime: time.Date(2019, 4, 25, 15, 5, 54, 254191414, time.UTC), + modTime: time.Date(2019, 4, 25, 16, 20, 36, 810751444, time.UTC), }, "/src/syscall/js/js.go": &vfsgen۰CompressedFileInfo{ name: "js.go", - modTime: time.Date(2019, 4, 11, 0, 32, 11, 442253390, time.UTC), - uncompressedSize: 5073, + modTime: time.Date(2019, 4, 25, 16, 20, 36, 810208460, time.UTC), + uncompressedSize: 5659, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x58\x4f\x6f\xdb\xb8\x12\x3f\x4b\x9f\x62\xaa\x43\x41\x35\x82\xf2\xfa\xe7\xe5\x15\x2e\x7c\xe8\x5b\x6c\x8b\x16\xdb\x66\xb1\xe9\xee\x1e\x82\x60\x43\xcb\x94\xc3\x44\xa6\x0c\x89\x52\x6d\x18\xfe\xee\x8b\x19\x52\x14\xa5\xc8\x6e\x80\xdd\x1c\x1c\x7a\xe6\x37\x7f\x38\x1c\xce\x0c\x7d\x7e\x0e\x67\x8b\x46\x16\x4b\xb8\xaf\xc3\x70\xc3\xb3\x07\xbe\x12\xb4\x96\xeb\x4d\x59\x69\x60\x61\x10\x55\x22\x2f\x44\xa6\xa3\x30\x88\x1a\x55\xf3\x5c\x44\x61\x18\x44\x2b\xa9\xef\x9a\x45\x9a\x95\xeb\xf3\x55\xb9\xb9\x13\xd5\x7d\xdd\x2f\xee\xeb\x28\x8c\xc3\x50\xef\x36\x02\xbe\xe1\x87\x54\x3a\x0c\xb3\x52\xd5\xa4\x12\x49\xbf\xab\xa5\xc8\xa5\x12\x4b\x03\x98\x83\x2c\x35\x37\xac\xaf\x4d\x51\x98\xd5\xff\xcb\xb2\x10\x5c\x75\xe4\xf5\x42\x54\x66\x7d\xa5\x2b\xa9\x56\x76\xbd\x5b\x2f\x4a\x2b\x70\xb9\xb8\x17\x99\x36\xeb\x0f\x8d\xca\xb4\x2c\x15\x7a\x92\x37\x2a\x03\xa6\xc9\x56\x0c\x46\x9a\xc5\x50\xd3\x02\xf6\x61\x50\x7f\x97\x3a\xbb\x03\x8d\xeb\x8c\xd7\xc6\x6d\xe7\xe3\x2c\x0c\x82\x4a\xe8\xa6\x52\x10\x35\x1d\x31\xf2\x90\xe8\xb2\x0f\x52\x4d\x51\xf8\x7c\xbb\x11\x1f\xb2\x30\xa4\xa1\x16\xdc\xe1\x50\x0f\x52\x7c\x8c\xf1\xdd\xc7\x98\x4d\x0c\x30\x14\x91\x01\x86\x28\x3e\xc6\x44\xca\xc7\x94\x44\xf1\x31\x5d\x04\x7d\x54\x6e\x69\x51\x18\x2c\x45\xce\x9b\x82\x74\x6c\xb8\x92\x19\x8b\x16\x7c\x09\x78\xe8\x51\x1c\x06\x87\xf0\x60\xe3\xfe\xb1\x28\x17\xbc\x60\x31\xfc\xc1\x8b\x46\x60\x84\xad\x32\xfa\xbe\x6f\x67\x70\x5f\xa7\x06\xd4\x0b\x61\x44\x4f\x89\x28\xe9\x81\xdd\x41\xfd\xc0\x88\xc3\x91\x28\xa5\x27\xee\x11\xf3\xa0\xc9\xe8\xec\x09\xed\xf4\xb2\x9c\xf8\x31\xfc\x26\x0a\xc1\x6b\xc1\x62\xc4\xe4\xa9\xb1\x31\xb7\x4e\x3a\x38\x62\x2f\x73\x96\x2b\xc0\xaf\x4c\xdf\xc9\xda\x98\x4f\x80\x57\xab\x1a\xae\x6f\xe8\x5b\x8c\xd7\x41\x54\x39\xcf\xc4\xfe\x10\x1b\x0f\x7a\x7f\xf1\xeb\x3e\x0c\x8c\x27\x33\xeb\x7e\x18\x04\x81\xd9\xc2\x17\xfe\x40\xe7\xc2\x7a\x13\x2f\xee\xeb\xd4\x1c\xa7\xb3\xd3\x93\x06\xc6\x80\x14\x05\x2d\xa1\x66\x73\x58\xf3\x07\xc1\xac\x57\x09\x14\x42\x31\xe4\xc4\x31\xa1\xf2\xb2\x02\x99\x00\x47\x60\xc5\xd5\x4a\x18\xe5\x46\x85\xd1\x71\x2d\x6f\x60\x6e\x5d\xe4\x07\x62\x98\x4f\xbb\x97\x5c\x31\xc3\x44\x3f\x0f\x09\x90\x10\x69\x3f\xc4\x49\x18\x04\x87\xc4\xe6\x09\x1d\xc5\xcf\x55\x55\x56\xc7\xcf\xc2\x02\x62\xf3\x6f\x70\x7b\xbb\xe4\xfc\xcc\x5b\x7e\x95\x55\x72\xa3\x41\x20\x68\x06\x11\x9c\x81\x48\x3f\x0a\xcd\xa2\xb5\xa8\x6b\xbe\x12\x51\x9c\x76\xf7\xdf\x59\x36\xe7\xd9\x5b\x6e\xbd\x98\x22\xa8\xe5\x15\xd6\x2d\xb9\x84\xfe\xcf\x43\x04\x52\xd5\x9a\xab\x4c\x5c\xe6\x23\xc6\x4a\x68\xd2\x4d\x35\xce\x63\x74\x25\x49\x2a\xa9\x4d\x52\xc9\xbc\xbf\x05\xf0\x6c\x8e\xf9\x4d\xa1\x96\x4b\x98\xf7\x9c\xf4\x27\x5e\x14\x2c\x12\x2d\x2f\xa2\x04\x22\xd6\xdd\x46\xb6\x8d\x61\x0f\x36\x0c\xdb\x77\x70\x88\xf1\x0a\xfa\x7e\x3d\x49\x49\x02\x3b\x5f\x0f\x74\xf2\x65\x0e\x3b\xa7\x74\xb0\xa7\xa3\x6a\x6f\x87\xbe\x85\x00\x32\x07\x86\xd1\x2e\x73\xa4\xcc\xe7\x73\xbf\x96\x1a\x08\x74\xa6\xff\xf3\x0e\xce\xcf\x87\x35\x38\x04\x38\x58\x2d\x5b\x92\xc6\x1a\x3b\x12\x7b\xe9\xc4\xa8\x87\xf4\x12\x23\xbb\x5d\xed\x1d\x89\xbf\x72\xe2\x5d\xe3\x39\xaa\xc1\x16\xe6\x91\x82\xd7\x9e\x7d\x6a\x56\x47\xe5\x6d\xd1\x1e\xc9\xbf\x71\xf2\xb6\xc1\x1d\x97\x37\x05\x7d\x24\xff\xdf\x5e\xde\x34\xc5\xa3\xf2\xae\x8c\x8f\x34\xfc\xcf\x69\x70\xed\xd3\xe8\xb0\xfc\x0b\xc7\xef\x6e\x47\x7c\x3b\x28\xf6\x94\x1a\x97\x39\xdb\x0e\x8b\x9c\xab\xca\xb6\xd1\x6e\xb1\xaa\x6c\x53\x72\x2b\x76\x4d\xd7\xd4\xbc\xbe\xdb\x6c\x2d\x1d\x7d\xf1\xc9\xa6\x00\x7b\x9d\x6a\xf9\xbe\xaa\xf8\xee\x28\x44\x49\xbf\x1b\xda\xaa\x6d\x58\x98\x0a\x09\xfa\x4a\x1f\x6f\xe9\xf3\xe5\x05\xfd\x7b\xfd\x8a\xfe\x5d\xbc\x49\xa0\x21\x40\x63\x10\x8d\x85\x34\x16\xd3\x58\x50\x5e\x94\x9c\x08\xb4\x20\x31\x9a\x97\xd2\x5f\x4b\x8a\x45\x62\x2b\x56\x02\x6b\xbe\xb9\x36\xeb\x1b\x2f\x4a\x09\x5c\xfb\x5f\x3d\x8f\x5d\x0f\x93\xcb\xf4\x93\x6a\xcb\x07\xc1\xb6\xf1\x61\xa2\x03\xdf\x4a\xd5\xf2\x42\x2e\xb1\x54\xcf\xe0\x16\xce\xc0\x4e\x6f\x29\x1d\x19\x9e\xbf\xab\x7e\x83\x63\x63\x2d\xd8\xde\x84\xa9\xcf\x62\x8a\x8b\xad\x4b\x2d\xdd\xf4\xd9\x1c\x5a\xd2\xc2\xe2\x77\x96\xf4\x6c\xee\x5f\x16\x2a\x57\xc6\x8d\xe7\xa4\x8b\xea\xf4\x3e\xa2\x75\x8a\xa0\x28\x31\x82\x07\x32\xdd\x6d\xae\x4d\xdb\xd4\x18\x75\xde\x64\xa5\x6a\x45\xa5\xdf\x57\xab\x9a\xd9\x8e\x36\xc8\xa6\xc1\x57\xb4\xab\xc4\xf7\xf7\xb6\xa7\x0d\x78\xfb\x43\x48\x7d\xec\x2f\xea\x8c\x13\x9d\xac\x45\x5a\x97\xb3\xbc\x5a\x61\x81\xeb\x94\xcd\x81\x6f\x36\x42\x2d\x99\x25\x24\xe8\xea\xc0\x75\xcb\x98\x88\x22\xd5\xc2\xb5\x3b\x70\xb2\x97\xa6\xe9\xf4\x9d\x78\x42\x8c\xcd\x6d\x83\xe7\xcf\x87\xe4\xee\x92\x9e\x8e\x3d\x3a\x33\x8a\xbd\xcc\x61\x53\x95\x9b\xde\x2a\xb6\xc8\x75\xec\x8c\x3b\xe6\x71\x43\xd1\x7d\x6d\xc7\x13\x32\x30\x23\x19\x51\xe9\x1d\x35\xdd\x35\x9c\x41\x04\xb2\x06\x55\x6a\xe0\xd0\xd5\x9b\x04\x56\xa5\x26\x40\x67\x61\x98\x8f\x8f\x32\x1e\xb3\xc3\x04\x33\x79\x94\x16\x71\x9a\xa6\xf1\x54\x0e\x7f\xc0\x0b\xc8\xe2\xee\x22\x3e\x31\xc6\xa6\x66\x9f\x0e\x25\x69\x3e\x9e\xc7\xd6\xf0\x84\x4b\x18\xdf\x8d\xcd\x87\x13\x43\x2a\x2a\x21\xe8\xe4\xbe\x3e\xa9\xa5\xd8\x32\x89\x55\xe9\x07\x3a\x2c\xf2\x88\x16\x8c\x8d\x54\xfa\x5f\x8c\xcb\x27\x75\x22\x2a\x64\x70\xd2\x91\x6e\x3c\x61\xba\xa3\x75\x75\xc7\x8a\xf7\x13\x4c\x57\xf8\xda\x04\x74\x3c\x2e\x18\xbe\x4e\x42\xfd\xe3\x0b\xf7\xb4\x9b\x65\xac\x4d\xef\x7c\x74\x1e\xe4\xd6\x93\x33\xf8\xf3\x15\x2d\x26\xde\x33\xed\x04\xfa\x17\xa1\x56\xfa\xae\x3f\x54\x2f\xf6\x1d\x6b\x42\xea\xab\xf8\xfe\x83\x38\x4d\xed\x04\xa5\x9e\xbc\x8d\x2b\x2f\xeb\x13\x18\xcd\x04\x38\x68\xa7\x6d\x4a\x98\x04\xb6\x53\x2e\x5e\x09\xed\xe5\xfc\x09\x0d\x16\x75\x4c\xcd\xe3\x07\xbf\x17\x22\xff\x39\x30\x12\xfc\x56\x35\xfa\x6e\xc7\x1e\xa5\xe5\x44\xcf\xf2\x84\x28\x9f\xcc\xef\x1a\xbd\x08\x51\xfd\xd9\xd9\x25\x74\x6c\x2e\x48\xff\x1c\xe9\x27\x9a\xa3\xaf\xa1\x1e\x72\x99\xb3\xba\x90\x99\x18\x46\xc6\x53\xd1\x0f\x5d\x06\x37\x9b\x9b\xc5\x78\xf8\xa2\xc6\xf9\xd6\x0e\x21\x38\xdf\xd0\x02\xe7\x99\xeb\x9b\xa6\x63\x35\x8e\xd7\x38\xa6\x9b\x7b\xec\xf2\xe2\x8d\x37\xba\xf4\x8e\xec\x27\xa6\x18\x72\x24\x3e\x4c\x8d\x32\x91\xbf\xc5\x99\x6d\x23\x75\xb3\xd9\x94\x95\x16\x4b\xb3\x85\xe1\xef\x0c\x4c\xc3\x8b\x5e\x68\xf4\x68\xd7\x13\x8f\xf6\xfe\xed\x37\x7e\x7a\x7e\x11\xfa\xae\x5c\xda\x74\x31\x3f\x27\x01\xd0\x5e\xfc\xf7\xe8\x8b\x5e\xf6\xd4\xab\xb4\xde\xd5\x19\x2f\x8a\x73\xec\x97\xb8\x80\x32\xb7\xef\x52\x6b\x06\x3b\x65\xa9\x2c\x6d\xd0\x13\x9d\x97\x7f\x56\x38\x8b\x54\xfd\x21\xa3\x81\x51\x91\x08\x0f\xe1\xdf\x01\x00\x00\xff\xff\x6d\x98\xe3\x82\xd1\x13\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x58\xed\x6f\xdb\xbc\x11\xff\x6c\xfd\x15\x57\x7d\xe8\x23\x35\x9a\xfc\xbc\x74\x59\xe1\xc2\x1f\xba\x61\x2d\x5a\xac\xcd\xb0\x74\xdb\x87\x20\x58\x68\x99\xb2\xe9\xc8\x94\x41\x51\x8a\xbd\xc0\xff\xfb\x70\x47\x8a\xa2\x14\x39\x71\xb1\xa7\x40\x1d\xfa\xf8\xbb\x17\x1e\xef\xcd\x9c\x4e\xe1\x62\x51\x8b\x62\x09\x9b\x2a\x08\x76\x2c\xbb\x67\x2b\x4e\x6b\xb1\xdd\x95\x4a\x43\x14\x4c\x42\xc5\xf3\x82\x67\x3a\x0c\x26\x61\x2d\x2b\x96\xf3\x30\x08\x26\xe1\x4a\xe8\x75\xbd\x48\xb3\x72\x3b\x5d\x95\xbb\x35\x57\x9b\xaa\x5b\x6c\xaa\x30\x88\x83\x40\x1f\x76\x1c\xbe\xe3\x87\x90\x3a\x08\xb2\x52\x56\x24\x12\x49\xff\x94\x4b\x9e\x0b\xc9\x97\x06\x30\x07\x51\x6a\x66\xb6\xbe\xd5\x45\x61\x56\x7f\x2e\xcb\x82\x33\xd9\x92\xb7\x0b\xae\xcc\xfa\x5a\x2b\x21\x57\x76\x7d\xd8\x2e\x4a\xcb\x70\xb5\xd8\xf0\x4c\x9b\xf5\xc7\x5a\x66\x5a\x94\x12\x2d\xc9\x6b\x99\x41\xa4\x49\x57\x0c\x86\x3b\x8a\xa1\xa2\x05\x3c\x06\x93\xea\x41\xe8\x6c\x0d\x1a\xd7\x19\xab\x8c\xd9\xce\xc6\x59\x30\x99\x28\xae\x6b\x25\x21\xac\x5b\x62\xe8\x21\xd1\x64\x1f\x24\xeb\xa2\xf0\xf7\xed\x41\x7c\xc8\xc2\x90\xfa\x52\xf0\x84\x7d\x39\x48\xf1\x31\xc6\x76\x1f\x63\x0e\xd1\xc3\x90\x47\x7a\x18\xa2\xf8\x18\xe3\x29\x1f\x53\x12\xc5\xc7\xb4\x1e\xf4\x51\xb9\xa5\x85\xc1\x64\xc9\x73\x56\x17\x24\x63\xc7\xa4\xc8\xa2\x70\xc1\x96\x80\x97\x1e\xc6\xc1\xe4\x18\x1c\xad\xdf\x3f\x15\xe5\x82\x15\x51\x0c\xff\x62\x45\xcd\xd1\xc3\x56\x98\xd1\xf8\xbd\x24\x7a\xb4\xa9\x52\x83\x8c\x1d\x27\xba\xf5\x45\x3e\x29\x3c\x0e\x77\x65\xe7\xa8\x73\x60\xe2\xa7\x68\xc5\x23\x63\x58\xd4\x19\x85\x02\x41\x9d\xf0\x28\xa7\xfd\x18\xfe\xc1\x0b\xce\x2a\x1e\xc5\x88\xc9\x53\xa3\x68\x6e\xcd\x75\x70\xc4\x5e\xe5\x51\x2e\x01\xbf\x46\x7a\x2d\x2a\x63\x53\x02\x4c\xad\x2a\xb8\xb9\xa5\x6f\x31\x66\x07\x57\x39\xcb\xf8\xe3\x31\x36\x16\x74\x46\xe3\xd7\xc7\x60\x62\x2c\x99\x3d\x3d\xc3\x57\x76\x4f\xf7\x14\x75\x3a\xde\x6c\xaa\xd4\x5c\xaf\x53\xd4\x91\x7a\xda\x50\xcf\x64\xd2\x10\x68\x36\x87\x2d\xbb\xe7\x91\xb5\x2a\x81\x82\xcb\x08\x77\xe2\x18\x41\x79\xa9\x40\x24\xc0\x10\xa7\x98\x5c\x71\x23\x9a\x04\x18\x09\x37\xe2\x16\xe6\x03\x03\x19\xf1\x1e\xf1\xc3\x9e\x27\x97\x51\x1f\x82\x26\xc7\x09\x90\x08\x44\x1f\xe3\x38\xb1\xd1\x43\x37\xf2\x57\xa5\x4a\x75\xfa\x4a\x2c\x20\x36\x7f\x7a\x39\xdd\x86\xec\x17\xd6\xb0\xeb\x4c\x89\x9d\x06\x8e\xa0\x19\x84\x70\x01\x3c\xfd\xc4\x75\x14\x6e\x79\x55\xb1\x15\x0f\xe3\xb4\xad\x0a\x4e\xb3\xb9\xd6\x4e\x73\xe3\x79\x36\x08\x26\xd3\x29\x08\x29\x34\x5f\x82\xe2\x3b\xc5\x2b\x2e\x75\x05\x0f\x6b\xae\xd7\x5c\x59\x5e\x51\x81\x2c\xe5\x1f\xfe\xcb\x55\x09\x0d\x52\x52\xd0\xaa\xe6\x3e\x83\x5e\x73\xb3\x65\xc0\x1a\x7e\x72\x05\xe6\xa7\x34\x98\x58\x0d\x58\x2c\xdc\x99\xfb\xfe\x2b\x17\x1b\xf0\xaf\xd7\x45\xbd\xc8\x11\x09\xf3\x39\xf8\xa1\x4e\x37\x66\x3d\x43\xd0\xc7\x23\x7a\xbb\x4f\x2a\x17\x9b\x84\x2c\xa5\x6b\x68\x98\xc2\xaa\x2d\x96\xd0\xfd\xf3\x3c\x31\x11\xb2\xd2\x4c\x66\xfc\x2a\x1f\x6c\xac\xb8\x26\x79\x54\xe1\xbd\x8d\xb6\x20\xe3\xe1\x4c\x0e\x89\x1c\x5c\xfa\xc3\xab\x39\x48\x51\x90\xa1\x62\x09\xf3\x6e\x27\xfd\x0b\x2b\x8a\x28\xe4\x0d\x2b\xc2\x04\xc2\xa8\xad\x45\xd1\x3e\x86\x47\xb0\x27\xd8\xbf\x87\x63\x8c\x05\xc8\xb7\xeb\x2c\x21\x09\x1c\x7c\x39\xd0\xf2\x97\x39\x1c\x9c\xd0\xde\x99\x4e\x8a\xbd\xeb\xdb\x16\x00\x88\x1c\x22\x8c\xaa\x32\x47\xca\x7c\x3e\xf7\x3b\x89\x81\x40\xab\xfa\xe7\xf7\x30\x9d\xf6\x3b\x50\x00\x70\xb4\x52\xf6\xc4\x8d\x1d\x66\xc0\xf6\x8b\x63\xa3\x0e\xda\x71\x0c\xf4\xb6\x9d\x67\xc0\xfe\xab\x63\x6f\xdb\xee\x49\x09\xb6\x2d\x0d\x04\xfc\xe6\xe9\xa7\x56\x7d\x92\xdf\xb6\xac\x01\xff\x5b\xc7\x6f\xdb\xfb\x69\x7e\xd3\xce\x06\xfc\x7f\xec\xf8\xcd\x48\x70\x92\xdf\x35\xb1\x81\x84\x3f\x39\x09\x6e\x78\x30\x32\xec\xfe\xa5\xdb\xb7\x91\x7c\x8c\xef\x7a\xad\x8e\x42\xe3\x2a\x8f\xf6\xfd\x9a\xee\x72\xd2\x8e\x19\x7b\xac\xa2\xfb\x94\xcc\x8a\xdd\xc8\x61\x4a\x7c\x97\x9e\x7b\x4b\x47\x5b\x7c\xb2\xe9\x37\x5e\x9f\x5e\x7e\x50\x8a\x1d\x4e\x42\xa4\xf0\x67\x01\xdb\xa4\xcc\x16\x86\x42\x82\xb6\xd2\xc7\x3b\xfa\xfc\xe5\x92\xfe\xfc\xf6\x2b\xfd\xb9\x7c\x9b\x40\x4d\x80\xda\x20\x6a\x0b\xa9\x2d\xa6\xb6\xa0\xbc\x28\x19\x11\x68\x41\x6c\x34\x2d\xa6\x7f\x2f\xc9\x17\x89\xad\xcc\x09\x6c\xd9\xee\xc6\xac\x6f\x3d\x2f\x25\x70\xe3\x7f\xf5\x2c\xee\xd7\x3b\xb1\x4c\x3f\xcb\xa6\xbc\xe7\xd1\x1e\x3b\xd3\x93\x21\xe4\x4e\xc8\x86\x15\x62\x89\xfd\x69\x06\x77\x70\x01\x76\x80\x4d\xe9\xde\x30\x08\x5c\xa9\xef\xdd\x5d\xd4\x80\xdf\x8f\x25\x8d\x2c\x5d\xd5\xb2\x65\xea\x55\x93\xda\x9a\xec\x15\x52\xbf\xc0\xfa\xd5\xb4\x49\x9b\x11\xf1\x98\x5e\x51\x4c\xbe\xb7\x42\x1b\xaa\x26\xb3\x39\x34\x64\x64\x14\xbf\xb7\xa4\x57\x73\x3f\x21\x49\xa5\x39\xe5\x6b\x92\x45\x3d\xef\x31\xa4\x75\x8a\xa0\x30\x31\x8c\xc7\xb8\x6f\x46\x77\xa2\xd4\x68\x77\x66\x65\xa5\x6c\xb8\xd2\x1f\xd4\xaa\xa2\x6e\x0f\x69\x9a\xf6\x62\xb7\x77\x2b\x68\x81\xe4\x0f\x1f\xec\xc0\xd0\xdb\xc3\x46\x82\x53\xc2\x7f\x68\xea\x18\x99\x13\x1a\xa4\xb5\x19\xc2\xd4\x0a\xcb\x69\x2b\x6c\x0e\x6c\xb7\xe3\x72\x19\x59\x42\xd2\x33\xba\x77\x1a\x8b\x18\x71\x2c\x95\xe0\xad\x8b\xb3\xd1\xe3\xf8\xed\xf1\x25\xb7\xdb\x8b\x7f\xfd\xba\x4f\x6e\x6b\xc3\xf3\xd7\x81\xc6\x0c\xae\x43\xe4\xb0\x53\xe5\xae\xd3\x8a\x13\xc8\x36\x76\xca\xdd\xe6\x69\x45\xe1\xa6\x9a\x41\xa7\x60\x46\x3c\x5c\xe9\x03\xcd\x34\x5b\xb8\x80\xb0\x1d\x24\x18\xb4\x65\x2e\x81\x55\xa9\x09\xd0\x6a\xe8\x67\xc0\x78\xa2\xf5\xa2\xc6\xb8\x36\x79\x12\x2e\x69\x9a\xc6\xf8\x3f\x1e\xb9\x8e\x8f\x58\x08\xa2\xb8\x2d\x08\x67\x3a\xdd\xf4\x8e\xe7\x7d\x4b\x92\xcf\x88\x75\x6b\xc1\x88\x6d\xe8\xf9\x9d\x8d\x94\x97\x7e\x29\xf4\x44\x12\xe3\xe8\x71\x3f\xcb\x25\xdf\x47\x02\xab\xc7\x0f\x49\xb4\x7c\x27\x64\xa2\x03\x85\xd4\xbf\xa3\xf3\x3e\xcb\x73\x5c\x47\x9a\x47\x2d\x6a\x87\xaa\x48\xb7\xb4\xb6\x92\x59\x39\xdd\xdc\xd5\x56\x6a\x5f\x72\x02\xda\xcf\xec\x61\x3d\xf2\x35\x11\xef\xff\x9d\xc5\xe7\xa5\xab\xd1\x36\xee\x98\x67\x2f\x8f\x8c\xfc\x91\xb4\xf8\x72\x6d\xe4\x3c\x0d\x92\xb1\x66\xf1\x37\x2e\x57\x7a\xdd\x05\xc1\xd8\x5d\xb5\x98\x11\xf6\x6f\xfc\xe1\x05\x0f\xbe\x7c\x46\x94\xf1\x23\x07\xbc\xf6\x72\x2b\x81\xc1\x28\x84\xbf\xa3\x7c\xe1\x04\xee\xd7\x95\x7d\x7c\xf3\xf3\xed\x09\xc1\x5e\x92\x9d\x23\xda\xc2\xcf\x95\xff\xf4\x5d\x68\xcc\xdd\xfe\x0f\xc5\x81\x84\xef\xaa\xd6\xeb\x43\xf4\x24\x25\x9e\xeb\xc0\x1e\x37\x85\xaf\x79\x10\xeb\x78\x89\xea\xff\xec\x18\xcb\x2a\x9b\xb0\xdd\x8f\xd7\x6e\x2e\x3c\xf9\xdb\xb9\x83\x5c\xe5\x51\x55\x88\x8c\xf7\xfd\xe9\x89\xe8\x46\x57\x83\x9b\xcd\xcd\x62\x38\xc2\xd2\x40\xf0\xce\x8e\x72\x38\x25\xd2\x02\xa7\xc2\x9b\xdb\xba\xdd\xaa\xdd\x5e\xed\x36\xdd\xf4\x68\x97\x97\x6f\xbd\x01\xb0\x33\xe4\xf1\xd4\x2c\x48\xd6\xc4\xf1\x71\xec\x55\xca\x3f\xe7\xcc\xb6\xc6\xaa\xde\xed\x4a\x85\x63\x1c\x71\xf6\x1f\xac\x22\x0d\x6f\x3a\xa6\xc1\x73\x8f\x76\xcf\x3d\xed\xcf\xe7\xde\x7b\xc1\xf0\xb9\xe2\x2b\xd7\xeb\x72\x69\x23\xca\x3c\x4c\x02\xd0\x89\xfc\x37\x8c\x37\x1d\xef\x73\x2f\x19\xd5\xa1\xca\x58\x51\x4c\x71\x08\xc0\x05\x94\xb9\x7d\xcb\xb0\x6a\xb0\xfd\x97\xd2\xd2\x7a\x8d\xde\x59\xf9\x6f\x85\x93\x96\xea\xae\x1a\x15\x0c\x6a\x52\x70\x0c\xfe\x17\x00\x00\xff\xff\x77\xd5\xe4\xae\x1b\x16\x00\x00"), }, "/src/syscall/syscall.go": &vfsgen۰CompressedFileInfo{ name: "syscall.go", diff --git a/compiler/natives/src/syscall/js/js.go b/compiler/natives/src/syscall/js/js.go index 4998c4407..81af995b7 100644 --- a/compiler/natives/src/syscall/js/js.go +++ b/compiler/natives/src/syscall/js/js.go @@ -46,15 +46,15 @@ func (t Type) String() string { } func Global() Value { - return Value{v: js.Global} + return objectToValue(js.Global) } func Null() Value { - return Value{v: nil} + return objectToValue(nil) } func Undefined() Value { - return Value{v: js.Undefined} + return objectToValue(js.Undefined) } type Func struct { @@ -67,15 +67,13 @@ func (f Func) Release() { func FuncOf(fn func(this Value, args []Value) interface{}) Func { return Func{ - Value: Value{ - v: js.MakeFunc(func(this *js.Object, args []*js.Object) interface{} { - vargs := make([]Value, len(args)) - for i, a := range args { - vargs[i] = Value{a} - } - return fn(Value{this}, vargs) - }), - }, + Value: objectToValue(js.MakeFunc(func(this *js.Object, args []*js.Object) interface{} { + vargs := make([]Value, len(args)) + for i, a := range args { + vargs[i] = objectToValue(a) + } + return fn(objectToValue(this), vargs) + })), } } @@ -89,6 +87,16 @@ func (e Error) Error() string { type Value struct { v *js.Object + + // inited represents whether Value is non-zero value. true represents the value is not 'undefined'. + inited bool +} + +func objectToValue(obj *js.Object) Value { + if obj == js.Undefined { + return Value{} + } + return Value{obj, true} } var ( @@ -139,24 +147,32 @@ func ValueOf(x interface{}) Value { case nil: return Null() case bool, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, unsafe.Pointer, string, map[string]interface{}, []interface{}: - return Value{v: id.Invoke(x)} + return objectToValue(id.Invoke(x)) default: panic(`invalid arg: ` + reflect.TypeOf(x).String()) } } +func (v Value) internal() *js.Object { + if !v.inited { + return js.Undefined + } + return v.v +} + func (v Value) Bool() bool { if vType := v.Type(); vType != TypeBoolean { panic(&ValueError{"Value.Bool", vType}) } - return v.v.Bool() + return v.internal().Bool() } -func convertArgs(args []interface{}) []interface{} { +// convertArgs converts arguments into values for GopherJS arguments. +func convertArgs(args ...interface{}) []interface{} { newArgs := []interface{}{} for _, arg := range args { v := ValueOf(arg) - newArgs = append(newArgs, v.v) + newArgs = append(newArgs, v.internal()) } return newArgs } @@ -168,40 +184,40 @@ func (v Value) Call(m string, args ...interface{}) Value { if propType := v.Get(m).Type(); propType != TypeFunction { panic("js: Value.Call: property " + m + " is not a function, got " + propType.String()) } - return Value{v: v.v.Call(m, convertArgs(args)...)} + return objectToValue(v.internal().Call(m, convertArgs(args...)...)) } func (v Value) Float() float64 { if vType := v.Type(); vType != TypeNumber { panic(&ValueError{"Value.Float", vType}) } - return v.v.Float() + return v.internal().Float() } func (v Value) Get(p string) Value { - return Value{v: v.v.Get(p)} + return objectToValue(v.internal().Get(p)) } func (v Value) Index(i int) Value { - return Value{v: v.v.Index(i)} + return objectToValue(v.internal().Index(i)) } func (v Value) Int() int { if vType := v.Type(); vType != TypeNumber { panic(&ValueError{"Value.Int", vType}) } - return v.v.Int() + return v.internal().Int() } func (v Value) InstanceOf(t Value) bool { - return instanceOf.Invoke(v, t).Bool() + return instanceOf.Invoke(v.internal(), t.internal()).Bool() } func (v Value) Invoke(args ...interface{}) Value { if vType := v.Type(); vType != TypeFunction { panic(&ValueError{"Value.Invoke", vType}) } - return Value{v: v.v.Invoke(convertArgs(args)...)} + return objectToValue(v.internal().Invoke(convertArgs(args...)...)) } func (v Value) JSValue() Value { @@ -209,31 +225,31 @@ func (v Value) JSValue() Value { } func (v Value) Length() int { - return v.v.Length() + return v.internal().Length() } func (v Value) New(args ...interface{}) Value { - return Value{v: v.v.New(convertArgs(args)...)} + return objectToValue(v.internal().New(convertArgs(args...)...)) } func (v Value) Set(p string, x interface{}) { - v.v.Set(p, x) + v.internal().Set(p, convertArgs(x)[0]) } func (v Value) SetIndex(i int, x interface{}) { - v.v.SetIndex(i, x) + v.internal().SetIndex(i, convertArgs(x)[0]) } func (v Value) String() string { - return v.v.String() + return v.internal().String() } func (v Value) Truthy() bool { - return v.v.Bool() + return v.internal().Bool() } func (v Value) Type() Type { - return Type(getValueType.Invoke(v).Int()) + return Type(getValueType.Invoke(v.internal()).Int()) } type TypedArray struct { @@ -243,14 +259,14 @@ type TypedArray struct { func TypedArrayOf(slice interface{}) TypedArray { switch slice := slice.(type) { case []int8, []int16, []int32, []uint8, []uint16, []uint32, []float32, []float64: - return TypedArray{Value{v: id.Invoke(slice)}} + return TypedArray{objectToValue(id.Invoke(slice))} default: panic("TypedArrayOf: not a supported slice") } } func (t *TypedArray) Release() { - t.Value = Null() + t.Value = Value{} } type ValueError struct { diff --git a/tests/syscalljs/js_test.go b/tests/syscalljs/js_test.go index c99489e3b..34c3cd17c 100644 --- a/tests/syscalljs/js_test.go +++ b/tests/syscalljs/js_test.go @@ -300,8 +300,6 @@ func TestValueOf(t *testing.T) { } func TestZeroValue(t *testing.T) { - t.Skip("the initial value is nil on GopherJS") - var v js.Value if v != js.Undefined() { t.Error("zero js.Value is not js.Undefined()") From 3b76189a1501530523d11fafada5d66b18355c41 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 26 Apr 2019 01:33:26 +0900 Subject: [PATCH 9/9] Add TestMain to suppress deadlock error --- tests/syscalljs/js_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/syscalljs/js_test.go b/tests/syscalljs/js_test.go index 34c3cd17c..5a59d9346 100644 --- a/tests/syscalljs/js_test.go +++ b/tests/syscalljs/js_test.go @@ -1,4 +1,4 @@ -// This file is copied from $GOROOT/src/syscall/js/js_test.go +// This file is basically copied from $GOROOT/src/syscall/js/js_test.go // Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -24,6 +24,14 @@ import ( "testing" ) +func TestMain(m *testing.M) { + // Suppress the 'deadlock' error on GopherJS by goroutine + // (https://github.com/gopherjs/gopherjs/issues/826). + go func() { + m.Run() + }() +} + var dummys = js.Global().Call("eval", `({ someBool: true, someString: "abc\u1234",