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

Unified Diff: src/date-delay.js

Issue 150021: Replaced DateFromTime and isNaN with macro calls in date code. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/macros.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/date-delay.js
===================================================================
--- src/date-delay.js (revision 2293)
+++ src/date-delay.js (working copy)
@@ -28,7 +28,6 @@
// This file relies on the fact that the following declarations have been made
// in v8natives.js:
-// const $isNaN = GlobalIsNaN;
// const $isFinite = GlobalIsFinite;
// -------------------------------------------------------------------
@@ -41,6 +40,11 @@
// changes to these properties.
const $Date = global.Date;
+// Helper function to throw error.
+function ThrowTypeError() {
Kasper Lund 2009/06/29 12:03:07 How about calling this something with Date in the
+ throw new $TypeError('this is not a Date object.');
+}
+
// ECMA 262 - 15.9.1.2
function Day(time) {
return FLOOR(time/msPerDay);
@@ -232,7 +236,7 @@
var local_time_offset = %DateLocalTimeOffset();
function LocalTime(time) {
- if ($isNaN(time)) return time;
+ if (NUMBER_IS_NAN(time)) return time;
return time + local_time_offset + DaylightSavingsOffset(time);
}
@@ -242,7 +246,7 @@
function UTC(time) {
- if ($isNaN(time)) return time;
+ if (NUMBER_IS_NAN(time)) return time;
var tmp = time - local_time_offset;
return tmp - DaylightSavingsOffset(tmp);
}
@@ -454,7 +458,7 @@
minutes = argc > 4 ? ToNumber(minutes) : 0;
seconds = argc > 5 ? ToNumber(seconds) : 0;
ms = argc > 6 ? ToNumber(ms) : 0;
- year = (!$isNaN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
+ year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
? 1900 + TO_INTEGER(year) : year;
var day = MakeDay(year, month, date);
var time = MakeTime(hours, minutes, seconds, ms);
@@ -468,106 +472,105 @@
// Helper functions.
function GetTimeFrom(aDate) {
- if (IS_DATE(aDate)) return %_ValueOf(aDate);
- throw new $TypeError('this is not a Date object.');
+ return DATE_VALUE(aDate);
}
function GetMillisecondsFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return msFromTime(LocalTimeNoCheck(t));
}
function GetUTCMillisecondsFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return msFromTime(t);
}
function GetSecondsFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return SecFromTime(LocalTimeNoCheck(t));
}
function GetUTCSecondsFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return SecFromTime(t);
}
function GetMinutesFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return MinFromTime(LocalTimeNoCheck(t));
}
function GetUTCMinutesFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return MinFromTime(t);
}
function GetHoursFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return HourFromTime(LocalTimeNoCheck(t));
}
function GetUTCHoursFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return HourFromTime(t);
}
function GetFullYearFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
// Ignore the DST offset for year computations.
return YearFromTime(t + local_time_offset);
}
function GetUTCFullYearFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return YearFromTime(t);
}
function GetMonthFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return MonthFromTime(LocalTimeNoCheck(t));
}
function GetUTCMonthFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return MonthFromTime(t);
}
function GetDateFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return DateFromTime(LocalTimeNoCheck(t));
}
function GetUTCDateFrom(aDate) {
- var t = GetTimeFrom(aDate);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(aDate);
+ if (NUMBER_IS_NAN(t)) return t;
return DateFromTime(t);
}
@@ -659,7 +662,7 @@
minutes = argc > 4 ? ToNumber(minutes) : 0;
seconds = argc > 5 ? ToNumber(seconds) : 0;
ms = argc > 6 ? ToNumber(ms) : 0;
- year = (!$isNaN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
+ year = (!NUMBER_IS_NAN(year) && 0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
? 1900 + TO_INTEGER(year) : year;
var day = MakeDay(year, month, date);
var time = MakeTime(hours, minutes, seconds, ms);
@@ -676,24 +679,24 @@
// ECMA 262 - 15.9.5.2
function DateToString() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return kInvalidDate;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) return kInvalidDate;
return DatePrintString(LocalTimeNoCheck(t)) + LocalTimezoneString(t);
}
// ECMA 262 - 15.9.5.3
function DateToDateString() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return kInvalidDate;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) return kInvalidDate;
return DateString(LocalTimeNoCheck(t));
}
// ECMA 262 - 15.9.5.4
function DateToTimeString() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return kInvalidDate;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) return kInvalidDate;
var lt = LocalTimeNoCheck(t);
return TimeString(lt) + LocalTimezoneString(lt);
}
@@ -707,16 +710,16 @@
// ECMA 262 - 15.9.5.6
function DateToLocaleDateString() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return kInvalidDate;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) return kInvalidDate;
return LongDateString(LocalTimeNoCheck(t));
}
// ECMA 262 - 15.9.5.7
function DateToLocaleTimeString() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return kInvalidDate;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) return kInvalidDate;
var lt = LocalTimeNoCheck(t);
return TimeString(lt);
}
@@ -724,13 +727,13 @@
// ECMA 262 - 15.9.5.8
function DateValueOf() {
- return GetTimeFrom(this);
+ return DATE_VALUE(this);
}
// ECMA 262 - 15.9.5.9
function DateGetTime() {
- return GetTimeFrom(this);
+ return DATE_VALUE(this);
}
@@ -772,16 +775,16 @@
// ECMA 262 - 15.9.5.16
function DateGetDay() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return t;
+ var t = %_ValueOf(this);
+ if (NUMBER_IS_NAN(t)) return t;
return WeekDay(LocalTimeNoCheck(t));
}
// ECMA 262 - 15.9.5.17
function DateGetUTCDay() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return t;
+ var t = %_ValueOf(this);
+ if (NUMBER_IS_NAN(t)) return t;
return WeekDay(t);
}
@@ -836,22 +839,22 @@
// ECMA 262 - 15.9.5.26
function DateGetTimezoneOffset() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return t;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) return t;
return (t - LocalTimeNoCheck(t)) / msPerMinute;
}
// ECMA 262 - 15.9.5.27
function DateSetTime(ms) {
- if (!IS_DATE(this)) throw new $TypeError('this is not a Date object.');
+ if (!IS_DATE(this)) ThrowTypeError();
return %_SetValueOf(this, TimeClip(ToNumber(ms)));
}
// ECMA 262 - 15.9.5.28
function DateSetMilliseconds(ms) {
- var t = LocalTime(GetTimeFrom(this));
+ var t = LocalTime(DATE_VALUE(this));
ms = ToNumber(ms);
var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(Day(t), time))));
@@ -860,7 +863,7 @@
// ECMA 262 - 15.9.5.29
function DateSetUTCMilliseconds(ms) {
- var t = GetTimeFrom(this);
+ var t = DATE_VALUE(this);
ms = ToNumber(ms);
var time = MakeTime(HourFromTime(t), MinFromTime(t), SecFromTime(t), ms);
return %_SetValueOf(this, TimeClip(MakeDate(Day(t), time)));
@@ -869,7 +872,7 @@
// ECMA 262 - 15.9.5.30
function DateSetSeconds(sec, ms) {
- var t = LocalTime(GetTimeFrom(this));
+ var t = LocalTime(DATE_VALUE(this));
sec = ToNumber(sec);
ms = %_ArgumentsLength() < 2 ? GetMillisecondsFrom(this) : ToNumber(ms);
var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms);
@@ -879,7 +882,7 @@
// ECMA 262 - 15.9.5.31
function DateSetUTCSeconds(sec, ms) {
- var t = GetTimeFrom(this);
+ var t = DATE_VALUE(this);
sec = ToNumber(sec);
ms = %_ArgumentsLength() < 2 ? GetUTCMillisecondsFrom(this) : ToNumber(ms);
var time = MakeTime(HourFromTime(t), MinFromTime(t), sec, ms);
@@ -889,7 +892,7 @@
// ECMA 262 - 15.9.5.33
function DateSetMinutes(min, sec, ms) {
- var t = LocalTime(GetTimeFrom(this));
+ var t = LocalTime(DATE_VALUE(this));
min = ToNumber(min);
var argc = %_ArgumentsLength();
sec = argc < 2 ? GetSecondsFrom(this) : ToNumber(sec);
@@ -901,7 +904,7 @@
// ECMA 262 - 15.9.5.34
function DateSetUTCMinutes(min, sec, ms) {
- var t = GetTimeFrom(this);
+ var t = DATE_VALUE(this);
min = ToNumber(min);
var argc = %_ArgumentsLength();
sec = argc < 2 ? GetUTCSecondsFrom(this) : ToNumber(sec);
@@ -913,7 +916,7 @@
// ECMA 262 - 15.9.5.35
function DateSetHours(hour, min, sec, ms) {
- var t = LocalTime(GetTimeFrom(this));
+ var t = LocalTime(DATE_VALUE(this));
hour = ToNumber(hour);
var argc = %_ArgumentsLength();
min = argc < 2 ? GetMinutesFrom(this) : ToNumber(min);
@@ -926,7 +929,7 @@
// ECMA 262 - 15.9.5.34
function DateSetUTCHours(hour, min, sec, ms) {
- var t = GetTimeFrom(this);
+ var t = DATE_VALUE(this);
hour = ToNumber(hour);
var argc = %_ArgumentsLength();
min = argc < 2 ? GetUTCMinutesFrom(this) : ToNumber(min);
@@ -939,7 +942,7 @@
// ECMA 262 - 15.9.5.36
function DateSetDate(date) {
- var t = LocalTime(GetTimeFrom(this));
+ var t = LocalTime(DATE_VALUE(this));
date = ToNumber(date);
var day = MakeDay(YearFromTime(t), MonthFromTime(t), date);
return %_SetValueOf(this, TimeClip(UTC(MakeDate(day, TimeWithinDay(t)))));
@@ -948,7 +951,7 @@
// ECMA 262 - 15.9.5.37
function DateSetUTCDate(date) {
- var t = GetTimeFrom(this);
+ var t = DATE_VALUE(this);
date = ToNumber(date);
var day = MakeDay(YearFromTime(t), MonthFromTime(t), date);
return %_SetValueOf(this, TimeClip(MakeDate(day, TimeWithinDay(t))));
@@ -957,7 +960,7 @@
// ECMA 262 - 15.9.5.38
function DateSetMonth(month, date) {
- var t = LocalTime(GetTimeFrom(this));
+ var t = LocalTime(DATE_VALUE(this));
month = ToNumber(month);
date = %_ArgumentsLength() < 2 ? GetDateFrom(this) : ToNumber(date);
var day = MakeDay(YearFromTime(t), month, date);
@@ -967,7 +970,7 @@
// ECMA 262 - 15.9.5.39
function DateSetUTCMonth(month, date) {
- var t = GetTimeFrom(this);
+ var t = DATE_VALUE(this);
month = ToNumber(month);
date = %_ArgumentsLength() < 2 ? GetUTCDateFrom(this) : ToNumber(date);
var day = MakeDay(YearFromTime(t), month, date);
@@ -977,8 +980,8 @@
// ECMA 262 - 15.9.5.40
function DateSetFullYear(year, month, date) {
- var t = GetTimeFrom(this);
- t = $isNaN(t) ? 0 : LocalTimeNoCheck(t);
+ var t = DATE_VALUE(this);
+ t = NUMBER_IS_NAN(t) ? 0 : LocalTimeNoCheck(t);
year = ToNumber(year);
var argc = %_ArgumentsLength();
month = argc < 2 ? MonthFromTime(t) : ToNumber(month);
@@ -990,8 +993,8 @@
// ECMA 262 - 15.9.5.41
function DateSetUTCFullYear(year, month, date) {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) t = 0;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) t = 0;
var argc = %_ArgumentsLength();
year = ToNumber(year);
month = argc < 2 ? MonthFromTime(t) : ToNumber(month);
@@ -1003,8 +1006,8 @@
// ECMA 262 - 15.9.5.42
function DateToUTCString() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return kInvalidDate;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) return kInvalidDate;
// Return UTC string of the form: Sat, 31 Jan 1970 23:00:00 GMT
return WeekDays[WeekDay(t)] + ', '
+ TwoDigitString(DateFromTime(t)) + ' '
@@ -1016,18 +1019,18 @@
// ECMA 262 - B.2.4
function DateGetYear() {
- var t = GetTimeFrom(this);
- if ($isNaN(t)) return $NaN;
+ var t = DATE_VALUE(this);
+ if (NUMBER_IS_NAN(t)) return $NaN;
return YearFromTime(LocalTimeNoCheck(t)) - 1900;
}
// ECMA 262 - B.2.5
function DateSetYear(year) {
- var t = LocalTime(GetTimeFrom(this));
- if ($isNaN(t)) t = 0;
+ var t = LocalTime(DATE_VALUE(this));
+ if (NUMBER_IS_NAN(t)) t = 0;
year = ToNumber(year);
- if ($isNaN(year)) return %_SetValueOf(this, $NaN);
+ if (NUMBER_IS_NAN(year)) return %_SetValueOf(this, $NaN);
year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99)
? 1900 + TO_INTEGER(year) : year;
var day = MakeDay(year, MonthFromTime(t), DateFromTime(t));
« no previous file with comments | « no previous file | src/macros.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698