mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1288457 - Part 4: Change Intl.NumberFormat to use ClassSpec. r=mgaudet
Differential Revision: https://phabricator.services.mozilla.com/D42873 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
0ec985f2cc
commit
a10d581508
@ -750,7 +750,7 @@ static const uint32_t JSCLASS_FOREGROUND_FINALIZE =
|
||||
// application.
|
||||
static const uint32_t JSCLASS_GLOBAL_APPLICATION_SLOTS = 5;
|
||||
static const uint32_t JSCLASS_GLOBAL_SLOT_COUNT =
|
||||
JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 2 + 36;
|
||||
JSCLASS_GLOBAL_APPLICATION_SLOTS + JSProto_LIMIT * 2 + 34;
|
||||
|
||||
#define JSCLASS_GLOBAL_FLAGS_WITH_SLOTS(n) \
|
||||
(JSCLASS_IS_GLOBAL | \
|
||||
|
@ -132,7 +132,8 @@
|
||||
IMAGINARY(WasmGlobal, dummy, dummy) \
|
||||
REAL_IF_INTL(Collator, InitViaClassSpec, OCLASP(Collator)) \
|
||||
REAL_IF_INTL(DateTimeFormat, InitViaClassSpec, OCLASP(DateTimeFormat)) \
|
||||
REAL_IF_INTL(Locale, InitViaClassSpec, OCLASP(Locale))
|
||||
REAL_IF_INTL(Locale, InitViaClassSpec, OCLASP(Locale)) \
|
||||
REAL_IF_INTL(NumberFormat, InitViaClassSpec, OCLASP(NumberFormat))
|
||||
|
||||
#define JS_FOR_PROTOTYPES(REAL, IMAGINARY) \
|
||||
JS_FOR_PROTOTYPES_(REAL, IMAGINARY, IF_INTL(REAL, IMAGINARY), \
|
||||
|
@ -830,10 +830,7 @@ bool GlobalObject::initIntlObject(JSContext* cx, Handle<GlobalObject*> global) {
|
||||
if (!CreateDateTimeFormat(cx, intl)) {
|
||||
return false;
|
||||
}
|
||||
RootedObject numberFormatProto(cx), numberFormat(cx);
|
||||
numberFormatProto =
|
||||
CreateNumberFormatPrototype(cx, intl, global, &numberFormat);
|
||||
if (!numberFormatProto) {
|
||||
if (!CreateNumberFormat(cx, intl)) {
|
||||
return false;
|
||||
}
|
||||
RootedObject pluralRulesProto(cx,
|
||||
@ -863,8 +860,6 @@ bool GlobalObject::initIntlObject(JSContext* cx, Handle<GlobalObject*> global) {
|
||||
// |String.prototype| we have |JSProto_*| that enables
|
||||
// |getPrototype(JSProto_*)|, but that has global-object-property-related
|
||||
// baggage we don't need or want, so we use one-off reserved slots.
|
||||
global->setReservedSlot(NUMBER_FORMAT, ObjectValue(*numberFormat));
|
||||
global->setReservedSlot(NUMBER_FORMAT_PROTO, ObjectValue(*numberFormatProto));
|
||||
global->setReservedSlot(PLURAL_RULES_PROTO, ObjectValue(*pluralRulesProto));
|
||||
global->setReservedSlot(RELATIVE_TIME_FORMAT_PROTO,
|
||||
ObjectValue(*relativeTimeFmtProto));
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "unicode/ures.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "vm/BigIntType.h"
|
||||
#include "vm/GlobalObject.h"
|
||||
#include "vm/JSContext.h"
|
||||
#include "vm/SelfHosting.h"
|
||||
#include "vm/Stack.h"
|
||||
@ -76,7 +77,9 @@ const JSClass NumberFormatObject::class_ = {
|
||||
js_Object_str,
|
||||
JSCLASS_HAS_RESERVED_SLOTS(NumberFormatObject::SLOT_COUNT) |
|
||||
JSCLASS_FOREGROUND_FINALIZE,
|
||||
&NumberFormatObject::classOps_};
|
||||
&NumberFormatObject::classOps_, &NumberFormatObject::classSpec_};
|
||||
|
||||
const JSClass& NumberFormatObject::protoClass_ = PlainObject::class_;
|
||||
|
||||
static bool numberFormat_toSource(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
@ -99,6 +102,18 @@ static const JSPropertySpec numberFormat_properties[] = {
|
||||
JS_SELF_HOSTED_GET("format", "$Intl_NumberFormat_format_get", 0),
|
||||
JS_STRING_SYM_PS(toStringTag, "Object", JSPROP_READONLY), JS_PS_END};
|
||||
|
||||
static bool NumberFormat(JSContext* cx, unsigned argc, Value* vp);
|
||||
|
||||
const ClassSpec NumberFormatObject::classSpec_ = {
|
||||
GenericCreateConstructor<NumberFormat, 0, gc::AllocKind::FUNCTION>,
|
||||
GenericCreatePrototype<NumberFormatObject>,
|
||||
numberFormat_static_methods,
|
||||
nullptr,
|
||||
numberFormat_methods,
|
||||
numberFormat_properties,
|
||||
nullptr,
|
||||
ClassSpec::DontDefineConstructor};
|
||||
|
||||
/**
|
||||
* 11.2.1 Intl.NumberFormat([ locales [, options]])
|
||||
*
|
||||
@ -109,7 +124,8 @@ static bool NumberFormat(JSContext* cx, const CallArgs& args, bool construct) {
|
||||
|
||||
// Step 2 (Inlined 9.1.14, OrdinaryCreateFromConstructor).
|
||||
RootedObject proto(cx);
|
||||
if (!GetPrototypeFromBuiltinConstructor(cx, args, JSProto_Null, &proto)) {
|
||||
if (!GetPrototypeFromBuiltinConstructor(cx, args, JSProto_NumberFormat,
|
||||
&proto)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -167,49 +183,16 @@ void js::NumberFormatObject::finalize(JSFreeOp* fop, JSObject* obj) {
|
||||
}
|
||||
}
|
||||
|
||||
JSObject* js::CreateNumberFormatPrototype(JSContext* cx, HandleObject Intl,
|
||||
Handle<GlobalObject*> global,
|
||||
MutableHandleObject constructor) {
|
||||
RootedFunction ctor(cx);
|
||||
ctor = GlobalObject::createConstructor(cx, &NumberFormat,
|
||||
cx->names().NumberFormat, 0);
|
||||
bool js::CreateNumberFormat(JSContext* cx, HandleObject Intl) {
|
||||
JSObject* ctor =
|
||||
GlobalObject::getOrCreateConstructor(cx, JSProto_NumberFormat);
|
||||
if (!ctor) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RootedObject proto(
|
||||
cx, GlobalObject::createBlankPrototype<PlainObject>(cx, global));
|
||||
if (!proto) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!LinkConstructorAndPrototype(cx, ctor, proto)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 11.3.2
|
||||
if (!JS_DefineFunctions(cx, ctor, numberFormat_static_methods)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 11.4.4
|
||||
if (!JS_DefineFunctions(cx, proto, numberFormat_methods)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 11.4.2 and 11.4.3
|
||||
if (!JS_DefineProperties(cx, proto, numberFormat_properties)) {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 8.1
|
||||
RootedValue ctorValue(cx, ObjectValue(*ctor));
|
||||
if (!DefineDataProperty(cx, Intl, cx->names().NumberFormat, ctorValue, 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
constructor.set(ctor);
|
||||
return proto;
|
||||
return DefineDataProperty(cx, Intl, cx->names().NumberFormat, ctorValue, 0);
|
||||
}
|
||||
|
||||
bool js::intl_numberingSystem(JSContext* cx, unsigned argc, Value* vp) {
|
||||
|
@ -23,11 +23,10 @@ struct UNumberFormatter;
|
||||
|
||||
namespace js {
|
||||
|
||||
class ArrayObject;
|
||||
|
||||
class NumberFormatObject : public NativeObject {
|
||||
public:
|
||||
static const JSClass class_;
|
||||
static const JSClass& protoClass_;
|
||||
|
||||
static constexpr uint32_t INTERNALS_SLOT = 0;
|
||||
static constexpr uint32_t UNUMBER_FORMATTER_SLOT = 1;
|
||||
@ -64,13 +63,12 @@ class NumberFormatObject : public NativeObject {
|
||||
|
||||
private:
|
||||
static const JSClassOps classOps_;
|
||||
static const ClassSpec classSpec_;
|
||||
|
||||
static void finalize(JSFreeOp* fop, JSObject* obj);
|
||||
};
|
||||
|
||||
extern JSObject* CreateNumberFormatPrototype(JSContext* cx, HandleObject Intl,
|
||||
Handle<GlobalObject*> global,
|
||||
MutableHandleObject constructor);
|
||||
extern bool CreateNumberFormat(JSContext* cx, HandleObject Intl);
|
||||
|
||||
/**
|
||||
* Returns a new instance of the standard built-in NumberFormat constructor.
|
||||
|
@ -313,7 +313,6 @@
|
||||
MACRO(noStack, noStack, "noStack") \
|
||||
MACRO(notation, notation, "notation") \
|
||||
MACRO(notes, notes, "notes") \
|
||||
MACRO(NumberFormat, NumberFormat, "NumberFormat") \
|
||||
MACRO(numberingSystem, numberingSystem, "numberingSystem") \
|
||||
MACRO(numeric, numeric, "numeric") \
|
||||
MACRO(objectArguments, objectArguments, "[object Arguments]") \
|
||||
|
@ -18,6 +18,7 @@
|
||||
# include "builtin/intl/Collator.h"
|
||||
# include "builtin/intl/DateTimeFormat.h"
|
||||
# include "builtin/intl/Locale.h"
|
||||
# include "builtin/intl/NumberFormat.h"
|
||||
#endif
|
||||
#include "builtin/MapObject.h"
|
||||
#include "builtin/ModuleObject.h"
|
||||
|
@ -88,8 +88,6 @@ class GlobalObject : public NativeObject {
|
||||
ASYNC_GENERATOR_PROTO,
|
||||
MAP_ITERATOR_PROTO,
|
||||
SET_ITERATOR_PROTO,
|
||||
NUMBER_FORMAT,
|
||||
NUMBER_FORMAT_PROTO,
|
||||
PLURAL_RULES_PROTO,
|
||||
RELATIVE_TIME_FORMAT_PROTO,
|
||||
MODULE_PROTO,
|
||||
@ -508,14 +506,20 @@ class GlobalObject : public NativeObject {
|
||||
|
||||
static JSFunction* getOrCreateNumberFormatConstructor(
|
||||
JSContext* cx, Handle<GlobalObject*> global) {
|
||||
JSObject* obj =
|
||||
getOrCreateObject(cx, global, NUMBER_FORMAT, initIntlObject);
|
||||
return obj ? &obj->as<JSFunction>() : nullptr;
|
||||
if (!ensureConstructor(cx, global, JSProto_NumberFormat)) {
|
||||
return nullptr;
|
||||
}
|
||||
return &global->getConstructor(JSProto_NumberFormat)
|
||||
.toObject()
|
||||
.as<JSFunction>();
|
||||
}
|
||||
|
||||
static JSObject* getOrCreateNumberFormatPrototype(
|
||||
JSContext* cx, Handle<GlobalObject*> global) {
|
||||
return getOrCreateObject(cx, global, NUMBER_FORMAT_PROTO, initIntlObject);
|
||||
if (!ensureConstructor(cx, global, JSProto_NumberFormat)) {
|
||||
return nullptr;
|
||||
}
|
||||
return &global->getPrototype(JSProto_NumberFormat).toObject();
|
||||
}
|
||||
|
||||
static JSFunction* getOrCreateDateTimeFormatConstructor(
|
||||
|
Loading…
Reference in New Issue
Block a user