Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | // http://creativecommons.org/licenses/publicdomain/ |
michael@0 | 3 | |
michael@0 | 4 | //----------------------------------------------------------------------------- |
michael@0 | 5 | print("Test for correct short-circuiting implementation of Date.set methods"); |
michael@0 | 6 | |
michael@0 | 7 | /************** |
michael@0 | 8 | * BEGIN TEST * |
michael@0 | 9 | **************/ |
michael@0 | 10 | var global = 0; |
michael@0 | 11 | var date; |
michael@0 | 12 | |
michael@0 | 13 | /* Test that methods don't short circuit argument evaluation. */ |
michael@0 | 14 | date = new Date(0).setSeconds(NaN, {valueOf:function(){global = 3}}); |
michael@0 | 15 | assertEq(global, 3); |
michael@0 | 16 | |
michael@0 | 17 | date = new Date(0).setUTCSeconds(NaN, {valueOf:function(){global = 4}}); |
michael@0 | 18 | assertEq(global, 4); |
michael@0 | 19 | |
michael@0 | 20 | date = new Date(0).setMinutes(NaN, {valueOf:function(){global = 5}}); |
michael@0 | 21 | assertEq(global, 5); |
michael@0 | 22 | |
michael@0 | 23 | date = new Date(0).setUTCMinutes(NaN, {valueOf:function(){global = 6}}); |
michael@0 | 24 | assertEq(global, 6); |
michael@0 | 25 | |
michael@0 | 26 | date = new Date(0).setHours(NaN, {valueOf:function(){global = 7}}); |
michael@0 | 27 | assertEq(global, 7); |
michael@0 | 28 | |
michael@0 | 29 | date = new Date(0).setUTCHours(NaN, {valueOf:function(){global = 8}}); |
michael@0 | 30 | assertEq(global, 8); |
michael@0 | 31 | |
michael@0 | 32 | date = new Date(0).setMonth(NaN, {valueOf:function(){global = 11}}); |
michael@0 | 33 | assertEq(global, 11); |
michael@0 | 34 | |
michael@0 | 35 | date = new Date(0).setUTCMonth(NaN, {valueOf:function(){global = 12}}); |
michael@0 | 36 | assertEq(global, 12); |
michael@0 | 37 | |
michael@0 | 38 | date = new Date(0).setFullYear(NaN, {valueOf:function(){global = 13}}); |
michael@0 | 39 | assertEq(global, 13); |
michael@0 | 40 | |
michael@0 | 41 | date = new Date(0).setUTCFullYear(NaN, {valueOf:function(){global = 14}}); |
michael@0 | 42 | assertEq(global, 14); |
michael@0 | 43 | |
michael@0 | 44 | |
michael@0 | 45 | |
michael@0 | 46 | /* Test that argument evaluation is not short circuited if Date == NaN */ |
michael@0 | 47 | date = new Date(NaN).setMilliseconds({valueOf:function(){global = 15}}); |
michael@0 | 48 | assertEq(global, 15); |
michael@0 | 49 | |
michael@0 | 50 | date = new Date(NaN).setUTCMilliseconds({valueOf:function(){global = 16}}); |
michael@0 | 51 | assertEq(global, 16); |
michael@0 | 52 | |
michael@0 | 53 | date = new Date(NaN).setSeconds({valueOf:function(){global = 17}}); |
michael@0 | 54 | assertEq(global, 17); |
michael@0 | 55 | |
michael@0 | 56 | date = new Date(NaN).setUTCSeconds({valueOf:function(){global = 18}}); |
michael@0 | 57 | assertEq(global, 18); |
michael@0 | 58 | |
michael@0 | 59 | date = new Date(NaN).setMinutes({valueOf:function(){global = 19}}); |
michael@0 | 60 | assertEq(global, 19); |
michael@0 | 61 | |
michael@0 | 62 | date = new Date(NaN).setUTCMinutes({valueOf:function(){global = 20}}); |
michael@0 | 63 | assertEq(global, 20); |
michael@0 | 64 | |
michael@0 | 65 | date = new Date(NaN).setHours({valueOf:function(){global = 21}}); |
michael@0 | 66 | assertEq(global, 21); |
michael@0 | 67 | |
michael@0 | 68 | date = new Date(NaN).setUTCHours({valueOf:function(){global = 22}}); |
michael@0 | 69 | assertEq(global, 22); |
michael@0 | 70 | |
michael@0 | 71 | date = new Date(NaN).setDate({valueOf:function(){global = 23}}); |
michael@0 | 72 | assertEq(global, 23); |
michael@0 | 73 | |
michael@0 | 74 | date = new Date(NaN).setUTCDate({valueOf:function(){global = 24}}); |
michael@0 | 75 | assertEq(global, 24); |
michael@0 | 76 | |
michael@0 | 77 | date = new Date(NaN).setMonth({valueOf:function(){global = 25}}); |
michael@0 | 78 | assertEq(global, 25); |
michael@0 | 79 | |
michael@0 | 80 | date = new Date(NaN).setUTCMonth({valueOf:function(){global = 26}}); |
michael@0 | 81 | assertEq(global, 26); |
michael@0 | 82 | |
michael@0 | 83 | date = new Date(NaN).setFullYear({valueOf:function(){global = 27}}); |
michael@0 | 84 | assertEq(global, 27); |
michael@0 | 85 | |
michael@0 | 86 | date = new Date(NaN).setUTCFullYear({valueOf:function(){global = 28}}); |
michael@0 | 87 | assertEq(global, 28); |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | /* Test the combination of the above two. */ |
michael@0 | 91 | date = new Date(NaN).setSeconds(NaN, {valueOf:function(){global = 31}}); |
michael@0 | 92 | assertEq(global, 31); |
michael@0 | 93 | |
michael@0 | 94 | date = new Date(NaN).setUTCSeconds(NaN, {valueOf:function(){global = 32}}); |
michael@0 | 95 | assertEq(global, 32); |
michael@0 | 96 | |
michael@0 | 97 | date = new Date(NaN).setMinutes(NaN, {valueOf:function(){global = 33}}); |
michael@0 | 98 | assertEq(global, 33); |
michael@0 | 99 | |
michael@0 | 100 | date = new Date(NaN).setUTCMinutes(NaN, {valueOf:function(){global = 34}}); |
michael@0 | 101 | assertEq(global, 34); |
michael@0 | 102 | |
michael@0 | 103 | date = new Date(NaN).setHours(NaN, {valueOf:function(){global = 35}}); |
michael@0 | 104 | assertEq(global, 35); |
michael@0 | 105 | |
michael@0 | 106 | date = new Date(NaN).setUTCHours(NaN, {valueOf:function(){global = 36}}); |
michael@0 | 107 | assertEq(global, 36); |
michael@0 | 108 | |
michael@0 | 109 | date = new Date(NaN).setMonth(NaN, {valueOf:function(){global = 39}}); |
michael@0 | 110 | assertEq(global, 39); |
michael@0 | 111 | |
michael@0 | 112 | date = new Date(NaN).setUTCMonth(NaN, {valueOf:function(){global = 40}}); |
michael@0 | 113 | assertEq(global, 40); |
michael@0 | 114 | |
michael@0 | 115 | date = new Date(NaN).setFullYear(NaN, {valueOf:function(){global = 41}}); |
michael@0 | 116 | assertEq(global, 41); |
michael@0 | 117 | |
michael@0 | 118 | date = new Date(NaN).setUTCFullYear(NaN, {valueOf:function(){global = 42}}); |
michael@0 | 119 | assertEq(global, 42); |
michael@0 | 120 | |
michael@0 | 121 | |
michael@0 | 122 | /*Test two methods evaluation*/ |
michael@0 | 123 | var secondGlobal = 0; |
michael@0 | 124 | |
michael@0 | 125 | date = new Date(NaN).setFullYear({valueOf:function(){global = 43}}, {valueOf:function(){secondGlobal = 1}}); |
michael@0 | 126 | assertEq(global, 43); |
michael@0 | 127 | assertEq(secondGlobal, 1); |
michael@0 | 128 | |
michael@0 | 129 | date = new Date(0).setFullYear(NaN, {valueOf:function(){global = 44}}, {valueOf:function(){secondGlobal = 2}}); |
michael@0 | 130 | assertEq(global, 44); |
michael@0 | 131 | assertEq(secondGlobal, 2); |
michael@0 | 132 | |
michael@0 | 133 | |
michael@0 | 134 | /* Test year methods*/ |
michael@0 | 135 | date = new Date(0).setYear({valueOf:function(){global = 45}}); |
michael@0 | 136 | assertEq(global, 45); |
michael@0 | 137 | |
michael@0 | 138 | date = new Date(NaN).setYear({valueOf:function(){global = 46}}); |
michael@0 | 139 | assertEq(global, 46); |
michael@0 | 140 | |
michael@0 | 141 | |
michael@0 | 142 | /******************************************************************************/ |
michael@0 | 143 | |
michael@0 | 144 | if (typeof reportCompare === "function") |
michael@0 | 145 | reportCompare(true, true); |
michael@0 | 146 | |
michael@0 | 147 | print("Tests complete"); |