From c6fb00a32a7736e82b0f96e88d79788adb9dc7ca Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 4 Feb 2014 07:51:54 -0800 Subject: [PATCH] Bug 959013 - Convert the Date object to use ClassSpec. r=luke --- js/src/jsdate.cpp | 83 ++++++++++++++++--------------------------- js/src/jsdate.h | 3 -- js/src/jsprototypes.h | 2 +- 3 files changed, 32 insertions(+), 56 deletions(-) diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp index d9a3c7d1abf..4934446147c 100644 --- a/js/src/jsdate.cpp +++ b/js/src/jsdate.cpp @@ -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 global(cx, &obj->as()); - - RootedObject dateProto(cx, global->createBlankPrototype(cx, &DateObject::class_)); - if (!dateProto) - return nullptr; - dateProto->as().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().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, + GenericCreatePrototype<&DateObject::class_>, + date_static_methods, + date_methods, + FinishDateClassInit + } +}; + JS_FRIEND_API(JSObject *) js_NewDateObjectMsec(JSContext *cx, double msec_time) { diff --git a/js/src/jsdate.h b/js/src/jsdate.h index 028e64794e4..5a033174ef9 100644 --- a/js/src/jsdate.h +++ b/js/src/jsdate.h @@ -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 */ diff --git a/js/src/jsprototypes.h b/js/src/jsprototypes.h index 91fdffc7a81..f85f30782f0 100644 --- a/js/src/jsprototypes.h +++ b/js/src/jsprototypes.h @@ -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)) \