Skip to content

Commit 96e2b0e

Browse files
flimzyneelance
authored andcommitted
fix externalization of empty typed arrays (fixes #597)
1 parent 9853efb commit 96e2b0e

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

compiler/prelude/prelude.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ var $substring = function(str, low, high) {
119119
};
120120
121121
var $sliceToArray = function(slice) {
122-
if (slice.$length === 0) {
123-
return [];
124-
}
125122
if (slice.$array.constructor !== Array) {
126123
return slice.$array.subarray(slice.$offset, slice.$offset + slice.$length);
127124
}

js/js_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var dummys = js.Global.Call("eval", `({
4343
call: function(f, a) {
4444
f(a);
4545
},
46+
return: function(x) {
47+
return x;
48+
},
4649
})`)
4750

4851
func TestBool(t *testing.T) {
@@ -558,3 +561,13 @@ func TestSurrogatePairs(t *testing.T) {
558561
t.Fail()
559562
}
560563
}
564+
565+
func TestUint8Array(t *testing.T) {
566+
uint8Array := js.Global.Get("Uint8Array")
567+
if dummys.Call("return", []byte{}).Get("constructor") != uint8Array {
568+
t.Errorf("Empty byte array is not externalized as a Uint8Array")
569+
}
570+
if dummys.Call("return", []byte{0x01}).Get("constructor") != uint8Array {
571+
t.Errorf("Non-empty byte array is not externalized as a Uint8Array")
572+
}
573+
}

tests/deferblock_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func outer(ch chan struct{}, b bool) ([]byte, error) {
2626
func TestBlockingInDefer(t *testing.T) {
2727
defer func() {
2828
if x := recover(); x != nil {
29-
t.Error("run time panic: %v", x)
29+
t.Errorf("run time panic: %v", x)
3030
}
3131
}()
3232

0 commit comments

Comments
 (0)