|
1 // Any copyright is dedicated to the Public Domain. |
|
2 // http://creativecommons.org/licenses/publicdomain/ |
|
3 |
|
4 //----------------------------------------------------------------------------- |
|
5 print("Test for correct implementation of |Date == boolean| and vice versa"); |
|
6 |
|
7 /************** |
|
8 * BEGIN TEST * |
|
9 **************/ |
|
10 |
|
11 Date.prototype.toString = function() { return 1; }; |
|
12 Date.prototype.valueOf = function() { return 0; }; |
|
13 |
|
14 /* |
|
15 * ES5 11.9.3 doesn't directly handle obj == boolean. Instead it translates it |
|
16 * as follows: |
|
17 * |
|
18 * obj == boolean |
|
19 * ↳ obj == ToNumber(boolean), per step 7 |
|
20 * ↳ ToPrimitive(obj) == ToNumber(boolean), per step 9 |
|
21 * |
|
22 * ToPrimitive calls [[DefaultValue]] with no hint. For Date objects this is |
|
23 * treated as if it were instead called with hint String. That calls toString, |
|
24 * which returns 1, so Date objects here should compare equal to true and |
|
25 * unequal to false. |
|
26 */ |
|
27 assertEq(new Date == true, true); |
|
28 assertEq(new Date == false, false); |
|
29 |
|
30 /* == is symmetric. */ |
|
31 assertEq(true == new Date, true); |
|
32 assertEq(false == new Date, false); |
|
33 |
|
34 /******************************************************************************/ |
|
35 |
|
36 if (typeof reportCompare === "function") |
|
37 reportCompare(true, true); |
|
38 |
|
39 print("Tests complete"); |