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

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

Issue 160451: Guard local time posix functions from NaN value of invalid dates. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 4 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/platform.h » ('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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 offset: 0, 149 offset: 0,
150 // Time interval where the cached offset is valid. 150 // Time interval where the cached offset is valid.
151 start: 0, end: -1, 151 start: 0, end: -1,
152 // Size of next interval expansion. 152 // Size of next interval expansion.
153 increment: 0 153 increment: 0
154 }; 154 };
155 155
156 156
157 // NOTE: The implementation relies on the fact that no time zones have 157 // NOTE: The implementation relies on the fact that no time zones have
158 // more than one daylight savings offset change per month. 158 // more than one daylight savings offset change per month.
159 // This function must never be called with the argument NaN.
160 // All uses of it are guarded so this does not happen.
159 function DaylightSavingsOffset(t) { 161 function DaylightSavingsOffset(t) {
160 // Load the cache object from the builtins object. 162 // Load the cache object from the builtins object.
161 var cache = DST_offset_cache; 163 var cache = DST_offset_cache;
162 164
163 // Cache the start and the end in local variables for fast access. 165 // Cache the start and the end in local variables for fast access.
164 var start = cache.start; 166 var start = cache.start;
165 var end = cache.end; 167 var end = cache.end;
166 168
167 if (start <= t) { 169 if (start <= t) {
168 // If the time fits in the cached interval, return the cached offset. 170 // If the time fits in the cached interval, return the cached offset.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 cache.start = cache.end = t; 214 cache.start = cache.end = t;
213 cache.increment = msPerMonth; 215 cache.increment = msPerMonth;
214 return offset; 216 return offset;
215 } 217 }
216 218
217 219
218 var timezone_cache_time = $NaN; 220 var timezone_cache_time = $NaN;
219 var timezone_cache_timezone; 221 var timezone_cache_timezone;
220 222
221 function LocalTimezone(t) { 223 function LocalTimezone(t) {
224 if (NUMBER_IS_NAN(t)) return "";
222 if (t == timezone_cache_time) { 225 if (t == timezone_cache_time) {
223 return timezone_cache_timezone; 226 return timezone_cache_timezone;
224 } 227 }
225 var timezone = %DateLocalTimezone(EquivalentTime(t)); 228 var timezone = %DateLocalTimezone(EquivalentTime(t));
226 timezone_cache_time = t; 229 timezone_cache_time = t;
227 timezone_cache_timezone = timezone; 230 timezone_cache_timezone = timezone;
228 return timezone; 231 return timezone;
229 } 232 }
230 233
231 234
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 value = TimeClip(year); 460 value = TimeClip(year);
458 461
459 } else if (IS_STRING(year)) { 462 } else if (IS_STRING(year)) {
460 // Probe the Date cache. If we already have a time value for the 463 // Probe the Date cache. If we already have a time value for the
461 // given time, we re-use that instead of parsing the string again. 464 // given time, we re-use that instead of parsing the string again.
462 var cache = Date_cache; 465 var cache = Date_cache;
463 if (cache.string === year) { 466 if (cache.string === year) {
464 value = cache.time; 467 value = cache.time;
465 } else { 468 } else {
466 value = DateParse(year); 469 value = DateParse(year);
467 cache.time = value; 470 if (!NUMBER_IS_NAN(value)) {
468 cache.year = YearFromTime(LocalTimeNoCheck(value)); 471 cache.time = value;
469 cache.string = year; 472 cache.year = YearFromTime(LocalTimeNoCheck(value));
473 cache.string = year;
474 }
470 } 475 }
471 476
472 } else { 477 } else {
473 // According to ECMA 262, no hint should be given for this 478 // According to ECMA 262, no hint should be given for this
474 // conversion. However, ToPrimitive defaults to STRING_HINT for 479 // conversion. However, ToPrimitive defaults to STRING_HINT for
475 // Date objects which will lose precision when the Date 480 // Date objects which will lose precision when the Date
476 // constructor is called with another Date object as its 481 // constructor is called with another Date object as its
477 // argument. We therefore use NUMBER_HINT for the conversion, 482 // argument. We therefore use NUMBER_HINT for the conversion,
478 // which is the default for everything else than Date objects. 483 // which is the default for everything else than Date objects.
479 // This makes us behave like KJS and SpiderMonkey. 484 // This makes us behave like KJS and SpiderMonkey.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 645
641 646
642 function TimeString(time) { 647 function TimeString(time) {
643 return TwoDigitString(HourFromTime(time)) + ':' 648 return TwoDigitString(HourFromTime(time)) + ':'
644 + TwoDigitString(MinFromTime(time)) + ':' 649 + TwoDigitString(MinFromTime(time)) + ':'
645 + TwoDigitString(SecFromTime(time)); 650 + TwoDigitString(SecFromTime(time));
646 } 651 }
647 652
648 653
649 function LocalTimezoneString(time) { 654 function LocalTimezoneString(time) {
655 // time is not NaN because of checks in calling functions.
650 var timezoneOffset = (local_time_offset + DaylightSavingsOffset(time)) / msPer Minute; 656 var timezoneOffset = (local_time_offset + DaylightSavingsOffset(time)) / msPer Minute;
651 var sign = (timezoneOffset >= 0) ? 1 : -1; 657 var sign = (timezoneOffset >= 0) ? 1 : -1;
652 var hours = FLOOR((sign * timezoneOffset)/60); 658 var hours = FLOOR((sign * timezoneOffset)/60);
653 var min = FLOOR((sign * timezoneOffset)%60); 659 var min = FLOOR((sign * timezoneOffset)%60);
654 var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + TwoDigitString(hours) + TwoDigi tString(min); 660 var gmt = ' GMT' + ((sign == 1) ? '+' : '-') + TwoDigitString(hours) + TwoDigi tString(min);
655 return gmt + ' (' + LocalTimezone(time) + ')'; 661 return gmt + ' (' + LocalTimezone(time) + ')';
656 } 662 }
657 663
658 664
659 function DatePrintString(time) { 665 function DatePrintString(time) {
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 "toGMTString", DateToGMTString, 1164 "toGMTString", DateToGMTString,
1159 "toUTCString", DateToUTCString, 1165 "toUTCString", DateToUTCString,
1160 "getYear", DateGetYear, 1166 "getYear", DateGetYear,
1161 "setYear", DateSetYear, 1167 "setYear", DateSetYear,
1162 "toISOString", DateToISOString, 1168 "toISOString", DateToISOString,
1163 "toJSON", DateToJSON 1169 "toJSON", DateToJSON
1164 )); 1170 ));
1165 } 1171 }
1166 1172
1167 SetupDate(); 1173 SetupDate();
OLDNEW
« no previous file with comments | « no previous file | src/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698