Skip to content

Commit 0bbcb74

Browse files
committed
WIP fixes for internalize and zero val translation of undefined and null
1 parent 3496c6f commit 0bbcb74

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler/prelude/jsmapping.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ var $internalize = function(v, t, recv) {
321321
case $kindSlice:
322322
return new t($mapArray(v, function(e) { return $internalize(e, t.elem); }));
323323
case $kindString:
324+
if (v === undefined || v == null) {
325+
return "";
326+
}
324327
v = String(v);
325328
if (v.search(/^[\x00-\x7F]*$/) !== -1) {
326329
return v;

js/js_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,3 +571,20 @@ func TestUint8Array(t *testing.T) {
571571
t.Errorf("Non-empty byte array is not externalized as a Uint8Array")
572572
}
573573
}
574+
575+
func TestInternalizeZeroVal(t *testing.T) {
576+
type S struct {
577+
*js.Object
578+
579+
string `js:"string"`
580+
}
581+
582+
s := &S{Object: js.Global.Get("Object").New()}
583+
584+
{
585+
exp := ""
586+
if v := s.string; v != exp {
587+
t.Fatalf("expected string field to be %q, got %q", exp, v)
588+
}
589+
}
590+
}

0 commit comments

Comments
 (0)