Bug 1288457 - Part 10: Use cached proto mechanism for Intl classes. r=mgaudet
☠☠ backed out by 0762557d4a99 ☠ ☠
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 15 Oct 2019 17:22:20 +0000
changeset 559158 c743e9d10ae5029b11404600770a9035d517a458
parent 559157 13369226eaca4e822f64bf2710f7fa66c42a4178
child 559159 19625261f55a278f8d0d36b05f720056f86dbd84
push id12175
push userccoroiu@mozilla.com
push dateThu, 17 Oct 2019 19:29:09 +0000
treeherdermozilla-beta@d333b6ef1fd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1288457
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1288457 - Part 10: Use cached proto mechanism for Intl classes. r=mgaudet This allows to replace `NewObjectWithGivenProto` with `NewObjectWithClassProto`, which aligns Intl code with the rest of the non-Intl built-ins. Differential Revision: https://phabricator.services.mozilla.com/D42880
js/src/builtin/intl/Collator.cpp
js/src/builtin/intl/DateTimeFormat.cpp
js/src/builtin/intl/Locale.cpp
js/src/builtin/intl/NumberFormat.cpp
js/src/builtin/intl/PluralRules.cpp
js/src/builtin/intl/RelativeTimeFormat.cpp
--- a/js/src/builtin/intl/Collator.cpp
+++ b/js/src/builtin/intl/Collator.cpp
@@ -47,16 +47,17 @@ const JSClassOps CollatorObject::classOp
                                               nullptr, /* newEnumerate */
                                               nullptr, /* resolve */
                                               nullptr, /* mayResolve */
                                               CollatorObject::finalize};
 
 const JSClass CollatorObject::class_ = {
     js_Object_str,
     JSCLASS_HAS_RESERVED_SLOTS(CollatorObject::SLOT_COUNT) |
+        JSCLASS_HAS_CACHED_PROTO(JSProto_Collator) |
         JSCLASS_FOREGROUND_FINALIZE,
     &CollatorObject::classOps_, &CollatorObject::classSpec_};
 
 const JSClass& CollatorObject::protoClass_ = PlainObject::class_;
 
 static bool collator_toSource(JSContext* cx, unsigned argc, Value* vp) {
   CallArgs args = CallArgsFromVp(argc, vp);
   args.rval().setString(cx->names().Collator);
@@ -97,25 +98,18 @@ static bool Collator(JSContext* cx, cons
   // Step 1 (Handled by OrdinaryCreateFromConstructor fallback code).
 
   // Steps 2-5 (Inlined 9.1.14, OrdinaryCreateFromConstructor).
   RootedObject proto(cx);
   if (!GetPrototypeFromBuiltinConstructor(cx, args, JSProto_Collator, &proto)) {
     return false;
   }
 
-  if (!proto) {
-    proto = GlobalObject::getOrCreateCollatorPrototype(cx, cx->global());
-    if (!proto) {
-      return false;
-    }
-  }
-
   Rooted<CollatorObject*> collator(
-      cx, NewObjectWithGivenProto<CollatorObject>(cx, proto));
+      cx, NewObjectWithClassProto<CollatorObject>(cx, proto));
   if (!collator) {
     return false;
   }
 
   HandleValue locales = args.get(0);
   HandleValue options = args.get(1);
 
   // Step 6.
--- a/js/src/builtin/intl/DateTimeFormat.cpp
+++ b/js/src/builtin/intl/DateTimeFormat.cpp
@@ -58,16 +58,17 @@ const JSClassOps DateTimeFormatObject::c
     nullptr, /* newEnumerate */
     nullptr, /* resolve */
     nullptr, /* mayResolve */
     DateTimeFormatObject::finalize};
 
 const JSClass DateTimeFormatObject::class_ = {
     js_Object_str,
     JSCLASS_HAS_RESERVED_SLOTS(DateTimeFormatObject::SLOT_COUNT) |
+        JSCLASS_HAS_CACHED_PROTO(JSProto_DateTimeFormat) |
         JSCLASS_FOREGROUND_FINALIZE,
     &DateTimeFormatObject::classOps_, &DateTimeFormatObject::classSpec_};
 
 const JSClass& DateTimeFormatObject::protoClass_ = PlainObject::class_;
 
 static bool dateTimeFormat_toSource(JSContext* cx, unsigned argc, Value* vp) {
   CallArgs args = CallArgsFromVp(argc, vp);
   args.rval().setString(cx->names().DateTimeFormat);
@@ -115,25 +116,18 @@ static bool DateTimeFormat(JSContext* cx
   JSProtoKey protoKey = dtfOptions == DateTimeFormatOptions::Standard
                             ? JSProto_DateTimeFormat
                             : JSProto_Null;
   RootedObject proto(cx);
   if (!GetPrototypeFromBuiltinConstructor(cx, args, protoKey, &proto)) {
     return false;
   }
 
-  if (!proto) {
-    proto = GlobalObject::getOrCreateDateTimeFormatPrototype(cx, cx->global());
-    if (!proto) {
-      return false;
-    }
-  }
-
   Rooted<DateTimeFormatObject*> dateTimeFormat(cx);
-  dateTimeFormat = NewObjectWithGivenProto<DateTimeFormatObject>(cx, proto);
+  dateTimeFormat = NewObjectWithClassProto<DateTimeFormatObject>(cx, proto);
   if (!dateTimeFormat) {
     return false;
   }
 
   RootedValue thisValue(
       cx, construct ? ObjectValue(*dateTimeFormat) : args.thisv());
   HandleValue locales = args.get(0);
   HandleValue options = args.get(1);
--- a/js/src/builtin/intl/Locale.cpp
+++ b/js/src/builtin/intl/Locale.cpp
@@ -41,17 +41,19 @@
 
 using namespace js;
 using namespace js::intl::LanguageTagLimits;
 
 using intl::LanguageTag;
 using intl::LanguageTagParser;
 
 const JSClass LocaleObject::class_ = {
-    js_Object_str, JSCLASS_HAS_RESERVED_SLOTS(LocaleObject::SLOT_COUNT),
+    js_Object_str,
+    JSCLASS_HAS_RESERVED_SLOTS(LocaleObject::SLOT_COUNT) |
+        JSCLASS_HAS_CACHED_PROTO(JSProto_Locale),
     JS_NULL_CLASS_OPS, &LocaleObject::classSpec_};
 
 const JSClass& LocaleObject::protoClass_ = PlainObject::class_;
 
 static inline bool IsLocale(HandleValue v) {
   return v.isObject() && v.toObject().is<LocaleObject>();
 }
 
@@ -95,24 +97,16 @@ static mozilla::Maybe<IndexAndLength> Un
     // Add +1 to skip over the preceding separator.
     index += 1 + extensionLength;
   }
   return mozilla::Nothing();
 }
 
 static LocaleObject* CreateLocaleObject(JSContext* cx, HandleObject prototype,
                                         const LanguageTag& tag) {
-  RootedObject proto(cx, prototype);
-  if (!proto) {
-    proto = GlobalObject::getOrCreateLocalePrototype(cx, cx->global());
-    if (!proto) {
-      return nullptr;
-    }
-  }
-
   RootedString tagStr(cx, tag.toString(cx));
   if (!tagStr) {
     return nullptr;
   }
 
   size_t baseNameLength = BaseNameLength(tag);
 
   RootedString baseName(cx, NewDependentString(cx, tagStr, 0, baseNameLength));
@@ -126,17 +120,17 @@ static LocaleObject* CreateLocaleObject(
         cx, tagStr, baseNameLength + 1 + result->index, result->length);
     if (!str) {
       return nullptr;
     }
 
     unicodeExtension.setString(str);
   }
 
