Index: src/date.js |
diff --git a/src/date.js b/src/date.js |
index 0a19a13e087806969e65bc31e97204aea6da1047..3a74e102eec1e7a2e48abb2334b3ff7a906b7b20 100644 |
--- a/src/date.js |
+++ b/src/date.js |
@@ -17,15 +17,18 @@ var $createDate; |
var GlobalDate = global.Date; |
var InternalArray = utils.InternalArray; |
- |
var IsFinite; |
var MathAbs; |
var MathFloor; |
+var ToNumber; |
+var ToString; |
utils.Import(function(from) { |
IsFinite = from.IsFinite; |
MathAbs = from.MathAbs; |
MathFloor = from.MathFloor; |
+ ToNumber = from.ToNumber; |
+ ToString = from.ToString; |
}); |
// ------------------------------------------------------------------- |
@@ -169,17 +172,17 @@ function DateConstructor(year, month, date, hours, minutes, seconds, ms) { |
// which is the default for everything else than Date objects. |
// This makes us behave like KJS and SpiderMonkey. |
var time = $toPrimitive(year, NUMBER_HINT); |
- value = IS_STRING(time) ? DateParse(time) : $toNumber(time); |
+ value = IS_STRING(time) ? DateParse(time) : ToNumber(time); |
} |
SET_UTC_DATE_VALUE(this, value); |
} else { |
- year = $toNumber(year); |
- month = $toNumber(month); |
- date = argc > 2 ? $toNumber(date) : 1; |
- hours = argc > 3 ? $toNumber(hours) : 0; |
- minutes = argc > 4 ? $toNumber(minutes) : 0; |
- seconds = argc > 5 ? $toNumber(seconds) : 0; |
- ms = argc > 6 ? $toNumber(ms) : 0; |
+ year = ToNumber(year); |
+ month = ToNumber(month); |
+ date = argc > 2 ? ToNumber(date) : 1; |
+ hours = argc > 3 ? ToNumber(hours) : 0; |
+ minutes = argc > 4 ? ToNumber(minutes) : 0; |
+ seconds = argc > 5 ? ToNumber(seconds) : 0; |
+ ms = argc > 6 ? ToNumber(ms) : 0; |
year = (!NUMBER_IS_NAN(year) && |
0 <= TO_INTEGER(year) && |
TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year; |
@@ -267,7 +270,7 @@ var parse_buffer = new InternalArray(8); |
// ECMA 262 - 15.9.4.2 |
function DateParse(string) { |
- var arr = %DateParseString($toString(string), parse_buffer); |
+ var arr = %DateParseString(ToString(string), parse_buffer); |
if (IS_NULL(arr)) return NAN; |
var day = MakeDay(arr[0], arr[1], arr[2]); |
@@ -284,14 +287,14 @@ function DateParse(string) { |
// ECMA 262 - 15.9.4.3 |
function DateUTC(year, month, date, hours, minutes, seconds, ms) { |
- year = $toNumber(year); |
- month = $toNumber(month); |
+ year = ToNumber(year); |
+ month = ToNumber(month); |
var argc = %_ArgumentsLength(); |
- date = argc > 2 ? $toNumber(date) : 1; |
- hours = argc > 3 ? $toNumber(hours) : 0; |
- minutes = argc > 4 ? $toNumber(minutes) : 0; |
- seconds = argc > 5 ? $toNumber(seconds) : 0; |
- ms = argc > 6 ? $toNumber(ms) : 0; |
+ date = argc > 2 ? ToNumber(date) : 1; |
+ hours = argc > 3 ? ToNumber(hours) : 0; |
+ minutes = argc > 4 ? ToNumber(minutes) : 0; |
+ seconds = argc > 5 ? ToNumber(seconds) : 0; |
+ ms = argc > 6 ? ToNumber(ms) : 0; |
year = (!NUMBER_IS_NAN(year) && |
0 <= TO_INTEGER(year) && |
TO_INTEGER(year) <= 99) ? 1900 + TO_INTEGER(year) : year; |
@@ -497,7 +500,7 @@ function DateGetTimezoneOffset() { |
// ECMA 262 - 15.9.5.27 |
function DateSetTime(ms) { |
CHECK_DATE(this); |
- SET_UTC_DATE_VALUE(this, $toNumber(ms)); |
+ SET_UTC_DATE_VALUE(this, ToNumber(ms)); |
return UTC_DATE_VALUE(this); |
} |
@@ -506,7 +509,7 @@ function DateSetTime(ms) { |
function DateSetMilliseconds(ms) { |
CHECK_DATE(this); |
var t = LOCAL_DATE_VALUE(this); |
- ms = $toNumber(ms); |
+ ms = ToNumber(ms); |
var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), LOCAL_SEC(this), ms); |
return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); |
} |
@@ -516,7 +519,7 @@ function DateSetMilliseconds(ms) { |
function DateSetUTCMilliseconds(ms) { |
CHECK_DATE(this); |
var t = UTC_DATE_VALUE(this); |
- ms = $toNumber(ms); |
+ ms = ToNumber(ms); |
var time = MakeTime(UTC_HOUR(this), |
UTC_MIN(this), |
UTC_SEC(this), |
@@ -529,8 +532,8 @@ function DateSetUTCMilliseconds(ms) { |
function DateSetSeconds(sec, ms) { |
CHECK_DATE(this); |
var t = LOCAL_DATE_VALUE(this); |
- sec = $toNumber(sec); |
- ms = %_ArgumentsLength() < 2 ? LOCAL_MS(this) : $toNumber(ms); |
+ sec = ToNumber(sec); |
+ ms = %_ArgumentsLength() < 2 ? LOCAL_MS(this) : ToNumber(ms); |
var time = MakeTime(LOCAL_HOUR(this), LOCAL_MIN(this), sec, ms); |
return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); |
} |
@@ -540,8 +543,8 @@ function DateSetSeconds(sec, ms) { |
function DateSetUTCSeconds(sec, ms) { |
CHECK_DATE(this); |
var t = UTC_DATE_VALUE(this); |
- sec = $toNumber(sec); |
- ms = %_ArgumentsLength() < 2 ? UTC_MS(this) : $toNumber(ms); |
+ sec = ToNumber(sec); |
+ ms = %_ArgumentsLength() < 2 ? UTC_MS(this) : ToNumber(ms); |
var time = MakeTime(UTC_HOUR(this), UTC_MIN(this), sec, ms); |
return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); |
} |
@@ -551,10 +554,10 @@ function DateSetUTCSeconds(sec, ms) { |
function DateSetMinutes(min, sec, ms) { |
CHECK_DATE(this); |
var t = LOCAL_DATE_VALUE(this); |
- min = $toNumber(min); |
+ min = ToNumber(min); |
var argc = %_ArgumentsLength(); |
- sec = argc < 2 ? LOCAL_SEC(this) : $toNumber(sec); |
- ms = argc < 3 ? LOCAL_MS(this) : $toNumber(ms); |
+ sec = argc < 2 ? LOCAL_SEC(this) : ToNumber(sec); |
+ ms = argc < 3 ? LOCAL_MS(this) : ToNumber(ms); |
var time = MakeTime(LOCAL_HOUR(this), min, sec, ms); |
return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); |
} |
@@ -564,10 +567,10 @@ function DateSetMinutes(min, sec, ms) { |
function DateSetUTCMinutes(min, sec, ms) { |
CHECK_DATE(this); |
var t = UTC_DATE_VALUE(this); |
- min = $toNumber(min); |
+ min = ToNumber(min); |
var argc = %_ArgumentsLength(); |
- sec = argc < 2 ? UTC_SEC(this) : $toNumber(sec); |
- ms = argc < 3 ? UTC_MS(this) : $toNumber(ms); |
+ sec = argc < 2 ? UTC_SEC(this) : ToNumber(sec); |
+ ms = argc < 3 ? UTC_MS(this) : ToNumber(ms); |
var time = MakeTime(UTC_HOUR(this), min, sec, ms); |
return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); |
} |
@@ -577,11 +580,11 @@ function DateSetUTCMinutes(min, sec, ms) { |
function DateSetHours(hour, min, sec, ms) { |
CHECK_DATE(this); |
var t = LOCAL_DATE_VALUE(this); |
- hour = $toNumber(hour); |
+ hour = ToNumber(hour); |
var argc = %_ArgumentsLength(); |
- min = argc < 2 ? LOCAL_MIN(this) : $toNumber(min); |
- sec = argc < 3 ? LOCAL_SEC(this) : $toNumber(sec); |
- ms = argc < 4 ? LOCAL_MS(this) : $toNumber(ms); |
+ min = argc < 2 ? LOCAL_MIN(this) : ToNumber(min); |
+ sec = argc < 3 ? LOCAL_SEC(this) : ToNumber(sec); |
+ ms = argc < 4 ? LOCAL_MS(this) : ToNumber(ms); |
var time = MakeTime(hour, min, sec, ms); |
return SET_LOCAL_DATE_VALUE(this, MakeDate(LOCAL_DAYS(this), time)); |
} |
@@ -591,11 +594,11 @@ function DateSetHours(hour, min, sec, ms) { |
function DateSetUTCHours(hour, min, sec, ms) { |
CHECK_DATE(this); |
var t = UTC_DATE_VALUE(this); |
- hour = $toNumber(hour); |
+ hour = ToNumber(hour); |
var argc = %_ArgumentsLength(); |
- min = argc < 2 ? UTC_MIN(this) : $toNumber(min); |
- sec = argc < 3 ? UTC_SEC(this) : $toNumber(sec); |
- ms = argc < 4 ? UTC_MS(this) : $toNumber(ms); |
+ min = argc < 2 ? UTC_MIN(this) : ToNumber(min); |
+ sec = argc < 3 ? UTC_SEC(this) : ToNumber(sec); |
+ ms = argc < 4 ? UTC_MS(this) : ToNumber(ms); |
var time = MakeTime(hour, min, sec, ms); |
return SET_UTC_DATE_VALUE(this, MakeDate(UTC_DAYS(this), time)); |
} |
@@ -605,7 +608,7 @@ function DateSetUTCHours(hour, min, sec, ms) { |
function DateSetDate(date) { |
CHECK_DATE(this); |
var t = LOCAL_DATE_VALUE(this); |
- date = $toNumber(date); |
+ date = ToNumber(date); |
var day = MakeDay(LOCAL_YEAR(this), LOCAL_MONTH(this), date); |
return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this))); |
} |
@@ -615,7 +618,7 @@ function DateSetDate(date) { |
function DateSetUTCDate(date) { |
CHECK_DATE(this); |
var t = UTC_DATE_VALUE(this); |
- date = $toNumber(date); |
+ date = ToNumber(date); |
var day = MakeDay(UTC_YEAR(this), UTC_MONTH(this), date); |
return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this))); |
} |
@@ -625,8 +628,8 @@ function DateSetUTCDate(date) { |
function DateSetMonth(month, date) { |
CHECK_DATE(this); |
var t = LOCAL_DATE_VALUE(this); |
- month = $toNumber(month); |
- date = %_ArgumentsLength() < 2 ? LOCAL_DAY(this) : $toNumber(date); |
+ month = ToNumber(month); |
+ date = %_ArgumentsLength() < 2 ? LOCAL_DAY(this) : ToNumber(date); |
var day = MakeDay(LOCAL_YEAR(this), month, date); |
return SET_LOCAL_DATE_VALUE(this, MakeDate(day, LOCAL_TIME_IN_DAY(this))); |
} |
@@ -636,8 +639,8 @@ function DateSetMonth(month, date) { |
function DateSetUTCMonth(month, date) { |
CHECK_DATE(this); |
var t = UTC_DATE_VALUE(this); |
- month = $toNumber(month); |
- date = %_ArgumentsLength() < 2 ? UTC_DAY(this) : $toNumber(date); |
+ month = ToNumber(month); |
+ date = %_ArgumentsLength() < 2 ? UTC_DAY(this) : ToNumber(date); |
var day = MakeDay(UTC_YEAR(this), month, date); |
return SET_UTC_DATE_VALUE(this, MakeDate(day, UTC_TIME_IN_DAY(this))); |
} |
@@ -647,16 +650,16 @@ function DateSetUTCMonth(month, date) { |
function DateSetFullYear(year, month, date) { |
CHECK_DATE(this); |
var t = LOCAL_DATE_VALUE(this); |
- year = $toNumber(year); |
+ year = ToNumber(year); |
var argc = %_ArgumentsLength(); |
var time ; |
if (NUMBER_IS_NAN(t)) { |
- month = argc < 2 ? 0 : $toNumber(month); |
- date = argc < 3 ? 1 : $toNumber(date); |
+ month = argc < 2 ? 0 : ToNumber(month); |
+ date = argc < 3 ? 1 : ToNumber(date); |
time = 0; |
} else { |
- month = argc < 2 ? LOCAL_MONTH(this) : $toNumber(month); |
- date = argc < 3 ? LOCAL_DAY(this) : $toNumber(date); |
+ month = argc < 2 ? LOCAL_MONTH(this) : ToNumber(month); |
+ date = argc < 3 ? LOCAL_DAY(this) : ToNumber(date); |
time = LOCAL_TIME_IN_DAY(this); |
} |
var day = MakeDay(year, month, date); |
@@ -668,16 +671,16 @@ function DateSetFullYear(year, month, date) { |
function DateSetUTCFullYear(year, month, date) { |
CHECK_DATE(this); |
var t = UTC_DATE_VALUE(this); |
- year = $toNumber(year); |
+ year = ToNumber(year); |
var argc = %_ArgumentsLength(); |
var time ; |
if (NUMBER_IS_NAN(t)) { |
- month = argc < 2 ? 0 : $toNumber(month); |
- date = argc < 3 ? 1 : $toNumber(date); |
+ month = argc < 2 ? 0 : ToNumber(month); |
+ date = argc < 3 ? 1 : ToNumber(date); |
time = 0; |
} else { |
- month = argc < 2 ? UTC_MONTH(this) : $toNumber(month); |
- date = argc < 3 ? UTC_DAY(this) : $toNumber(date); |
+ month = argc < 2 ? UTC_MONTH(this) : ToNumber(month); |
+ date = argc < 3 ? UTC_DAY(this) : ToNumber(date); |
time = UTC_TIME_IN_DAY(this); |
} |
var day = MakeDay(year, month, date); |
@@ -709,7 +712,7 @@ function DateGetYear() { |
// ECMA 262 - B.2.5 |
function DateSetYear(year) { |
CHECK_DATE(this); |
- year = $toNumber(year); |
+ year = ToNumber(year); |
if (NUMBER_IS_NAN(year)) return SET_UTC_DATE_VALUE(this, NAN); |
year = (0 <= TO_INTEGER(year) && TO_INTEGER(year) <= 99) |
? 1900 + TO_INTEGER(year) : year; |