Bug 1437842: [Part 8] Convert IsPluralRules to GuardToPluralRules r=jandem
authorMatthew Gaudet <mgaudet@mozilla.com>
Mon, 23 Apr 2018 14:28:51 -0400
changeset 460778 8206293b20c04d052b270d38d2586270dbfddce4
parent 460777 bcbac9c78599b1e48b2e868ccb15c6b2d9bdd151
child 460779 314bb18aab5237c69deeb216196eb165790c7dfb
push id165
push userfmarier@mozilla.com
push dateMon, 30 Apr 2018 23:50:51 +0000
reviewersjandem
bugs1437842
milestone61.0a1
Bug 1437842: [Part 8] Convert IsPluralRules to GuardToPluralRules r=jandem
js/src/builtin/intl/CommonFunctions.js
js/src/builtin/intl/PluralRules.js
js/src/jit/InlinableNatives.h
js/src/jit/MCallOptimize.cpp
js/src/vm/SelfHosting.cpp
--- a/js/src/builtin/intl/CommonFunctions.js
+++ b/js/src/builtin/intl/CommonFunctions.js
@@ -1442,18 +1442,18 @@ function intlFallbackSymbol() {
 /**
  * Initializes the INTL_INTERNALS_OBJECT_SLOT of the given object.
  */
 function initializeIntlObject(obj, type, lazyData) {
     assert(IsObject(obj), "Non-object passed to initializeIntlObject");
     assert((type === "Collator" && GuardToCollator(obj) !== null) ||
            (type === "DateTimeFormat" && GuardToDateTimeFormat(obj) !== null) ||
            (type === "NumberFormat" && GuardToNumberFormat(obj) !== null) ||
-           (type === "PluralRules" && IsPluralRules(obj)) ||
            (type === "RelativeTimeFormat" && IsRelativeTimeFormat(obj)),
+           (type === "PluralRules" && GuardToPluralRules(obj) !== null) ||
            "type must match the object's class");
     assert(IsObject(lazyData), "non-object lazy data");
 
     // The meaning of an internals object for an object |obj| is as follows.
     //
     // The .type property indicates the type of Intl object that |obj| is:
     // "Collator", "DateTimeFormat", "NumberFormat", or "PluralRules" (likely
     // with more coming in future Intl specs).
@@ -1508,29 +1508,29 @@ function maybeInternalProperties(interna
  *
  * Spec: ECMAScript Internationalization API Specification, 10.3.
  * Spec: ECMAScript Internationalization API Specification, 11.3.
  * Spec: ECMAScript Internationalization API Specification, 12.3.
  */
 function getIntlObjectInternals(obj) {
     assert(IsObject(obj), "getIntlObjectInternals called with non-Object");
     assert(GuardToCollator(obj) !== null || GuardToDateTimeFormat(obj) !== null ||
-           GuardToNumberFormat(obj) !== null || IsPluralRules(obj) ||
            IsRelativeTimeFormat(obj),
+           GuardToNumberFormat(obj) !== null || GuardToPluralRules(obj) !== null ||
            "getIntlObjectInternals called with non-Intl object");
 
     var internals = UnsafeGetReservedSlot(obj, INTL_INTERNALS_OBJECT_SLOT);
 
     assert(IsObject(internals), "internals not an object");
     assert(hasOwn("type", internals), "missing type");
     assert((internals.type === "Collator" && GuardToCollator(obj) !== null) ||
            (internals.type === "DateTimeFormat" && GuardToDateTimeFormat(obj) !== null) ||
            (internals.type === "NumberFormat" && GuardToNumberFormat(obj) !== null) ||
-           (internals.type === "PluralRules" && IsPluralRules(obj)) ||
            (internals.type === "RelativeTimeFormat" && IsRelativeTimeFormat(obj)),
+           (internals.type === "PluralRules" && GuardToPluralRules(obj) !== null) ||
            "type must match the object's class");
     assert(hasOwn("lazyData", internals), "missing lazyData");
     assert(hasOwn("internalProps", internals), "missing internalProps");
 
     return internals;
 }
 
 /**
--- a/js/src/builtin/intl/PluralRules.js
+++ b/js/src/builtin/intl/PluralRules.js
@@ -73,17 +73,17 @@ function resolvePluralRulesInternals(laz
     return internalProps;
 }
 
 /**
  * Returns an object containing the PluralRules internal properties of |obj|.
  */
 function getPluralRulesInternals(obj) {
     assert(IsObject(obj), "getPluralRulesInternals called with non-object");
-    assert(IsPluralRules(obj), "getPluralRulesInternals called with non-PluralRules");
+    assert(GuardToPluralRules(obj) !== null, "getPluralRulesInternals called with non-PluralRules");
 
     var internals = getIntlObjectInternals(obj);
     assert(internals.type === "PluralRules", "bad type escaped getIntlObjectInternals");
 
     var internalProps = maybeInternalProperties(internals);
     if (internalProps)
         return internalProps;
 
@@ -100,17 +100,17 @@ function getPluralRulesInternals(obj) {
  * all the work we can until the object is actually used as a PluralRules.
  * This later work occurs in |resolvePluralRulesInternals|; steps not noted
  * here occur there.
  *
  * Spec: ECMAScript 402 API, PluralRules, 13.1.1.
  */
 function InitializePluralRules(pluralRules, locales, options) {
     assert(IsObject(pluralRules), "InitializePluralRules called with non-object");
-    assert(IsPluralRules(pluralRules), "InitializePluralRules called with non-PluralRules");
+    assert(GuardToPluralRules(pluralRules) !== null, "InitializePluralRules called with non-PluralRules");
 
     // Lazy PluralRules data has the following structure:
     //
     //   {
     //     requestedLocales: List of locales,
     //     type: "cardinal" / "ordinal",
     //
     //     opt: // opt object computer in InitializePluralRules
@@ -191,17 +191,17 @@ function Intl_PluralRules_supportedLocal
  *
  * Spec: ECMAScript 402 API, PluralRules, 13.4.3.
  */
 function Intl_PluralRules_select(value) {
     // Step 1.
     let pluralRules = this;
 
     // Steps 2-3.
-    if (!IsObject(pluralRules) || !IsPluralRules(pluralRules))
+    if (!IsObject(pluralRules) || (pluralRules = GuardToPluralRules(pluralRules)) === null)
         ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "PluralRules", "select", "PluralRules");
 
     // Ensure the PluralRules internals are resolved.
     getPluralRulesInternals(pluralRules);
 
     // Step 4.
     let n = ToNumber(value);
 
@@ -214,17 +214,17 @@ function Intl_PluralRules_select(value) 
  *
  * Spec: ECMAScript 402 API, PluralRules, 13.4.4.
  */
 function Intl_PluralRules_resolvedOptions() {
     // Step 1.
     var pluralRules = this;
 
     // Steps 2-3.
-    if (!IsObject(pluralRules) || !IsPluralRules(pluralRules)) {
+    if (!IsObject(pluralRules) || (pluralRules = GuardToPluralRules(pluralRules)) === null) {
         ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "PluralRules", "resolvedOptions",
                        "PluralRules");
     }
 
     var internals = getPluralRulesInternals(pluralRules);
 
     var internalsPluralCategories = internals.pluralCategories;
     if (internalsPluralCategories === null) {
--- a/js/src/jit/InlinableNatives.h
+++ b/js/src/jit/InlinableNatives.h
@@ -27,18 +27,18 @@
     _(AtomicsXor)                   \
     _(AtomicsIsLockFree)            \
                                     \
     _(Boolean)                      \
                                     \
     _(IntlGuardToCollator)          \
     _(IntlGuardToDateTimeFormat)    \
     _(IntlGuardToNumberFormat)      \
-    _(IntlIsPluralRules)            \
     _(IntlIsRelativeTimeFormat)     \
+    _(IntlGuardToPluralRules)       \
                                     \
     _(MathAbs)                      \
     _(MathFloor)                    \
     _(MathCeil)                     \
     _(MathRound)                    \
     _(MathClz32)                    \
     _(MathSqrt)                     \
     _(MathATan2)                    \
--- a/js/src/jit/MCallOptimize.cpp
+++ b/js/src/jit/MCallOptimize.cpp
@@ -120,20 +120,20 @@ IonBuilder::inlineNativeCall(CallInfo& c
 
       // Intl natives.
       case InlinableNative::IntlGuardToCollator:
         return inlineGuardToClass(callInfo, &CollatorObject::class_);
       case InlinableNative::IntlGuardToDateTimeFormat:
         return inlineGuardToClass(callInfo, &DateTimeFormatObject::class_);
       case InlinableNative::IntlGuardToNumberFormat:
         return inlineGuardToClass(callInfo, &NumberFormatObject::class_);
-      case InlinableNative::IntlIsPluralRules:
-        return inlineHasClass(callInfo, &PluralRulesObject::class_);
       case InlinableNative::IntlIsRelativeTimeFormat:
         return inlineHasClass(callInfo, &RelativeTimeFormatObject::class_);
+      case InlinableNative::IntlGuardToPluralRules:
+        return inlineGuardToClass(callInfo, &PluralRulesObject::class_);
 
       // Math natives.
       case InlinableNative::MathAbs:
         return inlineMathAbs(callInfo);
       case InlinableNative::MathFloor:
         return inlineMathFloor(callInfo);
       case InlinableNative::MathCeil:
         return inlineMathCeil(callInfo);
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -2567,22 +2567,22 @@ static const JSFunctionSpec intrinsic_fu
                     intrinsic_GuardToBuiltin<CollatorObject>, 1,0,
                     IntlGuardToCollator),
     JS_INLINABLE_FN("GuardToDateTimeFormat",
                     intrinsic_GuardToBuiltin<DateTimeFormatObject>, 1,0,
                     IntlGuardToDateTimeFormat),
     JS_INLINABLE_FN("GuardToNumberFormat",
                     intrinsic_GuardToBuiltin<NumberFormatObject>, 1,0,
                     IntlGuardToNumberFormat),
-    JS_INLINABLE_FN("IsPluralRules",
-                    intrinsic_IsInstanceOfBuiltin<PluralRulesObject>, 1,0,
-                    IntlIsPluralRules),
     JS_INLINABLE_FN("IsRelativeTimeFormat",
                     intrinsic_IsInstanceOfBuiltin<RelativeTimeFormatObject>, 1,0,
                     IntlIsRelativeTimeFormat),
+    JS_INLINABLE_FN("GuardToPluralRules",
+                    intrinsic_GuardToBuiltin<PluralRulesObject>, 1,0,
+                    IntlGuardToPluralRules),
     JS_FN("GetDateTimeFormatConstructor",
           intrinsic_GetBuiltinIntlConstructor<GlobalObject::getOrCreateDateTimeFormatConstructor>,
           0,0),
     JS_FN("GetNumberFormatConstructor",
           intrinsic_GetBuiltinIntlConstructor<GlobalObject::getOrCreateNumberFormatConstructor>,
           0,0),
 
     JS_FN("GetOwnPropertyDescriptorToArray", GetOwnPropertyDescriptorToArray, 2,0),