js/src/tests/ecma_5/Date/defaultvalue.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommonn.org/licenses/publicdomain/
michael@0 4 */
michael@0 5
michael@0 6 var BUGNUMBER = 645464;
michael@0 7 var summary =
michael@0 8 "[[DefaultValue]] behavior wrong for Date with overridden valueOf/toString";
michael@0 9
michael@0 10 print(BUGNUMBER + ": " + summary);
michael@0 11
michael@0 12 /**************
michael@0 13 * BEGIN TEST *
michael@0 14 **************/
michael@0 15
michael@0 16 function allTests()
michael@0 17 {
michael@0 18 var DS = new Date(2010, 1, 1).toString();
michael@0 19
michael@0 20 // equality
michael@0 21
michael@0 22 var d = new Date(2010, 1, 1);
michael@0 23 assertEq(d == DS, true);
michael@0 24
michael@0 25 var d2 = new Date(2010, 1, 1);
michael@0 26 d2.valueOf = function() { assertEq(arguments.length, 0); return 17; };
michael@0 27 assertEq(d2 == DS, true);
michael@0 28
michael@0 29 var d3 = new Date(2010, 1, 1);
michael@0 30 d3.toString = function() { return 42; };
michael@0 31 assertEq(d3 == 42, true);
michael@0 32
michael@0 33 function testEquality()
michael@0 34 {
michael@0 35 var d = new Date(2010, 1, 1);
michael@0 36 assertEq(d == DS, true);
michael@0 37
michael@0 38 var d2 = new Date(2010, 1, 1);
michael@0 39 d2.valueOf = function() { assertEq(arguments.length, 0); return 17; };
michael@0 40 assertEq(d2 == DS, true);
michael@0 41
michael@0 42 var d3 = new Date(2010, 1, 1);
michael@0 43 d3.toString = function() { return 42; };
michael@0 44 assertEq(d3 == 42, true);
michael@0 45 }
michael@0 46 testEquality();
michael@0 47
michael@0 48
michael@0 49 // addition of Date to number
michael@0 50
michael@0 51 var d = new Date(2010, 1, 1);
michael@0 52 assertEq(d + 5, DS + "5");
michael@0 53
michael@0 54 var d2 = new Date(2010, 1, 1);
michael@0 55 d2.toString = function() { return 9; };
michael@0 56 assertEq(d2 + 3, 9 + 3);
michael@0 57
michael@0 58 var d3 = new Date(2010, 1, 1);
michael@0 59 d3.valueOf = function() { assertEq(arguments.length, 0); return 17; };
michael@0 60 assertEq(d3 + 5, DS + "5");
michael@0 61
michael@0 62 function testDateNumberAddition()
michael@0 63 {
michael@0 64 var d = new Date(2010, 1, 1);
michael@0 65 assertEq(d + 5, DS + "5");
michael@0 66
michael@0 67 var d2 = new Date(2010, 1, 1);
michael@0 68 d2.toString = function() { return 9; };
michael@0 69 assertEq(d2 + 3, 9 + 3);
michael@0 70
michael@0 71 var d3 = new Date(2010, 1, 1);
michael@0 72 d3.valueOf = function() { assertEq(arguments.length, 0); return 17; };
michael@0 73 assertEq(d3 + 5, DS + "5");
michael@0 74 }
michael@0 75 testDateNumberAddition();
michael@0 76
michael@0 77
michael@0 78 // addition of Date to Date
michael@0 79
michael@0 80 var d = new Date(2010, 1, 1);
michael@0 81 assertEq(d + d, DS + DS);
michael@0 82
michael@0 83 var d2 = new Date(2010, 1, 1);
michael@0 84 d2.toString = function() { return 5; };
michael@0 85 assertEq(d2 + d2, 10);
michael@0 86
michael@0 87 var d3 = new Date(2010, 1, 1);
michael@0 88 d3.valueOf = function() { assertEq(arguments.length, 0); return 8.5; };
michael@0 89 assertEq(d3 + d3, DS + DS);
michael@0 90
michael@0 91 function testDateDateAddition()
michael@0 92 {
michael@0 93 var d = new Date(2010, 1, 1);
michael@0 94 assertEq(d + d, DS + DS);
michael@0 95
michael@0 96 var d2 = new Date(2010, 1, 1);
michael@0 97 d2.toString = function() { return 5; };
michael@0 98 assertEq(d2 + d2, 10);
michael@0 99
michael@0 100 var d3 = new Date(2010, 1, 1);
michael@0 101 d3.valueOf = function() { assertEq(arguments.length, 0); return 8.5; };
michael@0 102 assertEq(d3 + d3, DS + DS);
michael@0 103 }
michael@0 104 testDateDateAddition();
michael@0 105
michael@0 106
michael@0 107 // Date as bracketed property name
michael@0 108
michael@0 109 var obj = { 8: 42, 9: 73 };
michael@0 110 obj[DS] = 17;
michael@0 111
michael@0 112 var d = new Date(2010, 1, 1);
michael@0 113 assertEq(obj[d], 17);
michael@0 114
michael@0 115 var d2 = new Date(2010, 1, 1);
michael@0 116 d2.valueOf = function() { assertEq(arguments.length, 0); return 8; }
michael@0 117 assertEq(obj[d2], 17);
michael@0 118
michael@0 119 var d3 = new Date(2010, 1, 1);
michael@0 120 d3.toString = function() { return 9; };
michael@0 121 assertEq(obj[d3], 73);
michael@0 122
michael@0 123 function testPropertyName()
michael@0 124 {
michael@0 125 var obj = { 8: 42, 9: 73 };
michael@0 126 obj[DS] = 17;
michael@0 127
michael@0 128 var d = new Date(2010, 1, 1);
michael@0 129 assertEq(obj[d], 17);
michael@0 130
michael@0 131 var d2 = new Date(2010, 1, 1);
michael@0 132 d2.valueOf = function() { assertEq(arguments.length, 0); return 8; }
michael@0 133 assertEq(obj[d2], 17);
michael@0 134
michael@0 135 var d3 = new Date(2010, 1, 1);
michael@0 136 d3.toString = function() { return 9; };
michael@0 137 assertEq(obj[d3], 73);
michael@0 138 }
michael@0 139 testPropertyName();
michael@0 140
michael@0 141
michael@0 142 // Date as property name with |in| operator
michael@0 143
michael@0 144 var obj = {};
michael@0 145 obj[DS] = 5;
michael@0 146
michael@0 147 var d = new Date(2010, 1, 1);
michael@0 148 assertEq(d in obj, true);
michael@0 149
michael@0 150 var d2 = new Date(2010, 1, 1);
michael@0 151 d2.toString = function() { return "baz"; };
michael@0 152 assertEq(d2 in { baz: 42 }, true);
michael@0 153
michael@0 154 var d3 = new Date(2010, 1, 1);
michael@0 155 d3.valueOf = function() { assertEq(arguments.length, 0); return "quux"; };
michael@0 156 assertEq(d3 in obj, true);
michael@0 157
michael@0 158 function testInOperatorName()
michael@0 159 {
michael@0 160 var obj = {};
michael@0 161 obj[DS] = 5;
michael@0 162
michael@0 163 var d = new Date(2010, 1, 1);
michael@0 164 assertEq(d in obj, true);
michael@0 165
michael@0 166 var d2 = new Date(2010, 1, 1);
michael@0 167 d2.toString = function() { return "baz"; };
michael@0 168 assertEq(d2 in { baz: 42 }, true);
michael@0 169
michael@0 170 var d3 = new Date(2010, 1, 1);
michael@0 171 d3.valueOf = function() { assertEq(arguments.length, 0); return "quux"; };
michael@0 172 assertEq(d3 in obj, true);
michael@0 173 }
michael@0 174 testInOperatorName();
michael@0 175 }
michael@0 176
michael@0 177 allTests();
michael@0 178
michael@0 179 if (typeof newGlobal === "function")
michael@0 180 {
michael@0 181 Date = newGlobal().Date;
michael@0 182 allTests();
michael@0 183 }
michael@0 184
michael@0 185 /******************************************************************************/
michael@0 186
michael@0 187 if (typeof reportCompare === "function")
michael@0 188 reportCompare(true, true);
michael@0 189
michael@0 190 print("All tests passed!");

mercurial