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

Side by Side Diff: src/runtime.cc

Issue 8392036: Fix error handling in Date.prototype.toISOString. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Lasse Reichstein. Created 9 years, 1 month 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/runtime.h ('k') | test/mjsunit/date.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 7472 matching lines...) Expand 10 before | Expand all | Expand 10 after
7483 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) { 7483 RUNTIME_FUNCTION(MaybeObject*, Runtime_Math_tan) {
7484 NoHandleAllocation ha; 7484 NoHandleAllocation ha;
7485 ASSERT(args.length() == 1); 7485 ASSERT(args.length() == 1);
7486 isolate->counters()->math_tan()->Increment(); 7486 isolate->counters()->math_tan()->Increment();
7487 7487
7488 CONVERT_DOUBLE_ARG_CHECKED(x, 0); 7488 CONVERT_DOUBLE_ARG_CHECKED(x, 0);
7489 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x); 7489 return isolate->transcendental_cache()->Get(TranscendentalCache::TAN, x);
7490 } 7490 }
7491 7491
7492 7492
7493 static int MakeDay(int year, int month, int day) { 7493 static int MakeDay(int year, int month) {
7494 static const int day_from_month[] = {0, 31, 59, 90, 120, 151, 7494 static const int day_from_month[] = {0, 31, 59, 90, 120, 151,
7495 181, 212, 243, 273, 304, 334}; 7495 181, 212, 243, 273, 304, 334};
7496 static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152, 7496 static const int day_from_month_leap[] = {0, 31, 60, 91, 121, 152,
7497 182, 213, 244, 274, 305, 335}; 7497 182, 213, 244, 274, 305, 335};
7498 7498
7499 year += month / 12; 7499 year += month / 12;
7500 month %= 12; 7500 month %= 12;
7501 if (month < 0) { 7501 if (month < 0) {
7502 year--; 7502 year--;
7503 month += 12; 7503 month += 12;
(...skipping 16 matching lines...) Expand all
7520 (1970 + year_delta) / 100 + 7520 (1970 + year_delta) / 100 +
7521 (1970 + year_delta) / 400; 7521 (1970 + year_delta) / 400;
7522 7522
7523 int year1 = year + year_delta; 7523 int year1 = year + year_delta;
7524 int day_from_year = 365 * year1 + 7524 int day_from_year = 365 * year1 +
7525 year1 / 4 - 7525 year1 / 4 -
7526 year1 / 100 + 7526 year1 / 100 +
7527 year1 / 400 - 7527 year1 / 400 -
7528 base_day; 7528 base_day;
7529 7529
7530 if (year % 4 || (year % 100 == 0 && year % 400 != 0)) { 7530 if ((year % 4 != 0) || (year % 100 == 0 && year % 400 != 0)) {
7531 return day_from_year + day_from_month[month] + day - 1; 7531 return day_from_year + day_from_month[month];
7532 } 7532 }
7533 7533
7534 return day_from_year + day_from_month_leap[month] + day - 1; 7534 return day_from_year + day_from_month_leap[month];
7535 } 7535 }
7536 7536
7537 7537
7538 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) { 7538 RUNTIME_FUNCTION(MaybeObject*, Runtime_DateMakeDay) {
7539 NoHandleAllocation ha; 7539 NoHandleAllocation ha;
7540 ASSERT(args.length() == 3); 7540 ASSERT(args.length() == 2);
7541 7541
7542 CONVERT_SMI_ARG_CHECKED(year, 0); 7542 CONVERT_SMI_ARG_CHECKED(year, 0);
7543 CONVERT_SMI_ARG_CHECKED(month, 1); 7543 CONVERT_SMI_ARG_CHECKED(month, 1);
7544 CONVERT_SMI_ARG_CHECKED(date, 2);
7545 7544
7546 return Smi::FromInt(MakeDay(year, month, date)); 7545 return Smi::FromInt(MakeDay(year, month));
7547 } 7546 }
7548 7547
7549 7548
7550 static const int kDays4Years[] = {0, 365, 2 * 365, 3 * 365 + 1}; 7549 static const int kDays4Years[] = {0, 365, 2 * 365, 3 * 365 + 1};
7551 static const int kDaysIn4Years = 4 * 365 + 1; 7550 static const int kDaysIn4Years = 4 * 365 + 1;
7552 static const int kDaysIn100Years = 25 * kDaysIn4Years - 1; 7551 static const int kDaysIn100Years = 25 * kDaysIn4Years - 1;
7553 static const int kDaysIn400Years = 4 * kDaysIn100Years + 1; 7552 static const int kDaysIn400Years = 4 * kDaysIn100Years + 1;
7554 static const int kDays1970to2000 = 30 * 365 + 7; 7553 static const int kDays1970to2000 = 30 * 365 + 7;
7555 static const int kDaysOffset = 1000 * kDaysIn400Years + 5 * kDaysIn400Years - 7554 static const int kDaysOffset = 1000 * kDaysIn400Years + 5 * kDaysIn400Years -
7556 kDays1970to2000; 7555 kDays1970to2000;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
7765 #ifdef DEBUG 7764 #ifdef DEBUG
7766 int save_date = date; // Need this for ASSERT in the end. 7765 int save_date = date; // Need this for ASSERT in the end.
7767 #endif 7766 #endif
7768 7767
7769 year = 1970 + (4 * date + 2) / kDaysIn4Years; 7768 year = 1970 + (4 * date + 2) / kDaysIn4Years;
7770 date %= kDaysIn4Years; 7769 date %= kDaysIn4Years;
7771 7770
7772 month = kMonthInYear[date]; 7771 month = kMonthInYear[date];
7773 day = kDayInYear[date]; 7772 day = kDayInYear[date];
7774 7773
7775 ASSERT(MakeDay(year, month, day) == save_date); 7774 ASSERT(MakeDay(year, month) + day - 1 == save_date);
7776 } 7775 }
7777 7776
7778 7777
7779 static inline void DateYMDFromTimeSlow(int date, 7778 static inline void DateYMDFromTimeSlow(int date,
7780 int& year, int& month, int& day) { 7779 int& year, int& month, int& day) {
7781 #ifdef DEBUG 7780 #ifdef DEBUG
7782 int save_date = date; // Need this for ASSERT in the end. 7781 int save_date = date; // Need this for ASSERT in the end.
7783 #endif 7782 #endif
7784 7783
7785 date += kDaysOffset; 7784 date += kDaysOffset;
7786 year = 400 * (date / kDaysIn400Years) - kYearsOffset; 7785 year = 400 * (date / kDaysIn400Years) - kYearsOffset;
7787 date %= kDaysIn400Years; 7786 date %= kDaysIn400Years;
7788 7787
7789 ASSERT(MakeDay(year, 0, 1) + date == save_date); 7788 ASSERT(MakeDay(year, 0) + date == save_date);
7790 7789
7791 date--; 7790 date--;
7792 int yd1 = date / kDaysIn100Years; 7791 int yd1 = date / kDaysIn100Years;
7793 date %= kDaysIn100Years; 7792 date %= kDaysIn100Years;
7794 year += 100 * yd1; 7793 year += 100 * yd1;
7795 7794
7796 date++; 7795 date++;
7797 int yd2 = date / kDaysIn4Years; 7796 int yd2 = date / kDaysIn4Years;
7798 date %= kDaysIn4Years; 7797 date %= kDaysIn4Years;
7799 year += 4 * yd2; 7798 year += 4 * yd2;
7800 7799
7801 date--; 7800 date--;
7802 int yd3 = date / 365; 7801 int yd3 = date / 365;
7803 date %= 365; 7802 date %= 365;
7804 year += yd3; 7803 year += yd3;
7805 7804
7806 bool is_leap = (!yd1 || yd2) && !yd3; 7805 bool is_leap = (!yd1 || yd2) && !yd3;
7807 7806
7808 ASSERT(date >= -1); 7807 ASSERT(date >= -1);
7809 ASSERT(is_leap || (date >= 0)); 7808 ASSERT(is_leap || (date >= 0));
7810 ASSERT((date < 365) || (is_leap && (date < 366))); 7809 ASSERT((date < 365) || (is_leap && (date < 366)));
7811 ASSERT(is_leap == ((year % 4 == 0) && (year % 100 || (year % 400 == 0)))); 7810 ASSERT(is_leap == ((year % 4 == 0) && (year % 100 || (year % 400 == 0))));
7812 ASSERT(is_leap || ((MakeDay(year, 0, 1) + date) == save_date)); 7811 ASSERT(is_leap || ((MakeDay(year, 0) + date) == save_date));
7813 ASSERT(!is_leap || ((MakeDay(year, 0, 1) + date + 1) == save_date)); 7812 ASSERT(!is_leap || ((MakeDay(year, 0) + date + 1) == save_date));
7814 7813
7815 if (is_leap) { 7814 if (is_leap) {
7816 day = kDayInYear[2*365 + 1 + date]; 7815 day = kDayInYear[2*365 + 1 + date];
7817 month = kMonthInYear[2*365 + 1 + date]; 7816 month = kMonthInYear[2*365 + 1 + date];
7818 } else { 7817 } else {
7819 day = kDayInYear[date]; 7818 day = kDayInYear[date];
7820 month = kMonthInYear[date]; 7819 month = kMonthInYear[date];
7821 } 7820 }
7822 7821
7823 ASSERT(MakeDay(year, month, day) == save_date); 7822 ASSERT(MakeDay(year, month) + day - 1 == save_date);
7824 } 7823 }
7825 7824
7826 7825
7827 static inline void DateYMDFromTime(int date, 7826 static inline void DateYMDFromTime(int date,
7828 int& year, int& month, int& day) { 7827 int& year, int& month, int& day) {
7829 if (date >= 0 && date < 32 * kDaysIn4Years) { 7828 if (date >= 0 && date < 32 * kDaysIn4Years) {
7830 DateYMDFromTimeAfter1970(date, year, month, day); 7829 DateYMDFromTimeAfter1970(date, year, month, day);
7831 } else { 7830 } else {
7832 DateYMDFromTimeSlow(date, year, month, day); 7831 DateYMDFromTimeSlow(date, year, month, day);
7833 } 7832 }
(...skipping 5692 matching lines...) Expand 10 before | Expand all | Expand 10 after
13526 } else { 13525 } else {
13527 // Handle last resort GC and make sure to allow future allocations 13526 // Handle last resort GC and make sure to allow future allocations
13528 // to grow the heap without causing GCs (if possible). 13527 // to grow the heap without causing GCs (if possible).
13529 isolate->counters()->gc_last_resort_from_js()->Increment(); 13528 isolate->counters()->gc_last_resort_from_js()->Increment();
13530 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 13529 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
13531 } 13530 }
13532 } 13531 }
13533 13532
13534 13533
13535 } } // namespace v8::internal 13534 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/date.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698