Bug 771742 - Refactor the date to-UTC-string methods to not use date_format_utc. r=luke

--HG--
extra : rebase_source : 3e56e0bcf6d26aa16e56a7558f21329d9bf48cf7
This commit is contained in:
Jeff Walden 2012-07-06 15:35:45 -07:00
parent b1883f8284
commit 98c18737fb

View File

@ -2436,12 +2436,14 @@ print_iso_string(char* buf, size_t size, double utctime)
msFromTime(utctime)); msFromTime(utctime));
} }
/* ES5 B.2.6. */
static JSBool static JSBool
date_utc_format(JSContext *cx, Native native, CallArgs args, date_toGMTString(JSContext *cx, unsigned argc, Value *vp)
void (*printFunc)(char*, size_t, double))
{ {
JSObject *thisObj; CallArgs args = CallArgsFromVp(argc, vp);
if (!NonGenericMethodGuard(cx, args, native, &DateClass, &thisObj))
Rooted<JSObject*> thisObj(cx);
if (!NonGenericMethodGuard(cx, args, date_toGMTString, &DateClass, thisObj.address()))
return false; return false;
if (!thisObj) if (!thisObj)
return true; return true;
@ -2449,16 +2451,10 @@ date_utc_format(JSContext *cx, Native native, CallArgs args,
double utctime = thisObj->getDateUTCTime().toNumber(); double utctime = thisObj->getDateUTCTime().toNumber();
char buf[100]; char buf[100];
if (!MOZ_DOUBLE_IS_FINITE(utctime)) { if (!MOZ_DOUBLE_IS_FINITE(utctime))
if (printFunc == print_iso_string) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INVALID_DATE);
return false;
}
JS_snprintf(buf, sizeof buf, js_NaN_date_str); JS_snprintf(buf, sizeof buf, js_NaN_date_str);
} else { else
(*printFunc)(buf, sizeof buf, utctime); print_gmt_string(buf, sizeof buf, utctime);
}
JSString *str = JS_NewStringCopyZ(cx, buf); JSString *str = JS_NewStringCopyZ(cx, buf);
if (!str) if (!str)
@ -2467,16 +2463,34 @@ date_utc_format(JSContext *cx, Native native, CallArgs args,
return true; return true;
} }
static JSBool /* ES5 15.9.5.43. */
date_toGMTString(JSContext *cx, unsigned argc, Value *vp)
{
return date_utc_format(cx, date_toGMTString, CallArgsFromVp(argc, vp), print_gmt_string);
}
static JSBool static JSBool
date_toISOString(JSContext *cx, unsigned argc, Value *vp) date_toISOString(JSContext *cx, unsigned argc, Value *vp)
{ {
return date_utc_format(cx, date_toISOString, CallArgsFromVp(argc, vp), print_iso_string); CallArgs args = CallArgsFromVp(argc, vp);
Rooted<JSObject*> thisObj(cx);
if (!NonGenericMethodGuard(cx, args, date_toISOString, &DateClass, thisObj.address()))
return false;
if (!thisObj)
return true;
double utctime = thisObj->getDateUTCTime().toNumber();
if (!MOZ_DOUBLE_IS_FINITE(utctime)) {
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_INVALID_DATE);
return false;
}
char buf[100];
print_iso_string(buf, sizeof buf, utctime);
JSString *str = JS_NewStringCopyZ(cx, buf);
if (!str)
return false;
args.rval().setString(str);
return true;
} }
/* ES5 15.9.5.44. */ /* ES5 15.9.5.44. */