Bug 1595745 - Part 9: Change Intl to use ClassSpec. r=mgaudet
☠☠ backed out by ec8cad689121 ☠ ☠
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 15 Nov 2019 15:04:27 +0000
changeset 502203 29ec5ccb4adf6d914edf9fb7dfaf9f362a902455
parent 502202 3b0e242d762a12cdcb16a0e9f2ac60ce3af21833
child 502204 a514661afdda948c4fb0917375534f06a82ff5b0
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1595745
milestone72.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 1595745 - Part 9: Change Intl to use ClassSpec. r=mgaudet Differential Revision: https://phabricator.services.mozilla.com/D52665
js/public/ProtoKey.h
js/src/builtin/intl/IntlObject.cpp
js/src/builtin/intl/IntlObject.h
--- a/js/public/ProtoKey.h
+++ b/js/public/ProtoKey.h
@@ -88,17 +88,17 @@
   REAL(BigInt, InitViaClassSpec, OCLASP(BigInt))                             \
   REAL(Proxy, InitProxyClass, &js::ProxyClass)                               \
   REAL(WeakMap, InitViaClassSpec, OCLASP(WeakMap))                           \
   REAL(Map, InitViaClassSpec, OCLASP(Map))                                   \
   REAL(Set, InitViaClassSpec, OCLASP(Set))                                   \
   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))                     \
   REAL_IF_INTL(ListFormat, InitViaClassSpec, OCLASP(ListFormat))             \
   REAL_IF_INTL(NumberFormat, InitViaClassSpec, OCLASP(NumberFormat))         \
   REAL_IF_INTL(PluralRules, InitViaClassSpec, OCLASP(PluralRules))           \
   REAL_IF_INTL(RelativeTimeFormat, InitViaClassSpec,                         \
                OCLASP(RelativeTimeFormat))                                   \
--- a/js/src/builtin/intl/IntlObject.cpp
+++ b/js/src/builtin/intl/IntlObject.cpp
@@ -777,77 +777,65 @@ bool js::intl_supportedLocaleOrFallback(
       return false;
     }
   }
 
   args.rval().setString(candidate);
   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);
   return true;
 }
 
 static const JSFunctionSpec intl_static_methods[] = {
     JS_FN(js_toSource_str, intl_toSource, 0, 0),
     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;
   }
 
   // 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;
-  }
+  return NewObjectWithGivenProto(cx, &IntlClass, proto, SingletonObject);
+}
 
-  // Add the static functions.
-  if (!JS_DefineFunctions(cx, intl, intl_static_methods)) {
-    return nullptr;
-  }
-
+/**
+ * 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);
   for (const auto& protoKey :
        {JSProto_Collator, JSProto_DateTimeFormat, JSProto_NumberFormat,
         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;
-  }
+  return true;
+}
 
-  // 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));
+static const ClassSpec IntlClassSpec = {
+    CreateIntlObject, nullptr, intl_static_methods, nullptr,
+    nullptr,          nullptr, IntlClassFinish};
 
-  return intl;
-}
+const JSClass js::IntlClass = {js_Object_str,
+                               JSCLASS_HAS_CACHED_PROTO(JSProto_Intl),
+                               JS_NULL_CLASS_OPS, &IntlClassSpec};
--- a/js/src/builtin/intl/IntlObject.h
+++ b/js/src/builtin/intl/IntlObject.h
@@ -9,27 +9,19 @@
 
 #include "mozilla/Attributes.h"
 
 #include "js/RootingAPI.h"
 #include "js/TypeDecls.h"
 
 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
  * properties:
  *
  *   firstDayOfWeek
  *     an integer in the range 1=Sunday to 7=Saturday indicating the day
  *     considered the first day of the week in calendars, e.g. 1 for en-US,
  *     2 for en-GB, 1 for bn-IN