Bug 959013 - Convert the Date object to use ClassSpec. r=luke

This commit is contained in:
Bobby Holley 2014-02-04 07:51:54 -08:00
parent 460ab407b5
commit c6fb00a32a
3 changed files with 32 additions and 56 deletions

View File

@ -521,23 +521,6 @@ date_convert(JSContext *cx, HandleObject obj, JSType hint, MutableHandleValue vp
return DefaultValue(cx, obj, (hint == JSTYPE_VOID) ? JSTYPE_STRING : hint, vp);
}
/*
* Other Support routines and definitions
*/
const Class DateObject::class_ = {
js_Date_str,
JSCLASS_HAS_RESERVED_SLOTS(RESERVED_SLOTS) |
JSCLASS_HAS_CACHED_PROTO(JSProto_Date),
JS_PropertyStub, /* addProperty */
JS_DeletePropertyStub, /* delProperty */
JS_PropertyStub, /* getProperty */
JS_StrictPropertyStub, /* setProperty */
JS_EnumerateStub,
JS_ResolveStub,
date_convert
};
/* for use by date_parse */
static const char* const wtb[] = {
@ -3027,52 +3010,48 @@ js_Date(JSContext *cx, unsigned argc, Value *vp)
return true;
}
JSObject *
js_InitDateClass(JSContext *cx, HandleObject obj)
static bool
FinishDateClassInit(JSContext *cx, HandleObject ctor, HandleObject proto)
{
JS_ASSERT(obj->isNative());
Rooted<GlobalObject*> global(cx, &obj->as<GlobalObject>());
RootedObject dateProto(cx, global->createBlankPrototype(cx, &DateObject::class_));
if (!dateProto)
return nullptr;
dateProto->as<DateObject>().setUTCTime(GenericNaN());
RootedFunction ctor(cx);
ctor = global->createConstructor(cx, js_Date, cx->names().Date, MAXARGS);
if (!ctor)
return nullptr;
if (!LinkConstructorAndPrototype(cx, ctor, dateProto))
return nullptr;
if (!DefinePropertiesAndBrand(cx, ctor, nullptr, date_static_methods))
return nullptr;
proto->as<DateObject>().setUTCTime(GenericNaN());
/*
* Define all Date.prototype.* functions, then brand for trace-jitted code.
* Date.prototype.toGMTString has the same initial value as
* Date.prototype.toUTCString.
*/
if (!JS_DefineFunctions(cx, dateProto, date_methods))
return nullptr;
RootedValue toUTCStringFun(cx);
RootedId toUTCStringId(cx, NameToId(cx->names().toUTCString));
RootedId toGMTStringId(cx, NameToId(cx->names().toGMTString));
if (!baseops::GetProperty(cx, dateProto, toUTCStringId, &toUTCStringFun) ||
!baseops::DefineGeneric(cx, dateProto, toGMTStringId, toUTCStringFun,
JS_PropertyStub, JS_StrictPropertyStub, 0))
{
return nullptr;
}
if (!DefineConstructorAndPrototype(cx, global, JSProto_Date, ctor, dateProto))
return nullptr;
return dateProto;
return baseops::GetProperty(cx, proto, toUTCStringId, &toUTCStringFun) &&
baseops::DefineGeneric(cx, proto, toGMTStringId, toUTCStringFun,
JS_PropertyStub, JS_StrictPropertyStub, 0);
}
const Class DateObject::class_ = {
js_Date_str,
JSCLASS_HAS_RESERVED_SLOTS(RESERVED_SLOTS) |
JSCLASS_HAS_CACHED_PROTO(JSProto_Date),
JS_PropertyStub, /* addProperty */
JS_DeletePropertyStub, /* delProperty */
JS_PropertyStub, /* getProperty */
JS_StrictPropertyStub, /* setProperty */
JS_EnumerateStub,
JS_ResolveStub,
date_convert,
nullptr, /* finalize */
nullptr, /* call */
nullptr, /* hasInstance */
nullptr, /* construct */
nullptr, /* trace */
{
GenericCreateConstructor<js_Date, NAME_OFFSET(Date), MAXARGS>,
GenericCreatePrototype<&DateObject::class_>,
date_static_methods,
date_methods,
FinishDateClassInit
}
};
JS_FRIEND_API(JSObject *)
js_NewDateObjectMsec(JSContext *cx, double msec_time)
{

View File

@ -16,9 +16,6 @@
#include "js/RootingAPI.h"
#include "js/TypeDecls.h"
extern JSObject *
js_InitDateClass(JSContext *cx, JS::HandleObject obj);
/*
* These functions provide a C interface to the date/time object
*/

View File

@ -61,7 +61,7 @@
real(Array, 3, js_InitArrayClass, OCLASP(Array)) \
real(Boolean, 4, js_InitBooleanClass, OCLASP(Boolean)) \
real(JSON, 5, js_InitJSONClass, CLASP(JSON)) \
real(Date, 6, js_InitDateClass, OCLASP(Date)) \
real(Date, 6, js_InitViaClassSpec, OCLASP(Date)) \
real(Math, 7, js_InitMathClass, CLASP(Math)) \
real(Number, 8, js_InitNumberClass, OCLASP(Number)) \
real(String, 9, js_InitStringClass, OCLASP(String)) \