Bug 579471 - fast constructors (r=dmandelin,lw)
This commit is contained in:
@@ -484,7 +484,8 @@ msFromTime(jsdouble t)
|
||||
Class js_DateClass = {
|
||||
js_Date_str,
|
||||
JSCLASS_HAS_RESERVED_SLOTS(JSObject::DATE_FIXED_RESERVED_SLOTS) |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Date),
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Date) |
|
||||
JSCLASS_FAST_CONSTRUCTOR,
|
||||
PropertyStub, /* addProperty */
|
||||
PropertyStub, /* delProperty */
|
||||
PropertyStub, /* getProperty */
|
||||
@@ -2302,28 +2303,28 @@ static JSFunctionSpec date_methods[] = {
|
||||
};
|
||||
|
||||
JSBool
|
||||
js_Date(JSContext *cx, JSObject *obj, uintN argc, Value *argv, Value *rval)
|
||||
js_Date(JSContext *cx, uintN argc, Value *vp)
|
||||
{
|
||||
/* Date called as function. */
|
||||
if (!JS_IsConstructing(cx))
|
||||
return date_format(cx, NowAsMillis(), FORMATSPEC_FULL, rval);
|
||||
if (!vp[1].isMagic(JS_FAST_CONSTRUCTOR))
|
||||
return date_format(cx, NowAsMillis(), FORMATSPEC_FULL, vp);
|
||||
|
||||
/* Date called as constructor. */
|
||||
jsdouble d;
|
||||
if (argc == 0) {
|
||||
d = NowAsMillis();
|
||||
} else if (argc == 1) {
|
||||
if (!argv[0].isString()) {
|
||||
if (!vp[2].isString()) {
|
||||
/* the argument is a millisecond number */
|
||||
if (!ValueToNumber(cx, argv[0], &d))
|
||||
if (!ValueToNumber(cx, vp[2], &d))
|
||||
return JS_FALSE;
|
||||
d = TIMECLIP(d);
|
||||
} else {
|
||||
/* the argument is a string; parse it. */
|
||||
JSString *str = js_ValueToString(cx, argv[0]);
|
||||
JSString *str = js_ValueToString(cx, vp[2]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
argv[0].setString(str);
|
||||
vp[2].setString(str);
|
||||
|
||||
if (!date_parseString(str, &d, cx))
|
||||
d = js_NaN;
|
||||
@@ -2332,7 +2333,7 @@ js_Date(JSContext *cx, JSObject *obj, uintN argc, Value *argv, Value *rval)
|
||||
}
|
||||
} else {
|
||||
jsdouble msec_time;
|
||||
if (!date_msecFromArgs(cx, argc, argv, &msec_time))
|
||||
if (!date_msecFromArgs(cx, argc, vp + 2, &msec_time))
|
||||
return JS_FALSE;
|
||||
|
||||
if (JSDOUBLE_IS_FINITE(msec_time)) {
|
||||
@@ -2341,7 +2342,13 @@ js_Date(JSContext *cx, JSObject *obj, uintN argc, Value *argv, Value *rval)
|
||||
}
|
||||
d = msec_time;
|
||||
}
|
||||
return SetUTCTime(cx, obj, d);
|
||||
|
||||
JSObject *obj = js_NewDateObjectMsec(cx, d);
|
||||
if (!obj)
|
||||
return JS_FALSE;
|
||||
vp->setObject(*obj);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSObject *
|
||||
@@ -2349,7 +2356,7 @@ js_InitDateClass(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
/* set static LocalTZA */
|
||||
LocalTZA = -(PRMJ_LocalGMTDifference() * msPerSecond);
|
||||
JSObject *proto = js_InitClass(cx, obj, NULL, &js_DateClass, js_Date, MAXARGS,
|
||||
JSObject *proto = js_InitClass(cx, obj, NULL, &js_DateClass, (Native) js_Date, MAXARGS,
|
||||
NULL, date_methods, NULL, date_static_methods);
|
||||
if (!proto)
|
||||
return NULL;
|
||||
|
||||
Reference in New Issue
Block a user