зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1595745 - Part 9: Change Intl to use ClassSpec. r=mgaudet
Differential Revision: https://phabricator.services.mozilla.com/D52665 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
cc20d25168
Коммит
dfc558b12e
|
@ -93,7 +93,7 @@
|
|||
REAL(DataView, InitViaClassSpec, OCLASP(DataView)) \
|
||||
REAL(Symbol, InitViaClassSpec, OCLASP(Symbol)) \
|
||||
REAL(SharedArrayBuffer, InitViaClassSpec, OCLASP(SharedArrayBuffer)) \
|
||||
REAL_IF_INTL(Intl, InitIntlClass, CLASP(Intl)) \
|
||||
REAL_IF_INTL(Intl, InitViaClassSpec, CLASP(Intl)) \
|
||||
REAL_IF_INTL(Collator, InitViaClassSpec, OCLASP(Collator)) \
|
||||
REAL_IF_INTL(DateTimeFormat, InitViaClassSpec, OCLASP(DateTimeFormat)) \
|
||||
REAL_IF_INTL(Locale, InitViaClassSpec, OCLASP(Locale)) \
|
||||
|
|
|
@ -782,9 +782,6 @@ bool js::intl_supportedLocaleOrFallback(JSContext* cx, unsigned argc,
|
|||
return true;
|
||||
}
|
||||
|
||||
const JSClass js::IntlClass = {js_Object_str,
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Intl)};
|
||||
|
||||
static bool intl_toSource(JSContext* cx, unsigned argc, Value* vp) {
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
args.rval().setString(cx->names().Intl);
|
||||
|
@ -796,11 +793,8 @@ static const JSFunctionSpec intl_static_methods[] = {
|
|||
JS_SELF_HOSTED_FN("getCanonicalLocales", "Intl_getCanonicalLocales", 1, 0),
|
||||
JS_FS_END};
|
||||
|
||||
/**
|
||||
* Initializes the Intl Object and its standard built-in properties.
|
||||
* Spec: ECMAScript Internationalization API Specification, 8.0, 8.1
|
||||
*/
|
||||
JSObject* js::InitIntlClass(JSContext* cx, Handle<GlobalObject*> global) {
|
||||
static JSObject* CreateIntlObject(JSContext* cx, JSProtoKey key) {
|
||||
Handle<GlobalObject*> global = cx->global();
|
||||
RootedObject proto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global));
|
||||
if (!proto) {
|
||||
return nullptr;
|
||||
|
@ -808,17 +802,15 @@ JSObject* js::InitIntlClass(JSContext* cx, Handle<GlobalObject*> global) {
|
|||
|
||||
// The |Intl| object is just a plain object with some "static" function
|
||||
// properties and some constructor properties.
|
||||
RootedObject intl(
|
||||
cx, NewObjectWithGivenProto(cx, &IntlClass, proto, SingletonObject));
|
||||
if (!intl) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Add the static functions.
|
||||
if (!JS_DefineFunctions(cx, intl, intl_static_methods)) {
|
||||
return nullptr;
|
||||
}
|
||||
return NewObjectWithGivenProto(cx, &IntlClass, proto, SingletonObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Intl Object and its standard built-in properties.
|
||||
* Spec: ECMAScript Internationalization API Specification, 8.0, 8.1
|
||||
*/
|
||||
static bool IntlClassFinish(JSContext* cx, HandleObject intl,
|
||||
HandleObject proto) {
|
||||
// Add the constructor properties.
|
||||
RootedId ctorId(cx);
|
||||
RootedValue ctorValue(cx);
|
||||
|
@ -827,27 +819,23 @@ JSObject* js::InitIntlClass(JSContext* cx, Handle<GlobalObject*> global) {
|
|||
JSProto_PluralRules, JSProto_RelativeTimeFormat}) {
|
||||
JSObject* ctor = GlobalObject::getOrCreateConstructor(cx, protoKey);
|
||||
if (!ctor) {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
ctorId = NameToId(ClassName(protoKey, cx));
|
||||
ctorValue.setObject(*ctor);
|
||||
if (!DefineDataProperty(cx, intl, ctorId, ctorValue, 0)) {
|
||||
return nullptr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// The |Intl| object is fully set up now, so define the global property.
|
||||
RootedValue intlValue(cx, ObjectValue(*intl));
|
||||
if (!DefineDataProperty(cx, global, cx->names().Intl, intlValue,
|
||||
JSPROP_RESOLVING)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Also cache |Intl| to implement spec language that conditions behavior
|
||||
// based on values being equal to "the standard built-in |Intl| object".
|
||||
// Use |setConstructor| to correspond with |JSProto_Intl|.
|
||||
global->setConstructor(JSProto_Intl, ObjectValue(*intl));
|
||||
|
||||
return intl;
|
||||
return true;
|
||||
}
|
||||
|
||||
static const ClassSpec IntlClassSpec = {
|
||||
CreateIntlObject, nullptr, intl_static_methods, nullptr,
|
||||
nullptr, nullptr, IntlClassFinish};
|
||||
|
||||
const JSClass js::IntlClass = {js_Object_str,
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_Intl),
|
||||
JS_NULL_CLASS_OPS, &IntlClassSpec};
|
||||
|
|
|
@ -14,16 +14,8 @@
|
|||
|
||||
namespace js {
|
||||
|
||||
class GlobalObject;
|
||||
|
||||
extern const JSClass IntlClass;
|
||||
|
||||
/**
|
||||
* Initializes the Intl Object and its standard built-in properties.
|
||||
* Spec: ECMAScript Internationalization API Specification, 8.0, 8.1
|
||||
*/
|
||||
extern JSObject* InitIntlClass(JSContext* cx, JS::Handle<GlobalObject*> global);
|
||||
|
||||
/**
|
||||
* Returns a plain object with calendar information for a single valid locale
|
||||
* (callers must perform this validation). The object will have these
|
||||
|
|
Загрузка…
Ссылка в новой задаче