@@ -869,24 +869,28 @@ func TestInternalizeSlice(t *testing.T) {
869
869
}
870
870
871
871
func TestInternalizeArray (t * testing.T ) {
872
+ fn := js .Global .Call ("eval" , "(function(b, v) { b.V = v; })" )
873
+
872
874
tests := []struct {
873
875
name string
874
- init [ 3 ] int
876
+ init any
875
877
want string
876
878
}{
879
+ {
880
+ name : `null array` ,
881
+ init : nil ,
882
+ want : `[3]int{0, 0, 0}` ,
883
+ },
877
884
{
878
885
name : `zeros array` ,
879
886
init : [3 ]int {},
880
887
want : `[3]int{0, 0, 0}` ,
881
888
},
882
- // TODO(grantnelson-wf): The following test doesn't pass because
883
- // the assignment of an externalized array doesn't work when this was written,
884
- // see https://github.com/gopherjs/gopherjs/issues/1302
885
- //{
886
- // name: `non-zero array`,
887
- // init: [3]int{42, 53, 64},
888
- // want: `[3]int{42, 53, 64}`,
889
- //},
889
+ {
890
+ name : `non-zero array` ,
891
+ init : [3 ]int {42 , 53 , 64 },
892
+ want : `[3]int{42, 53, 64}` ,
893
+ },
890
894
}
891
895
892
896
for _ , tt := range tests {
@@ -895,7 +899,11 @@ func TestInternalizeArray(t *testing.T) {
895
899
* js.Object
896
900
V [3 ]int `js:"V"` // V is externalized
897
901
}{Object : js .Global .Get ("Object" ).New ()}
898
- b .V = tt .init
902
+
903
+ // Assign the array to b.V using JS because of GopherJS
904
+ // assignment of externalized array's issue,
905
+ // see https://github.com/gopherjs/gopherjs/issues/1302
906
+ fn .Invoke (b , tt .init )
899
907
900
908
result := fmt .Sprintf (`%#v` , b .V ) // internalize b.V
901
909
if result != tt .want {
0 commit comments