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

Side by Side Diff: src/date.js

Issue 8701006: Clean up JavaScript files to better follow coding standard. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove more empty statments and fix bug. Created 9 years 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 | « src/d8.js ('k') | src/debug-debugger.js » ('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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 var ymd_from_time_cache = [1970, 0, 1]; 297 var ymd_from_time_cache = [1970, 0, 1];
298 var ymd_from_time_cached_time = 0; 298 var ymd_from_time_cached_time = 0;
299 299
300 function YearFromTime(t) { 300 function YearFromTime(t) {
301 if (t !== ymd_from_time_cached_time) { 301 if (t !== ymd_from_time_cached_time) {
302 if (!$isFinite(t)) { 302 if (!$isFinite(t)) {
303 return $NaN; 303 return $NaN;
304 } 304 }
305 305
306 %DateYMDFromTime(t, ymd_from_time_cache); 306 %DateYMDFromTime(t, ymd_from_time_cache);
307 ymd_from_time_cached_time = t 307 ymd_from_time_cached_time = t;
308 } 308 }
309 309
310 return ymd_from_time_cache[0]; 310 return ymd_from_time_cache[0];
311 } 311 }
312 312
313 function MonthFromTime(t) { 313 function MonthFromTime(t) {
314 if (t !== ymd_from_time_cached_time) { 314 if (t !== ymd_from_time_cached_time) {
315 if (!$isFinite(t)) { 315 if (!$isFinite(t)) {
316 return $NaN; 316 return $NaN;
317 } 317 }
318 %DateYMDFromTime(t, ymd_from_time_cache); 318 %DateYMDFromTime(t, ymd_from_time_cache);
319 ymd_from_time_cached_time = t 319 ymd_from_time_cached_time = t;
320 } 320 }
321 321
322 return ymd_from_time_cache[1]; 322 return ymd_from_time_cache[1];
323 } 323 }
324 324
325 function DateFromTime(t) { 325 function DateFromTime(t) {
326 if (t !== ymd_from_time_cached_time) { 326 if (t !== ymd_from_time_cached_time) {
327 if (!$isFinite(t)) { 327 if (!$isFinite(t)) {
328 return $NaN; 328 return $NaN;
329 } 329 }
330 330
331 %DateYMDFromTime(t, ymd_from_time_cache); 331 %DateYMDFromTime(t, ymd_from_time_cache);
332 ymd_from_time_cached_time = t 332 ymd_from_time_cached_time = t;
333 } 333 }
334 334
335 return ymd_from_time_cache[2]; 335 return ymd_from_time_cache[2];
336 } 336 }
337 337
338 338
339 // Compute number of days given a year, month, date. 339 // Compute number of days given a year, month, date.
340 // Note that month and date can lie outside the normal range. 340 // Note that month and date can lie outside the normal range.
341 // For example: 341 // For example:
342 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20) 342 // MakeDay(2007, -4, 20) --> MakeDay(2006, 8, 20)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 438 }
439 439
440 } else { 440 } else {
441 year = ToNumber(year); 441 year = ToNumber(year);
442 month = ToNumber(month); 442 month = ToNumber(month);
443 date = argc > 2 ? ToNumber(date) : 1; 443 date = argc > 2 ? ToNumber(date) : 1;
444 hours = argc > 3 ? ToNumber(hours) : 0; 444 hours = argc > 3 ? ToNumber(hours) : 0;
445 minutes = argc > 4 ? ToNumber(minutes) : 0; 445 minutes = argc > 4 ? ToNumber(minutes) : 0;
446 seconds = argc > 5 ? ToNumber(seconds) : 0; 446 seconds = argc > 5 ? ToNumber(seconds) : 0;
447 ms = argc > 6 ? ToNumber(ms) : 0; 447 ms = argc > 6 ? ToNumber(ms) : 0;
448 year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) 448 year = (!NUMBER_IS_NAN(year) &&
449 ? 1900 + TO_INTEGER(year) : year; 449 0 <= TO_INTEGER(year) &&
450 TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year;
450 var day = MakeDay(year, month, date); 451 var day = MakeDay(year, month, date);
451 var time = MakeTime(hours, minutes, seconds, ms); 452 var time = MakeTime(hours, minutes, seconds, ms);
452 value = TimeClip(UTC(MakeDate(day, time))); 453 value = TimeClip(UTC(MakeDate(day, time)));
453 } 454 }
454 %_SetValueOf(this, value); 455 %_SetValueOf(this, value);
455 }); 456 });
456 457
457 458
458 %FunctionSetPrototype($Date, new $Date($NaN)); 459 %FunctionSetPrototype($Date, new $Date($NaN));
459 460
460 461
461 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; 462 var WeekDays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
462 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oc t', 'Nov', 'Dec']; 463 var Months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
464 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
463 465
464 466
465 function TwoDigitString(value) { 467 function TwoDigitString(value) {
466 return value < 10 ? "0" + value : "" + value; 468 return value < 10 ? "0" + value : "" + value;
467 } 469 }
468 470
469 471
470 function DateString(time) { 472 function DateString(time) {
471 return WeekDays[WeekDay(time)] + ' ' 473 return WeekDays[WeekDay(time)] + ' '
472 + Months[MonthFromTime(time)] + ' ' 474 + Months[MonthFromTime(time)] + ' '
473 + TwoDigitString(DateFromTime(time)) + ' ' 475 + TwoDigitString(DateFromTime(time)) + ' '
474 + YearFromTime(time); 476 + YearFromTime(time);
475 } 477 }
476 478
477 479
478 var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Fri day', 'Saturday']; 480 var LongWeekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday',
479 var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July' , 'August', 'September', 'October', 'November', 'December']; 481 'Thursday', 'Friday', 'Saturday'];
482 var LongMonths = ['January', 'February', 'March', 'April', 'May', 'June',
483 'July', 'August', 'September', 'October', 'November', 'December'];
480 484
481 485
482 function LongDateString(time) { 486 function LongDateString(time) {
483 return LongWeekDays[WeekDay(time)] + ', ' 487 return LongWeekDays[WeekDay(time)] + ', '
484 + LongMonths[MonthFromTime(time)] + ' ' 488 + LongMonths[MonthFromTime(time)] + ' '
485 + TwoDigitString(DateFromTime(time)) + ', ' 489 + TwoDigitString(DateFromTime(time)) + ', '
486 + YearFromTime(time); 490 + YearFromTime(time);
487 } 491 }
488 492
489 493
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // ECMA 262 - 15.9.4.3 553 // ECMA 262 - 15.9.4.3
550 function DateUTC(year, month, date, hours, minutes, seconds, ms) { 554 function DateUTC(year, month, date, hours, minutes, seconds, ms) {
551 year = ToNumber(year); 555 year = ToNumber(year);
552 month = ToNumber(month); 556 month = ToNumber(month);
553 var argc = %_ArgumentsLength(); 557 var argc = %_ArgumentsLength();
554 date = argc > 2 ? ToNumber(date) : 1; 558 date = argc > 2 ? ToNumber(date) : 1;
555 hours = argc > 3 ? ToNumber(hours) : 0; 559 hours = argc > 3 ? ToNumber(hours) : 0;
556 minutes = argc > 4 ? ToNumber(minutes) : 0; 560 minutes = argc > 4 ? ToNumber(minutes) : 0;
557 seconds = argc > 5 ? ToNumber(seconds) : 0; 561 seconds = argc > 5 ? ToNumber(seconds) : 0;
558 ms = argc > 6 ? ToNumber(ms) : 0; 562 ms = argc > 6 ? ToNumber(ms) : 0;
559 year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 9 9) 563 year = (!NUMBER_IS_NAN(year) &&
560 ? 1900 + TO_INTEGER(year) : year; 564 0 <= TO_INTEGER(year) &&
565 TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year;
561 var day = MakeDay(year, month, date); 566 var day = MakeDay(year, month, date);
562 var time = MakeTime(hours, minutes, seconds, ms); 567 var time = MakeTime(hours, minutes, seconds, ms);
563 return %_SetValueOf(this, TimeClip(MakeDate(day, time))); 568 return %_SetValueOf(this, TimeClip(MakeDate(day, time)));
564 } 569 }
565 570
566 571
567 // Mozilla-specific extension. Returns the number of milliseconds 572 // Mozilla-specific extension. Returns the number of milliseconds
568 // elapsed since 1 January 1970 00:00:00 UTC. 573 // elapsed since 1 January 1970 00:00:00 UTC.
569 function DateNow() { 574 function DateNow() {
570 return %DateCurrentTime(); 575 return %DateCurrentTime();
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 function DateSetTime(ms) { 775 function DateSetTime(ms) {
771 if (!IS_DATE(this)) ThrowDateTypeError(); 776 if (!IS_DATE(this)) ThrowDateTypeError();
772 return %_SetValueOf(this, TimeClip(ToNumber(ms))); 777 return %_SetValueOf(this, TimeClip(ToNumber(ms)));
773 } 778 }
774 779
775 780
776 // ECMA 262 - 15.9.5.28 781 // ECMA 262 - 15.9.5.28
777 function DateSetMilliseconds(ms) { 782 function DateSetMilliseconds(ms) {
778 var t = LocalTime(DATE_VALUE(this)); 783 var t = LocalTime(DATE_VALUE(this));
779 ms = ToNumber(ms); 784 ms = ToNumber(ms);
780 var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), SEC_FROM_TIME(t), ms) ; 785 var time = MakeTime(HOUR_FROM_TIME(t),
786 MIN_FROM_TIME(t),
787 SEC_FROM_TIME(t),
788 ms);
781 return %_SetValueOf(this, TimeClip(UTC(MakeDate(DAY(t), time)))); 789 return %_SetValueOf(this, TimeClip(UTC(MakeDate(DAY(t), time))));
782 } 790 }
783 791
784 792
785 // ECMA 262 - 15.9.5.29 793 // ECMA 262 - 15.9.5.29
786 function DateSetUTCMilliseconds(ms) { 794 function DateSetUTCMilliseconds(ms) {
787 var t = DATE_VALUE(this); 795 var t = DATE_VALUE(this);
788 ms = ToNumber(ms); 796 ms = ToNumber(ms);
789 var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), SEC_FROM_TIME(t), ms) ; 797 var time = MakeTime(HOUR_FROM_TIME(t),
798 MIN_FROM_TIME(t),
799 SEC_FROM_TIME(t),
800 ms);
790 return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time))); 801 return %_SetValueOf(this, TimeClip(MakeDate(DAY(t), time)));
791 } 802 }
792 803
793 804
794 // ECMA 262 - 15.9.5.30 805 // ECMA 262 - 15.9.5.30
795 function DateSetSeconds(sec, ms) { 806 function DateSetSeconds(sec, ms) {
796 var t = LocalTime(DATE_VALUE(this)); 807 var t = LocalTime(DATE_VALUE(this));
797 sec = ToNumber(sec); 808 sec = ToNumber(sec);
798 ms = %_ArgumentsLength() < 2 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms); 809 ms = %_ArgumentsLength() < 2 ? NAN_OR_MS_FROM_TIME(t) : ToNumber(ms);
799 var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), sec, ms); 810 var time = MakeTime(HOUR_FROM_TIME(t), MIN_FROM_TIME(t), sec, ms);
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 "toGMTString", DateToGMTString, 1117 "toGMTString", DateToGMTString,
1107 "toUTCString", DateToUTCString, 1118 "toUTCString", DateToUTCString,
1108 "getYear", DateGetYear, 1119 "getYear", DateGetYear,
1109 "setYear", DateSetYear, 1120 "setYear", DateSetYear,
1110 "toISOString", DateToISOString, 1121 "toISOString", DateToISOString,
1111 "toJSON", DateToJSON 1122 "toJSON", DateToJSON
1112 )); 1123 ));
1113 } 1124 }
1114 1125
1115 SetUpDate(); 1126 SetUpDate();
OLDNEW
« no previous file with comments | « src/d8.js ('k') | src/debug-debugger.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698