-  auto* locale = NewObjectWithGivenProto<LocaleObject>(cx, proto);
+  auto* locale = NewObjectWithClassProto<LocaleObject>(cx, prototype);
   if (!locale) {
     return nullptr;
   }
 
   locale->setFixedSlot(LocaleObject::LANGUAGE_TAG_SLOT, StringValue(tagStr));
   locale->setFixedSlot(LocaleObject::BASENAME_SLOT, StringValue(baseName));
   locale->setFixedSlot(LocaleObject::UNICODE_EXTENSION_SLOT, unicodeExtension);
 
--- a/js/src/builtin/intl/NumberFormat.cpp
+++ b/js/src/builtin/intl/NumberFormat.cpp
@@ -71,16 +71,17 @@ const JSClassOps NumberFormatObject::cla
                                                   nullptr, /* newEnumerate */
                                                   nullptr, /* resolve */
                                                   nullptr, /* mayResolve */
                                                   NumberFormatObject::finalize};
 
 const JSClass NumberFormatObject::class_ = {
     js_Object_str,
     JSCLASS_HAS_RESERVED_SLOTS(NumberFormatObject::SLOT_COUNT) |
+        JSCLASS_HAS_CACHED_PROTO(JSProto_NumberFormat) |
         JSCLASS_FOREGROUND_FINALIZE,
     &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);
   args.rval().setString(cx->names().NumberFormat);
