js/src/tests/ecma/jsref.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 var completed = false;
michael@0 2 var testcases;
michael@0 3 var tc = 0;
michael@0 4
michael@0 5 SECTION = "";
michael@0 6 VERSION = "";
michael@0 7 BUGNUMBER = "";
michael@0 8 TITLE = "";
michael@0 9
michael@0 10 /*
michael@0 11 * constant strings
michael@0 12 */
michael@0 13 var GLOBAL = "[object global]";
michael@0 14 var PASSED = " PASSED!"
michael@0 15 var FAILED = " FAILED! expected: ";
michael@0 16 var DEBUG = false;
michael@0 17
michael@0 18 TZ_DIFF = -8;
michael@0 19
michael@0 20 var TT = "";
michael@0 21 var TT_ = "";
michael@0 22 var BR = "";
michael@0 23 var NBSP = " ";
michael@0 24 var CR = "\n";
michael@0 25 var FONT = "";
michael@0 26 var FONT_ = "";
michael@0 27 var FONT_RED = "";
michael@0 28 var FONT_GREEN = "";
michael@0 29 var B = "";
michael@0 30 var B_ = ""
michael@0 31 var H2 = "";
michael@0 32 var H2_ = "";
michael@0 33 var HR = "";
michael@0 34 var DEBUG = false;
michael@0 35
michael@0 36 var PASSED = " PASSED!"
michael@0 37 var FAILED = " FAILED! expected: ";
michael@0 38
michael@0 39 function test() {
michael@0 40 for ( tc=0; tc < testcases.length; tc++ ) {
michael@0 41 testcases[tc].passed = writeTestCaseResult(
michael@0 42 testcases[tc].expect,
michael@0 43 testcases[tc].actual,
michael@0 44 testcases[tc].description +" = "+
michael@0 45 testcases[tc].actual );
michael@0 46
michael@0 47 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
michael@0 48 }
michael@0 49 stopTest();
michael@0 50 return ( testcases );
michael@0 51 }
michael@0 52 /* wrapper for test cas constructor that doesn't require the SECTION
michael@0 53 * argument.
michael@0 54 */
michael@0 55
michael@0 56 function AddTestCase( description, expect, actual ) {
michael@0 57 testcases[tc++] = new TestCase( SECTION, description, expect, actual );
michael@0 58 }
michael@0 59
michael@0 60 function TestCase( n, d, e, a ) {
michael@0 61 this.name = n;
michael@0 62 this.description = d;
michael@0 63 this.expect = e;
michael@0 64 this.actual = a;
michael@0 65 this.passed = true;
michael@0 66 this.reason = "";
michael@0 67 this.bugnumber = BUGNUMBER;
michael@0 68
michael@0 69 this.passed = getTestCaseResult( this.expect, this.actual );
michael@0 70 if ( DEBUG ) {
michael@0 71 print( "added " + this.description );
michael@0 72 }
michael@0 73 }
michael@0 74
michael@0 75 /*
michael@0 76 * Set up test environment.
michael@0 77 *
michael@0 78 */
michael@0 79 function startTest() {
michael@0 80 if ( version ) {
michael@0 81 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
michael@0 82 if ( VERSION == "ECMA_1" ) {
michael@0 83 version ( "130" );
michael@0 84 }
michael@0 85 if ( VERSION == "JS_1.3" ) {
michael@0 86 version ( "130" );
michael@0 87 }
michael@0 88 if ( VERSION == "JS_1.2" ) {
michael@0 89 version ( "120" );
michael@0 90 }
michael@0 91 if ( VERSION == "JS_1.1" ) {
michael@0 92 version ( "110" );
michael@0 93 }
michael@0 94 // for ecma version 2.0, we will leave the javascript version to
michael@0 95 // the default ( for now ).
michael@0 96 }
michael@0 97
michael@0 98 // print out bugnumber
michael@0 99
michael@0 100 if ( BUGNUMBER ) {
michael@0 101 print ("BUGNUMBER: " + BUGNUMBER );
michael@0 102 }
michael@0 103
michael@0 104 testcases = new Array();
michael@0 105 tc = 0;
michael@0 106 }
michael@0 107
michael@0 108
michael@0 109 function test() {
michael@0 110 for ( tc=0; tc < testcases.length; tc++ ) {
michael@0 111 testcases[tc].passed = writeTestCaseResult(
michael@0 112 testcases[tc].expect,
michael@0 113 testcases[tc].actual,
michael@0 114 testcases[tc].description +" = "+ testcases[tc].actual );
michael@0 115 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
michael@0 116 }
michael@0 117 stopTest();
michael@0 118 return ( testcases );
michael@0 119 }
michael@0 120
michael@0 121
michael@0 122 function getTestCaseResult( expect, actual ) {
michael@0 123 // because ( NaN == NaN ) always returns false, need to do
michael@0 124 // a special compare to see if we got the right result.
michael@0 125 if ( actual != actual ) {
michael@0 126 if ( typeof actual == "object" ) {
michael@0 127 actual = "NaN object";
michael@0 128 } else {
michael@0 129 actual = "NaN number";
michael@0 130 }
michael@0 131 }
michael@0 132 if ( expect != expect ) {
michael@0 133 if ( typeof expect == "object" ) {
michael@0 134 expect = "NaN object";
michael@0 135 } else {
michael@0 136 expect = "NaN number";
michael@0 137 }
michael@0 138 }
michael@0 139
michael@0 140 var passed = ( expect == actual ) ? true : false;
michael@0 141
michael@0 142 // if both objects are numbers
michael@0 143 // need to replace w/ IEEE standard for rounding
michael@0 144 if ( !passed
michael@0 145 && typeof(actual) == "number"
michael@0 146 && typeof(expect) == "number"
michael@0 147 ) {
michael@0 148 if ( Math.abs(actual-expect) < 0.0000001 ) {
michael@0 149 passed = true;
michael@0 150 }
michael@0 151 }
michael@0 152
michael@0 153 // verify type is the same
michael@0 154 if ( typeof(expect) != typeof(actual) ) {
michael@0 155 passed = false;
michael@0 156 }
michael@0 157
michael@0 158 return passed;
michael@0 159 }
michael@0 160 function writeTestCaseResult( expect, actual, string ) {
michael@0 161 var passed = getTestCaseResult( expect, actual );
michael@0 162 writeFormattedResult( expect, actual, string, passed );
michael@0 163 return passed;
michael@0 164 }
michael@0 165 function writeFormattedResult( expect, actual, string, passed ) {
michael@0 166 var s = TT + string ;
michael@0 167
michael@0 168 for ( k = 0;
michael@0 169 k < (60 - string.length >= 0 ? 60 - string.length : 5) ;
michael@0 170 k++ ) {
michael@0 171 }
michael@0 172
michael@0 173 s += B ;
michael@0 174 s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ;
michael@0 175
michael@0 176 print( s + FONT_ + B_ + TT_ );
michael@0 177
michael@0 178 return passed;
michael@0 179 }
michael@0 180
michael@0 181 function writeHeaderToLog( string ) {
michael@0 182 print( H2 + string + H2_ );
michael@0 183 }
michael@0 184 function stopTest()
michael@0 185 {
michael@0 186 var sizeTag = "<#TEST CASES SIZE>";
michael@0 187 var doneTag = "<#TEST CASES DONE>";
michael@0 188 var beginTag = "<#TEST CASE ";
michael@0 189 var endTag = ">";
michael@0 190
michael@0 191 print(sizeTag);
michael@0 192 print(testcases.length);
michael@0 193 for (tc = 0; tc < testcases.length; tc++)
michael@0 194 {
michael@0 195 print(beginTag + 'PASSED' + endTag);
michael@0 196 print(testcases[tc].passed);
michael@0 197 print(beginTag + 'NAME' + endTag);
michael@0 198 print(testcases[tc].name);
michael@0 199 print(beginTag + 'EXPECTED' + endTag);
michael@0 200 print(testcases[tc].expect);
michael@0 201 print(beginTag + 'ACTUAL' + endTag);
michael@0 202 print(testcases[tc].actual);
michael@0 203 print(beginTag + 'DESCRIPTION' + endTag);
michael@0 204 print(testcases[tc].description);
michael@0 205 print(beginTag + 'REASON' + endTag);
michael@0 206 print(( testcases[tc].passed ) ? "" : "wrong value ");
michael@0 207 print(beginTag + 'BUGNUMBER' + endTag);
michael@0 208 print( BUGNUMBER );
michael@0 209 }
michael@0 210 print(doneTag);
michael@0 211 print( HR );
michael@0 212 gc();
michael@0 213 }
michael@0 214 function getFailedCases() {
michael@0 215 for ( var i = 0; i < testcases.length; i++ ) {
michael@0 216 if ( ! testcases[i].passed ) {
michael@0 217 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
michael@0 218 }
michael@0 219 }
michael@0 220 }
michael@0 221 function err( msg, page, line ) {
michael@0 222 testcases[tc].actual = "error";
michael@0 223 testcases[tc].reason = msg;
michael@0 224 writeTestCaseResult( testcases[tc].expect,
michael@0 225 testcases[tc].actual,
michael@0 226 testcases[tc].description +" = "+ testcases[tc].actual +
michael@0 227 ": " + testcases[tc].reason );
michael@0 228 stopTest();
michael@0 229 return true;
michael@0 230 }
michael@0 231
michael@0 232 /**
michael@0 233 * Type Conversion functions used by Type Conversion
michael@0 234 *
michael@0 235 */
michael@0 236
michael@0 237
michael@0 238
michael@0 239 /*
michael@0 240 * Date functions used by tests in Date suite
michael@0 241 *
michael@0 242 */
michael@0 243 var msPerDay = 86400000;
michael@0 244 var HoursPerDay = 24;
michael@0 245 var MinutesPerHour = 60;
michael@0 246 var SecondsPerMinute = 60;
michael@0 247 var msPerSecond = 1000;
michael@0 248 var msPerMinute = 60000; // msPerSecond * SecondsPerMinute
michael@0 249 var msPerHour = 3600000; // msPerMinute * MinutesPerHour
michael@0 250
michael@0 251 var TIME_1970 = 0;
michael@0 252 var TIME_2000 = 946684800000;
michael@0 253 var TIME_1900 = -2208988800000;
michael@0 254
michael@0 255 function Day( t ) {
michael@0 256 return ( Math.floor(t/msPerDay ) );
michael@0 257 }
michael@0 258 function DaysInYear( y ) {
michael@0 259 if ( y % 4 != 0 ) {
michael@0 260 return 365;
michael@0 261 }
michael@0 262 if ( (y % 4 == 0) && (y % 100 != 0) ) {
michael@0 263 return 366;
michael@0 264 }
michael@0 265 if ( (y % 100 == 0) && (y % 400 != 0) ) {
michael@0 266 return 365;
michael@0 267 }
michael@0 268 if ( (y % 400 == 0) ){
michael@0 269 return 366;
michael@0 270 } else {
michael@0 271 return "ERROR: DaysInYear(" + y + ") case not covered";
michael@0 272 }
michael@0 273 }
michael@0 274 function TimeInYear( y ) {
michael@0 275 return ( DaysInYear(y) * msPerDay );
michael@0 276 }
michael@0 277 function DayNumber( t ) {
michael@0 278 return ( Math.floor( t / msPerDay ) );
michael@0 279 }
michael@0 280 function TimeWithinDay( t ) {
michael@0 281 if ( t < 0 ) {
michael@0 282 return ( (t % msPerDay) + msPerDay );
michael@0 283 } else {
michael@0 284 return ( t % msPerDay );
michael@0 285 }
michael@0 286 }
michael@0 287 function YearNumber( t ) {
michael@0 288 }
michael@0 289 function TimeFromYear( y ) {
michael@0 290 return ( msPerDay * DayFromYear(y) );
michael@0 291 }
michael@0 292 function DayFromYear( y ) {
michael@0 293 return ( 365*(y-1970) +
michael@0 294 Math.floor((y-1969)/4) -
michael@0 295 Math.floor((y-1901)/100) +
michael@0 296 Math.floor((y-1601)/400) );
michael@0 297 }
michael@0 298 function InLeapYear( t ) {
michael@0 299 if ( DaysInYear(YearFromTime(t)) == 365 ) {
michael@0 300 return 0;
michael@0 301 }
michael@0 302 if ( DaysInYear(YearFromTime(t)) == 366 ) {
michael@0 303 return 1;
michael@0 304 } else {
michael@0 305 return "ERROR: InLeapYear("+t+") case not covered";
michael@0 306 }
michael@0 307 }
michael@0 308 function YearFromTime( t ) {
michael@0 309 t = Number( t );
michael@0 310 var sign = ( t < 0 ) ? -1 : 1;
michael@0 311 var year = ( sign < 0 ) ? 1969 : 1970;
michael@0 312 for ( var timeToTimeZero = t; ; ) {
michael@0 313 // subtract the current year's time from the time that's left.
michael@0 314 timeToTimeZero -= sign * TimeInYear(year)
michael@0 315
michael@0 316 // if there's less than the current year's worth of time left, then break.
michael@0 317 if ( sign < 0 ) {
michael@0 318 if ( sign * timeToTimeZero <= 0 ) {
michael@0 319 break;
michael@0 320 } else {
michael@0 321 year += sign;
michael@0 322 }
michael@0 323 } else {
michael@0 324 if ( sign * timeToTimeZero < 0 ) {
michael@0 325 break;
michael@0 326 } else {
michael@0 327 year += sign;
michael@0 328 }
michael@0 329 }
michael@0 330 }
michael@0 331 return ( year );
michael@0 332 }
michael@0 333 function MonthFromTime( t ) {
michael@0 334 // i know i could use switch but i'd rather not until it's part of ECMA
michael@0 335 var day = DayWithinYear( t );
michael@0 336 var leap = InLeapYear(t);
michael@0 337
michael@0 338 if ( (0 <= day) && (day < 31) ) {
michael@0 339 return 0;
michael@0 340 }
michael@0 341 if ( (31 <= day) && (day < (59+leap)) ) {
michael@0 342 return 1;
michael@0 343 }
michael@0 344 if ( ((59+leap) <= day) && (day < (90+leap)) ) {
michael@0 345 return 2;
michael@0 346 }
michael@0 347 if ( ((90+leap) <= day) && (day < (120+leap)) ) {
michael@0 348 return 3;
michael@0 349 }
michael@0 350 if ( ((120+leap) <= day) && (day < (151+leap)) ) {
michael@0 351 return 4;
michael@0 352 }
michael@0 353 if ( ((151+leap) <= day) && (day < (181+leap)) ) {
michael@0 354 return 5;
michael@0 355 }
michael@0 356 if ( ((181+leap) <= day) && (day < (212+leap)) ) {
michael@0 357 return 6;
michael@0 358 }
michael@0 359 if ( ((212+leap) <= day) && (day < (243+leap)) ) {
michael@0 360 return 7;
michael@0 361 }
michael@0 362 if ( ((243+leap) <= day) && (day < (273+leap)) ) {
michael@0 363 return 8;
michael@0 364 }
michael@0 365 if ( ((273+leap) <= day) && (day < (304+leap)) ) {
michael@0 366 return 9;
michael@0 367 }
michael@0 368 if ( ((304+leap) <= day) && (day < (334+leap)) ) {
michael@0 369 return 10;
michael@0 370 }
michael@0 371 if ( ((334+leap) <= day) && (day < (365+leap)) ) {
michael@0 372 return 11;
michael@0 373 } else {
michael@0 374 return "ERROR: MonthFromTime("+t+") not known";
michael@0 375 }
michael@0 376 }
michael@0 377 function DayWithinYear( t ) {
michael@0 378 return( Day(t) - DayFromYear(YearFromTime(t)));
michael@0 379 }
michael@0 380 function DateFromTime( t ) {
michael@0 381 var day = DayWithinYear(t);
michael@0 382 var month = MonthFromTime(t);
michael@0 383
michael@0 384 if ( month == 0 ) {
michael@0 385 return ( day + 1 );
michael@0 386 }
michael@0 387 if ( month == 1 ) {
michael@0 388 return ( day - 30 );
michael@0 389 }
michael@0 390 if ( month == 2 ) {
michael@0 391 return ( day - 58 - InLeapYear(t) );
michael@0 392 }
michael@0 393 if ( month == 3 ) {
michael@0 394 return ( day - 89 - InLeapYear(t));
michael@0 395 }
michael@0 396 if ( month == 4 ) {
michael@0 397 return ( day - 119 - InLeapYear(t));
michael@0 398 }
michael@0 399 if ( month == 5 ) {
michael@0 400 return ( day - 150- InLeapYear(t));
michael@0 401 }
michael@0 402 if ( month == 6 ) {
michael@0 403 return ( day - 180- InLeapYear(t));
michael@0 404 }
michael@0 405 if ( month == 7 ) {
michael@0 406 return ( day - 211- InLeapYear(t));
michael@0 407 }
michael@0 408 if ( month == 8 ) {
michael@0 409 return ( day - 242- InLeapYear(t));
michael@0 410 }
michael@0 411 if ( month == 9 ) {
michael@0 412 return ( day - 272- InLeapYear(t));
michael@0 413 }
michael@0 414 if ( month == 10 ) {
michael@0 415 return ( day - 303- InLeapYear(t));
michael@0 416 }
michael@0 417 if ( month == 11 ) {
michael@0 418 return ( day - 333- InLeapYear(t));
michael@0 419 }
michael@0 420
michael@0 421 return ("ERROR: DateFromTime("+t+") not known" );
michael@0 422 }
michael@0 423 function WeekDay( t ) {
michael@0 424 var weekday = (Day(t)+4) % 7;
michael@0 425 return( weekday < 0 ? 7 + weekday : weekday );
michael@0 426 }
michael@0 427
michael@0 428 // missing daylight savins time adjustment
michael@0 429
michael@0 430 function HourFromTime( t ) {
michael@0 431 var h = Math.floor( t / msPerHour ) % HoursPerDay;
michael@0 432 return ( (h<0) ? HoursPerDay + h : h );
michael@0 433 }
michael@0 434 function MinFromTime( t ) {
michael@0 435 var min = Math.floor( t / msPerMinute ) % MinutesPerHour;
michael@0 436 return( ( min < 0 ) ? MinutesPerHour + min : min );
michael@0 437 }
michael@0 438 function SecFromTime( t ) {
michael@0 439 var sec = Math.floor( t / msPerSecond ) % SecondsPerMinute;
michael@0 440 return ( (sec < 0 ) ? SecondsPerMinute + sec : sec );
michael@0 441 }
michael@0 442 function msFromTime( t ) {
michael@0 443 var ms = t % msPerSecond;
michael@0 444 return ( (ms < 0 ) ? msPerSecond + ms : ms );
michael@0 445 }
michael@0 446 function LocalTZA() {
michael@0 447 return ( TZ_DIFF * msPerHour );
michael@0 448 }
michael@0 449 function UTC( t ) {
michael@0 450 return ( t - LocalTZA() - DaylightSavingTA(t - LocalTZA()) );
michael@0 451 }
michael@0 452 function DaylightSavingTA( t ) {
michael@0 453 t = t - LocalTZA();
michael@0 454
michael@0 455 var dst_start = GetFirstSundayInApril(t) + 2*msPerHour;
michael@0 456 var dst_end = GetLastSundayInOctober(t)+ 2*msPerHour;
michael@0 457
michael@0 458 if ( t >= dst_start && t < dst_end ) {
michael@0 459 return msPerHour;
michael@0 460 } else {
michael@0 461 return 0;
michael@0 462 }
michael@0 463
michael@0 464 // Daylight Savings Time starts on the first Sunday in April at 2:00AM in
michael@0 465 // PST. Other time zones will need to override this function.
michael@0 466
michael@0 467 print( new Date( UTC(dst_start + LocalTZA())) );
michael@0 468
michael@0 469 return UTC(dst_start + LocalTZA());
michael@0 470 }
michael@0 471 function GetFirstSundayInApril( t ) {
michael@0 472 var year = YearFromTime(t);
michael@0 473 var leap = InLeapYear(t);
michael@0 474
michael@0 475 var april = TimeFromYear(year) + TimeInMonth(0, leap) + TimeInMonth(1,leap) +
michael@0 476 TimeInMonth(2,leap);
michael@0 477
michael@0 478 for ( var first_sunday = april; WeekDay(first_sunday) > 0;
michael@0 479 first_sunday += msPerDay )
michael@0 480 {
michael@0 481 ;
michael@0 482 }
michael@0 483
michael@0 484 return first_sunday;
michael@0 485 }
michael@0 486 function GetLastSundayInOctober( t ) {
michael@0 487 var year = YearFromTime(t);
michael@0 488 var leap = InLeapYear(t);
michael@0 489
michael@0 490 for ( var oct = TimeFromYear(year), m = 0; m < 9; m++ ) {
michael@0 491 oct += TimeInMonth(m, leap);
michael@0 492 }
michael@0 493 for ( var last_sunday = oct + 30*msPerDay; WeekDay(last_sunday) > 0;
michael@0 494 last_sunday -= msPerDay )
michael@0 495 {
michael@0 496 ;
michael@0 497 }
michael@0 498 return last_sunday;
michael@0 499 }
michael@0 500 function LocalTime( t ) {
michael@0 501 return ( t + LocalTZA() + DaylightSavingTA(t) );
michael@0 502 }
michael@0 503 function MakeTime( hour, min, sec, ms ) {
michael@0 504 if ( isNaN( hour ) || isNaN( min ) || isNaN( sec ) || isNaN( ms ) ) {
michael@0 505 return Number.NaN;
michael@0 506 }
michael@0 507
michael@0 508 hour = ToInteger(hour);
michael@0 509 min = ToInteger( min);
michael@0 510 sec = ToInteger( sec);
michael@0 511 ms = ToInteger( ms );
michael@0 512
michael@0 513 return( (hour*msPerHour) + (min*msPerMinute) +
michael@0 514 (sec*msPerSecond) + ms );
michael@0 515 }
michael@0 516 function MakeDay( year, month, date ) {
michael@0 517 if ( isNaN(year) || isNaN(month) || isNaN(date) ) {
michael@0 518 return Number.NaN;
michael@0 519 }
michael@0 520 year = ToInteger(year);
michael@0 521 month = ToInteger(month);
michael@0 522 date = ToInteger(date );
michael@0 523
michael@0 524 var sign = ( year < 1970 ) ? -1 : 1;
michael@0 525 var t = ( year < 1970 ) ? 1 : 0;
michael@0 526 var y = ( year < 1970 ) ? 1969 : 1970;
michael@0 527
michael@0 528 var result5 = year + Math.floor( month/12 );
michael@0 529 var result6 = month % 12;
michael@0 530
michael@0 531 if ( year < 1970 ) {
michael@0 532 for ( y = 1969; y >= year; y += sign ) {
michael@0 533 t += sign * TimeInYear(y);
michael@0 534 }
michael@0 535 } else {
michael@0 536 for ( y = 1970 ; y < year; y += sign ) {
michael@0 537 t += sign * TimeInYear(y);
michael@0 538 }
michael@0 539 }
michael@0 540
michael@0 541 var leap = InLeapYear( t );
michael@0 542
michael@0 543 for ( var m = 0; m < month; m++ ) {
michael@0 544 t += TimeInMonth( m, leap );
michael@0 545 }
michael@0 546
michael@0 547 if ( YearFromTime(t) != result5 ) {
michael@0 548 return Number.NaN;
michael@0 549 }
michael@0 550 if ( MonthFromTime(t) != result6 ) {
michael@0 551 return Number.NaN;
michael@0 552 }
michael@0 553 if ( DateFromTime(t) != 1 ) {
michael@0 554 return Number.NaN;
michael@0 555 }
michael@0 556
michael@0 557 return ( (Day(t)) + date - 1 );
michael@0 558 }
michael@0 559 function TimeInMonth( month, leap ) {
michael@0 560 // september april june november
michael@0 561 // jan 0 feb 1 mar 2 apr 3 may 4 june 5 jul 6
michael@0 562 // aug 7 sep 8 oct 9 nov 10 dec 11
michael@0 563
michael@0 564 if ( month == 3 || month == 5 || month == 8 || month == 10 ) {
michael@0 565 return ( 30*msPerDay );
michael@0 566 }
michael@0 567
michael@0 568 // all the rest
michael@0 569 if ( month == 0 || month == 2 || month == 4 || month == 6 ||
michael@0 570 month == 7 || month == 9 || month == 11 ) {
michael@0 571 return ( 31*msPerDay );
michael@0 572 }
michael@0 573
michael@0 574 // save february
michael@0 575 return ( (leap == 0) ? 28*msPerDay : 29*msPerDay );
michael@0 576 }
michael@0 577 function MakeDate( day, time ) {
michael@0 578 if ( day == Number.POSITIVE_INFINITY ||
michael@0 579 day == Number.NEGATIVE_INFINITY ||
michael@0 580 day == Number.NaN ) {
michael@0 581 return Number.NaN;
michael@0 582 }
michael@0 583 if ( time == Number.POSITIVE_INFINITY ||
michael@0 584 time == Number.POSITIVE_INFINITY ||
michael@0 585 day == Number.NaN) {
michael@0 586 return Number.NaN;
michael@0 587 }
michael@0 588 return ( day * msPerDay ) + time;
michael@0 589 }
michael@0 590 function TimeClip( t ) {
michael@0 591 if ( isNaN( t ) ) {
michael@0 592 return ( Number.NaN );
michael@0 593 }
michael@0 594 if ( Math.abs( t ) > 8.64e15 ) {
michael@0 595 return ( Number.NaN );
michael@0 596 }
michael@0 597
michael@0 598 return ( ToInteger( t ) );
michael@0 599 }
michael@0 600 function ToInteger( t ) {
michael@0 601 t = Number( t );
michael@0 602
michael@0 603 if ( isNaN( t ) ){
michael@0 604 return ( Number.NaN );
michael@0 605 }
michael@0 606 if ( t == 0 || t == -0 ||
michael@0 607 t == Number.POSITIVE_INFINITY || t == Number.NEGATIVE_INFINITY ) {
michael@0 608 return 0;
michael@0 609 }
michael@0 610
michael@0 611 var sign = ( t < 0 ) ? -1 : 1;
michael@0 612
michael@0 613 return ( sign * Math.floor( Math.abs( t ) ) );
michael@0 614 }
michael@0 615 function Enumerate ( o ) {
michael@0 616 var properties = new Array();
michael@0 617 for ( p in o ) {
michael@0 618 properties[ properties.length ] = new Array( p, o[p] );
michael@0 619 }
michael@0 620 return properties;
michael@0 621 }
michael@0 622 function AddTestCase( description, expect, actual ) {
michael@0 623 testcases[tc++] = new TestCase( SECTION, description, expect, actual );
michael@0 624 }
michael@0 625
michael@0 626 function getFailedCases() {
michael@0 627 for ( var i = 0; i < testcases.length; i++ ) {
michael@0 628 if ( ! testcases[i].passed ) {
michael@0 629 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
michael@0 630 }
michael@0 631 }
michael@0 632 }

mercurial