diff --git a/compiler/prelude/prelude.go b/compiler/prelude/prelude.go index 9b1c4a6e2..8ee4ea5bf 100644 --- a/compiler/prelude/prelude.go +++ b/compiler/prelude/prelude.go @@ -119,9 +119,6 @@ var $substring = function(str, low, high) { }; var $sliceToArray = function(slice) { - if (slice.$length === 0) { - return []; - } if (slice.$array.constructor !== Array) { return slice.$array.subarray(slice.$offset, slice.$offset + slice.$length); } diff --git a/js/js_test.go b/js/js_test.go index 798d73e50..f96cac143 100644 --- a/js/js_test.go +++ b/js/js_test.go @@ -43,6 +43,9 @@ var dummys = js.Global.Call("eval", `({ call: function(f, a) { f(a); }, + return: function(x) { + return x; + }, })`) func TestBool(t *testing.T) { @@ -558,3 +561,13 @@ func TestSurrogatePairs(t *testing.T) { t.Fail() } } + +func TestUint8Array(t *testing.T) { + uint8Array := js.Global.Get("Uint8Array") + if dummys.Call("return", []byte{}).Get("constructor") != uint8Array { + t.Errorf("Empty byte array is not externalized as a Uint8Array") + } + if dummys.Call("return", []byte{0x01}).Get("constructor") != uint8Array { + t.Errorf("Non-empty byte array is not externalized as a Uint8Array") + } +} diff --git a/tests/deferblock_test.go b/tests/deferblock_test.go index 8aa3f72d9..89fe0c9c6 100644 --- a/tests/deferblock_test.go +++ b/tests/deferblock_test.go @@ -26,7 +26,7 @@ func outer(ch chan struct{}, b bool) ([]byte, error) { func TestBlockingInDefer(t *testing.T) { defer func() { if x := recover(); x != nil { - t.Error("run time panic: %v", x) + t.Errorf("run time panic: %v", x) } }()