js/src/tests/ecma_5/Date/setTime-argument-shortcircuiting.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_5/Date/setTime-argument-shortcircuiting.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +// Any copyright is dedicated to the Public Domain.
     1.5 +// http://creativecommons.org/licenses/publicdomain/
     1.6 +
     1.7 +//-----------------------------------------------------------------------------
     1.8 +print("Test for correct short-circuiting implementation of Date.set methods");
     1.9 +
    1.10 +/**************
    1.11 + * BEGIN TEST *
    1.12 + **************/
    1.13 +var global = 0;
    1.14 +var date;
    1.15 +
    1.16 +/* Test that methods don't short circuit argument evaluation. */
    1.17 +date = new Date(0).setSeconds(NaN, {valueOf:function(){global = 3}});
    1.18 +assertEq(global, 3);
    1.19 +
    1.20 +date = new Date(0).setUTCSeconds(NaN, {valueOf:function(){global = 4}});
    1.21 +assertEq(global, 4);
    1.22 +
    1.23 +date = new Date(0).setMinutes(NaN, {valueOf:function(){global = 5}});
    1.24 +assertEq(global, 5);
    1.25 +
    1.26 +date = new Date(0).setUTCMinutes(NaN, {valueOf:function(){global = 6}});
    1.27 +assertEq(global, 6);
    1.28 +
    1.29 +date = new Date(0).setHours(NaN, {valueOf:function(){global = 7}});
    1.30 +assertEq(global, 7);
    1.31 +
    1.32 +date = new Date(0).setUTCHours(NaN, {valueOf:function(){global = 8}});
    1.33 +assertEq(global, 8);
    1.34 +
    1.35 +date = new Date(0).setMonth(NaN, {valueOf:function(){global = 11}});
    1.36 +assertEq(global, 11);
    1.37 +
    1.38 +date = new Date(0).setUTCMonth(NaN, {valueOf:function(){global = 12}});
    1.39 +assertEq(global, 12);
    1.40 +
    1.41 +date = new Date(0).setFullYear(NaN, {valueOf:function(){global = 13}});
    1.42 +assertEq(global, 13);
    1.43 +
    1.44 +date = new Date(0).setUTCFullYear(NaN, {valueOf:function(){global = 14}});
    1.45 +assertEq(global, 14);
    1.46 +
    1.47 +
    1.48 +
    1.49 +/* Test that argument evaluation is not short circuited if Date == NaN */
    1.50 +date = new Date(NaN).setMilliseconds({valueOf:function(){global = 15}});
    1.51 +assertEq(global, 15);
    1.52 +
    1.53 +date = new Date(NaN).setUTCMilliseconds({valueOf:function(){global = 16}});
    1.54 +assertEq(global, 16);
    1.55 +
    1.56 +date = new Date(NaN).setSeconds({valueOf:function(){global = 17}});
    1.57 +assertEq(global, 17);
    1.58 +
    1.59 +date = new Date(NaN).setUTCSeconds({valueOf:function(){global = 18}});
    1.60 +assertEq(global, 18);
    1.61 +
    1.62 +date = new Date(NaN).setMinutes({valueOf:function(){global = 19}});
    1.63 +assertEq(global, 19);
    1.64 +
    1.65 +date = new Date(NaN).setUTCMinutes({valueOf:function(){global = 20}});
    1.66 +assertEq(global, 20);
    1.67 +
    1.68 +date = new Date(NaN).setHours({valueOf:function(){global = 21}});
    1.69 +assertEq(global, 21);
    1.70 +
    1.71 +date = new Date(NaN).setUTCHours({valueOf:function(){global = 22}});
    1.72 +assertEq(global, 22);
    1.73 +
    1.74 +date = new Date(NaN).setDate({valueOf:function(){global = 23}});
    1.75 +assertEq(global, 23);
    1.76 +
    1.77 +date = new Date(NaN).setUTCDate({valueOf:function(){global = 24}});
    1.78 +assertEq(global, 24);
    1.79 +
    1.80 +date = new Date(NaN).setMonth({valueOf:function(){global = 25}});
    1.81 +assertEq(global, 25);
    1.82 +
    1.83 +date = new Date(NaN).setUTCMonth({valueOf:function(){global = 26}});
    1.84 +assertEq(global, 26);
    1.85 +
    1.86 +date = new Date(NaN).setFullYear({valueOf:function(){global = 27}});
    1.87 +assertEq(global, 27);
    1.88 +
    1.89 +date = new Date(NaN).setUTCFullYear({valueOf:function(){global = 28}});
    1.90 +assertEq(global, 28);
    1.91 +
    1.92 +
    1.93 +/* Test the combination of the above two. */
    1.94 +date = new Date(NaN).setSeconds(NaN, {valueOf:function(){global = 31}});
    1.95 +assertEq(global, 31);
    1.96 +
    1.97 +date = new Date(NaN).setUTCSeconds(NaN, {valueOf:function(){global = 32}});
    1.98 +assertEq(global, 32);
    1.99 +
   1.100 +date = new Date(NaN).setMinutes(NaN, {valueOf:function(){global = 33}});
   1.101 +assertEq(global, 33);
   1.102 +
   1.103 +date = new Date(NaN).setUTCMinutes(NaN, {valueOf:function(){global = 34}});
   1.104 +assertEq(global, 34);
   1.105 +
   1.106 +date = new Date(NaN).setHours(NaN, {valueOf:function(){global = 35}});
   1.107 +assertEq(global, 35);
   1.108 +
   1.109 +date = new Date(NaN).setUTCHours(NaN, {valueOf:function(){global = 36}});
   1.110 +assertEq(global, 36);
   1.111 +
   1.112 +date = new Date(NaN).setMonth(NaN, {valueOf:function(){global = 39}});
   1.113 +assertEq(global, 39);
   1.114 +
   1.115 +date = new Date(NaN).setUTCMonth(NaN, {valueOf:function(){global = 40}});
   1.116 +assertEq(global, 40);
   1.117 +
   1.118 +date = new Date(NaN).setFullYear(NaN, {valueOf:function(){global = 41}});
   1.119 +assertEq(global, 41);
   1.120 +
   1.121 +date = new Date(NaN).setUTCFullYear(NaN, {valueOf:function(){global = 42}});
   1.122 +assertEq(global, 42);
   1.123 +
   1.124 +
   1.125 +/*Test two methods evaluation*/
   1.126 +var secondGlobal = 0;
   1.127 +
   1.128 +date = new Date(NaN).setFullYear({valueOf:function(){global = 43}}, {valueOf:function(){secondGlobal = 1}});
   1.129 +assertEq(global, 43);
   1.130 +assertEq(secondGlobal, 1);
   1.131 +
   1.132 +date = new Date(0).setFullYear(NaN, {valueOf:function(){global = 44}}, {valueOf:function(){secondGlobal = 2}});
   1.133 +assertEq(global, 44);
   1.134 +assertEq(secondGlobal, 2);
   1.135 +
   1.136 +
   1.137 +/* Test year methods*/
   1.138 +date = new Date(0).setYear({valueOf:function(){global = 45}});
   1.139 +assertEq(global, 45);
   1.140 +
   1.141 +date = new Date(NaN).setYear({valueOf:function(){global = 46}});
   1.142 +assertEq(global, 46);
   1.143 +
   1.144 +
   1.145 +/******************************************************************************/
   1.146 +
   1.147 +if (typeof reportCompare === "function")
   1.148 +  reportCompare(true, true);
   1.149 +
   1.150 +print("Tests complete");

mercurial