@@ -124,25 +125,18 @@ static bool NumberFormat(JSContext* cx, 
 
   // Step 2 (Inlined 9.1.14, OrdinaryCreateFromConstructor).
   RootedObject proto(cx);
   if (!GetPrototypeFromBuiltinConstructor(cx, args, JSProto_NumberFormat,
                                           &proto)) {
     return false;
   }
 
-  if (!proto) {
-    proto = GlobalObject::getOrCreateNumberFormatPrototype(cx, cx->global());
-    if (!proto) {
-      return false;
-    }
-  }
-
   Rooted<NumberFormatObject*> numberFormat(cx);
-  numberFormat = NewObjectWithGivenProto<NumberFormatObject>(cx, proto);
+  numberFormat = NewObjectWithClassProto<NumberFormatObject>(cx, proto);
   if (!numberFormat) {
     return false;
   }
 
   RootedValue thisValue(cx,
                         construct ? ObjectValue(*numberFormat) : args.thisv());
   HandleValue locales = args.get(0);
   HandleValue options = args.get(1);
--- a/js/src/builtin/intl/PluralRules.cpp
+++ b/js/src/builtin/intl/PluralRules.cpp
@@ -43,16 +43,17 @@ const JSClassOps PluralRulesObject::clas
                                                  nullptr, /* newEnumerate */
                                                  nullptr, /* resolve */
                                                  nullptr, /* mayResolve */
                                                  PluralRulesObject::finalize};
 
 const JSClass PluralRulesObject::class_ = {
     js_Object_str,
     JSCLASS_HAS_RESERVED_SLOTS(PluralRulesObject::SLOT_COUNT) |
+        JSCLASS_HAS_CACHED_PROTO(JSProto_PluralRules) |
         JSCLASS_FOREGROUND_FINALIZE,
     &PluralRulesObject::classOps_, &PluralRulesObject::classSpec_};
 
 const JSClass& PluralRulesObject::protoClass_ = PlainObject::class_;
 
 static bool pluralRules_toSource(JSContext* cx, unsigned argc, Value* vp) {
   CallArgs args = CallArgsFromVp(argc, vp);
   args.rval().setString(cx->names().PluralRules);
@@ -96,25 +97,18 @@ static bool PluralRules(JSContext* cx, u
 
   // Step 2 (Inlined 9.1.14, OrdinaryCreateFromConstructor).
   RootedObject proto(cx);
   if (!GetPrototypeFromBuiltinConstructor(cx, args, JSProto_PluralRules,
                                           &proto)) {
     return false;
   }
 
-  if (!proto) {
-    proto = GlobalObject::getOrCreatePluralRulesPrototype(cx, cx->global());
-    if (!proto) {
-      return false;
-    }
-  }
-
   Rooted<PluralRulesObject*> pluralRules(cx);
-  pluralRules = NewObjectWithGivenProto<PluralRulesObject>(cx, proto);
+  pluralRules = NewObjectWithClassProto<PluralRulesObject>(cx, proto);
   if (!pluralRules) {
     return false;
   }
 
   HandleValue locales = args.get(0);
   HandleValue options = args.get(1);
 
   // Step 3.
--- a/js/src/builtin/intl/RelativeTimeFormat.cpp
+++ b/js/src/builtin/intl/RelativeTimeFormat.cpp
@@ -42,16 +42,17 @@ const JSClassOps RelativeTimeFormatObjec
     nullptr, /* newEnumerate */
     nullptr, /* resolve */
     nullptr, /* mayResolve */
     RelativeTimeFormatObject::finalize};
 
 const JSClass RelativeTimeFormatObject::class_ = {
     js_Object_str,
     JSCLASS_HAS_RESERVED_SLOTS(RelativeTimeFormatObject::SLOT_COUNT) |
+        JSCLASS_HAS_CACHED_PROTO(JSProto_RelativeTimeFormat) |
         JSCLASS_FOREGROUND_FINALIZE,
     &RelativeTimeFormatObject::classOps_,
     &RelativeTimeFormatObject::classSpec_};
 
 const JSClass& RelativeTimeFormatObject::protoClass_ = PlainObject::class_;
 
 static bool relativeTimeFormat_toSource(JSContext* cx, unsigned argc,
                                         Value* vp) {
@@ -105,27 +106,19 @@ static bool RelativeTimeFormat(JSContext
 
   // Step 2 (Inlined 9.1.14, OrdinaryCreateFromConstructor).
   RootedObject proto(cx);
   if (!GetPrototypeFromBuiltinConstructor(cx, args, JSProto_RelativeTimeFormat,
                                           &proto)) {
     return false;
   }
 
-  if (!proto) {
-    proto =
-        GlobalObject::getOrCreateRelativeTimeFormatPrototype(cx, cx->global());
-    if (!proto) {
-      return false;
-    }
-  }
-
   Rooted<RelativeTimeFormatObject*> relativeTimeFormat(cx);
   relativeTimeFormat =
-      NewObjectWithGivenProto<RelativeTimeFormatObject>(cx, proto);
+      NewObjectWithClassProto<RelativeTimeFormatObject>(cx, proto);
   if (!relativeTimeFormat) {
     return false;
   }
 
   HandleValue locales = args.get(0);
   HandleValue options = args.get(1);
 
   // Step 3.