Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: src/date-delay.js

Issue 149247: Fix issue 397 and issue 399. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/runtime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 420
421 421
422 // ECMA 262 - 15.9.1.14 422 // ECMA 262 - 15.9.1.14
423 function TimeClip(time) { 423 function TimeClip(time) {
424 if (!$isFinite(time)) return $NaN; 424 if (!$isFinite(time)) return $NaN;
425 if ($abs(time) > 8.64E15) return $NaN; 425 if ($abs(time) > 8.64E15) return $NaN;
426 return TO_INTEGER(time); 426 return TO_INTEGER(time);
427 } 427 }
428 428
429 429
430 // The Date cache is used to limit the cost of parsing the same Date
431 // strings over and over again.
432 var Date_cache = {
433 // Cached time value.
434 time: $NaN,
435 // Cached year. Only valid when the time matches cached time.
bak 2009/07/07 11:54:02 Year when interpreting time as a local time.
436 year: $NaN,
437 // String input for which the cached time is valid.
438 string: null
439 };
440
441
430 %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) { 442 %SetCode($Date, function(year, month, date, hours, minutes, seconds, ms) {
431 if (!%_IsConstructCall()) { 443 if (!%_IsConstructCall()) {
432 // ECMA 262 - 15.9.2 444 // ECMA 262 - 15.9.2
433 return (new $Date()).toString(); 445 return (new $Date()).toString();
434 } 446 }
435 447
436 // ECMA 262 - 15.9.3 448 // ECMA 262 - 15.9.3
437 var argc = %_ArgumentsLength(); 449 var argc = %_ArgumentsLength();
438 var value; 450 var value;
439 if (argc == 0) { 451 if (argc == 0) {
440 value = %DateCurrentTime(); 452 value = %DateCurrentTime();
441 453
442 } else if (argc == 1) { 454 } else if (argc == 1) {
443 if (IS_NUMBER(year)) { 455 if (IS_NUMBER(year)) {
444 value = TimeClip(year); 456 value = TimeClip(year);
457
458 } else if (IS_STRING(year)) {
459 // Probe the Date cache. If we already have a time value for the
460 // given time, we re-use that instead of parsing the string again.
461 var cache = Date_cache;
462 if (cache.string === year) {
463 value = cache.time;
464 } else {
465 value = DateParse(year);
466 cache.time = value;
467 cache.year = YearFromTime(LocalTimeNoCheck(value));
468 cache.string = year;
469 }
470
445 } else { 471 } else {
446 // According to ECMA 262, no hint should be given for this 472 // According to ECMA 262, no hint should be given for this
447 // conversion. However, ToPrimitive defaults to STRING_HINT for 473 // conversion. However, ToPrimitive defaults to STRING_HINT for
448 // Date objects which will lose precision when the Date 474 // Date objects which will lose precision when the Date
449 // constructor is called with another Date object as its 475 // constructor is called with another Date object as its
450 // argument. We therefore use NUMBER_HINT for the conversion, 476 // argument. We therefore use NUMBER_HINT for the conversion,
451 // which is the default for everything else than Date objects. 477 // which is the default for everything else than Date objects.
452 // This makes us behave like KJS and SpiderMonkey. 478 // This makes us behave like KJS and SpiderMonkey.
453 var time = ToPrimitive(year, NUMBER_HINT); 479 var time = ToPrimitive(year, NUMBER_HINT);
454 value = IS_STRING(time) ? DateParse(time) : TimeClip(ToNumber(time)); 480 value = IS_STRING(time) ? DateParse(time) : TimeClip(ToNumber(time));
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 function GetUTCHoursFrom(aDate) { 556 function GetUTCHoursFrom(aDate) {
531 var t = DATE_VALUE(aDate); 557 var t = DATE_VALUE(aDate);
532 if (NUMBER_IS_NAN(t)) return t; 558 if (NUMBER_IS_NAN(t)) return t;
533 return HourFromTime(t); 559 return HourFromTime(t);
534 } 560 }
535 561
536 562
537 function GetFullYearFrom(aDate) { 563 function GetFullYearFrom(aDate) {
538 var t = DATE_VALUE(aDate); 564 var t = DATE_VALUE(aDate);
539 if (NUMBER_IS_NAN(t)) return t; 565 if (NUMBER_IS_NAN(t)) return t;
540 // Ignore the DST offset for year computations. 566 var cache = Date_cache;
541 return YearFromTime(t + local_time_offset); 567 if (cache.time === t) return cache.year;
568 return YearFromTime(LocalTimeNoCheck(t));
542 } 569 }
543 570
544 571
545 function GetUTCFullYearFrom(aDate) { 572 function GetUTCFullYearFrom(aDate) {
546 var t = DATE_VALUE(aDate); 573 var t = DATE_VALUE(aDate);
547 if (NUMBER_IS_NAN(t)) return t; 574 if (NUMBER_IS_NAN(t)) return t;
548 return YearFromTime(t); 575 return YearFromTime(t);
549 } 576 }
550 577
551 578
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 return gmt + ' (' + LocalTimezone(time) + ')'; 654 return gmt + ' (' + LocalTimezone(time) + ')';
628 } 655 }
629 656
630 657
631 function DatePrintString(time) { 658 function DatePrintString(time) {
632 return DateString(time) + ' ' + TimeString(time); 659 return DateString(time) + ' ' + TimeString(time);
633 } 660 }
634 661
635 // ------------------------------------------------------------------- 662 // -------------------------------------------------------------------
636 663
637 // Reused output buffer. 664 // Reused output buffer. Used when parsing date strings.
638 var parse_buffer = $Array(7); 665 var parse_buffer = $Array(7);
639 666
640 // ECMA 262 - 15.9.4.2 667 // ECMA 262 - 15.9.4.2
641 function DateParse(string) { 668 function DateParse(string) {
642 var arr = %DateParseString(ToString(string), parse_buffer); 669 var arr = %DateParseString(ToString(string), parse_buffer);
643 if (IS_NULL(arr)) return $NaN; 670 if (IS_NULL(arr)) return $NaN;
644 671
645 var day = MakeDay(arr[0], arr[1], arr[2]); 672 var day = MakeDay(arr[0], arr[1], arr[2]);
646 var time = MakeTime(arr[3], arr[4], arr[5], 0); 673 var time = MakeTime(arr[3], arr[4], arr[5], 0);
647 var date = MakeDate(day, time); 674 var date = MakeDate(day, time);
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 "toGMTString", DateToGMTString, 1157 "toGMTString", DateToGMTString,
1131 "toUTCString", DateToUTCString, 1158 "toUTCString", DateToUTCString,
1132 "getYear", DateGetYear, 1159 "getYear", DateGetYear,
1133 "setYear", DateSetYear, 1160 "setYear", DateSetYear,
1134 "toISOString", DateToISOString, 1161 "toISOString", DateToISOString,
1135 "toJSON", DateToJSON 1162 "toJSON", DateToJSON
1136 )); 1163 ));
1137 } 1164 }
1138 1165
1139 SetupDate(); 1166 SetupDate();
OLDNEW
« no previous file with comments | « no previous file | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698