Skip to content

Commit cb553f3

Browse files
committed
Fix interface equality for undefined (js.Undefined).
Catch and handle the case of both values being js.Undefined in $interfaceIsEqual. Place this check underneath the check for (a.constructor !== b.constructor) as an optimization. Related to #237.
1 parent 8839012 commit cb553f3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

compiler/prelude/prelude.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ var $interfaceIsEqual = function(a, b) {
413413
if (a.constructor !== b.constructor) {
414414
return false;
415415
}
416+
if (a.constructor === $jsObjectPtr && a.object === undefined &&
417+
b.constructor === $jsObjectPtr && b.object === undefined) {
418+
return true;
419+
}
416420
if (!a.constructor.comparable) {
417421
$throwRuntimeError("comparing uncomparable type " + a.constructor.string);
418422
}

js/js_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ func TestEquality(t *testing.T) {
302302
}
303303
}
304304

305+
func TestUndefinedEquality(t *testing.T) {
306+
var ui interface{} = js.Undefined
307+
if ui != js.Undefined {
308+
t.Fail()
309+
}
310+
}
311+
305312
func TestSameFuncWrapper(t *testing.T) {
306313
a := func(_ string) {} // string argument to force wrapping
307314
b := func(_ string) {} // string argument to force wrapping

0 commit comments

Comments
 (0)