michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: print("Test for correct implementation of |Date == boolean| and vice versa"); michael@0: michael@0: /************** michael@0: * BEGIN TEST * michael@0: **************/ michael@0: michael@0: Date.prototype.toString = function() { return 1; }; michael@0: Date.prototype.valueOf = function() { return 0; }; michael@0: michael@0: /* michael@0: * ES5 11.9.3 doesn't directly handle obj == boolean. Instead it translates it michael@0: * as follows: michael@0: * michael@0: * obj == boolean michael@0: * ↳ obj == ToNumber(boolean), per step 7 michael@0: * ↳ ToPrimitive(obj) == ToNumber(boolean), per step 9 michael@0: * michael@0: * ToPrimitive calls [[DefaultValue]] with no hint. For Date objects this is michael@0: * treated as if it were instead called with hint String. That calls toString, michael@0: * which returns 1, so Date objects here should compare equal to true and michael@0: * unequal to false. michael@0: */ michael@0: assertEq(new Date == true, true); michael@0: assertEq(new Date == false, false); michael@0: michael@0: /* == is symmetric. */ michael@0: assertEq(true == new Date, true); michael@0: assertEq(false == new Date, false); michael@0: michael@0: /******************************************************************************/ michael@0: michael@0: if (typeof reportCompare === "function") michael@0: reportCompare(true, true); michael@0: michael@0: print("Tests complete");