Bug 1437842: [Part 6] Convert IsNumberFormat to GuardToNumberFormat r=jandem
authorMatthew Gaudet <mgaudet@mozilla.com>
Mon, 23 Apr 2018 11:07:04 -0400
changeset 471913 83ea97f7f8d3aca75d44c6818780cb3d42301d44
parent 471912 0993cb0d74e6e4466a4c19b8fe917714cce6546d
child 471914 bcbac9c78599b1e48b2e868ccb15c6b2d9bdd151
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1437842
milestone61.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 1437842: [Part 6] Convert IsNumberFormat to GuardToNumberFormat r=jandem
js/src/builtin/intl/CommonFunctions.js
js/src/builtin/intl/NumberFormat.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
@@ -1441,17 +1441,17 @@ 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" && IsDateTimeFormat(obj)) ||
-           (type === "NumberFormat" && IsNumberFormat(obj)) ||
+           (type === "NumberFormat" && GuardToNumberFormat(obj) !== null) ||
            (type === "PluralRules" && IsPluralRules(obj)) ||
            (type === "RelativeTimeFormat" && IsRelativeTimeFormat(obj)),
            "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:
@@ -1508,27 +1508,27 @@ 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 || IsDateTimeFormat(obj) ||
-           IsNumberFormat(obj) || IsPluralRules(obj) ||
+           GuardToNumberFormat(obj) !== null || IsPluralRules(obj) ||
            IsRelativeTimeFormat(obj),
            "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" && IsDateTimeFormat(obj)) ||
-           (internals.type === "NumberFormat" && IsNumberFormat(obj)) ||
+           (internals.type === "NumberFormat" && GuardToNumberFormat(obj) !== null) ||
            (internals.type === "PluralRules" && IsPluralRules(obj)) ||
            (internals.type === "RelativeTimeFormat" && IsRelativeTimeFormat(obj)),
            "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/NumberFormat.js
+++ b/js/src/builtin/intl/NumberFormat.js
@@ -83,17 +83,17 @@ function resolveNumberFormatInternals(la
     return internalProps;
 }
 
 /**
  * Returns an object containing the NumberFormat internal properties of |obj|.
  */
 function getNumberFormatInternals(obj) {
     assert(IsObject(obj), "getNumberFormatInternals called with non-object");
-    assert(IsNumberFormat(obj), "getNumberFormatInternals called with non-NumberFormat");
+    assert(GuardToNumberFormat(obj) !== null, "getNumberFormatInternals called with non-NumberFormat");
 
     var internals = getIntlObjectInternals(obj);
     assert(internals.type === "NumberFormat", "bad type escaped getIntlObjectInternals");
 
     // If internal properties have already been computed, use them.
     var internalProps = maybeInternalProperties(internals);
     if (internalProps)
         return internalProps;
@@ -106,21 +106,21 @@ function getNumberFormatInternals(obj) {
 
 /**
  * 11.1.11 UnwrapNumberFormat( nf )
  */
 function UnwrapNumberFormat(nf, methodName) {
     // Step 1 (not applicable in our implementation).
 
     // Step 2.
-    if (IsObject(nf) && !IsNumberFormat(nf) && nf instanceof GetNumberFormatConstructor())
+    if (IsObject(nf) && (GuardToNumberFormat(nf)) === null && nf instanceof GetNumberFormatConstructor())
         nf = nf[intlFallbackSymbol()];
 
     // Step 3.
-    if (!IsObject(nf) || !IsNumberFormat(nf))
+    if (!IsObject(nf) || (nf = GuardToNumberFormat(nf)) === null)
         ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "NumberFormat", methodName, "NumberFormat");
 
     // Step 4.
     return nf;
 }
 
 /**
  * Applies digit options used for number formatting onto the intl object.
@@ -200,17 +200,17 @@ function IsWellFormedCurrencyCode(curren
  * all the work we can until the object is actually used as a NumberFormat.
  * This later work occurs in |resolveNumberFormatInternals|; steps not noted
  * here occur there.
  *
  * Spec: ECMAScript Internationalization API Specification, 11.1.2.
  */
 function InitializeNumberFormat(numberFormat, thisValue, locales, options) {
     assert(IsObject(numberFormat), "InitializeNumberFormat called with non-object");
-    assert(IsNumberFormat(numberFormat), "InitializeNumberFormat called with non-NumberFormat");
+    assert(GuardToNumberFormat(numberFormat) !== null, "InitializeNumberFormat called with non-NumberFormat");
 
     // Lazy NumberFormat data has the following structure:
     //
     //   {
     //     requestedLocales: List of locales,
     //     style: "decimal" / "percent" / "currency",
     //
     //     // fields present only if style === "currency":
@@ -400,17 +400,17 @@ function numberFormatLocaleData() {
  * Spec: ECMAScript Internationalization API Specification, 11.1.4.
  */
 function numberFormatFormatToBind(value) {
     // Step 1.
     var nf = this;
 
     // Step 2.
     assert(IsObject(nf), "InitializeNumberFormat called with non-object");
-    assert(IsNumberFormat(nf), "InitializeNumberFormat called with non-NumberFormat");
+    assert(GuardToNumberFormat(nf) !== null, "InitializeNumberFormat called with non-NumberFormat");
 
     // Steps 3-4.
     var x = ToNumber(value);
 
     // Step 5.
     return intl_FormatNumber(nf, x, /* formatToParts = */ false);
 }
 
@@ -444,17 +444,17 @@ function Intl_NumberFormat_format_get() 
 /**
  * 11.4.4 Intl.NumberFormat.prototype.formatToParts ( value )
  */
 function Intl_NumberFormat_formatToParts(value) {
     // Step 1.
     var nf = this;
 
     // Steps 2-3.
-    if (!IsObject(nf) || !IsNumberFormat(nf)) {
+    if (!IsObject(nf) || (nf = GuardToNumberFormat(nf)) === null) {
         ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "NumberFormat", "formatToParts",
                        "NumberFormat");
     }
 
     // Ensure the NumberFormat internals are resolved.
     getNumberFormatInternals(nf);
 
     // Step 4.
--- a/js/src/jit/InlinableNatives.h
+++ b/js/src/jit/InlinableNatives.h
@@ -26,17 +26,17 @@
     _(AtomicsOr)                    \
     _(AtomicsXor)                   \
     _(AtomicsIsLockFree)            \
                                     \
     _(Boolean)                      \
                                     \
     _(IntlGuardToCollator)          \
     _(IntlIsDateTimeFormat)         \
-    _(IntlIsNumberFormat)           \
+    _(IntlGuardToNumberFormat)      \
     _(IntlIsPluralRules)            \
     _(IntlIsRelativeTimeFormat)     \
                                     \
     _(MathAbs)                      \
     _(MathFloor)                    \
     _(MathCeil)                     \
     _(MathRound)                    \
     _(MathClz32)                    \
--- a/js/src/jit/MCallOptimize.cpp
+++ b/js/src/jit/MCallOptimize.cpp
@@ -118,18 +118,18 @@ IonBuilder::inlineNativeCall(CallInfo& c
       case InlinableNative::Boolean:
         return inlineBoolean(callInfo);
 
       // Intl natives.
       case InlinableNative::IntlGuardToCollator:
         return inlineGuardToClass(callInfo, &CollatorObject::class_);
       case InlinableNative::IntlIsDateTimeFormat:
         return inlineHasClass(callInfo, &DateTimeFormatObject::class_);
-      case InlinableNative::IntlIsNumberFormat:
-        return inlineHasClass(callInfo, &NumberFormatObject::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_);
 
       // Math natives.
       case InlinableNative::MathAbs:
         return inlineMathAbs(callInfo);
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -2564,19 +2564,19 @@ static const JSFunctionSpec intrinsic_fu
     JS_FN("intl_toLocaleUpperCase", intl_toLocaleUpperCase, 2,0),
 
     JS_INLINABLE_FN("GuardToCollator",
                     intrinsic_GuardToBuiltin<CollatorObject>, 1,0,
                     IntlGuardToCollator),
     JS_INLINABLE_FN("IsDateTimeFormat",
                     intrinsic_IsInstanceOfBuiltin<DateTimeFormatObject>, 1,0,
                     IntlIsDateTimeFormat),
-    JS_INLINABLE_FN("IsNumberFormat",
-                    intrinsic_IsInstanceOfBuiltin<NumberFormatObject>, 1,0,
-                    IntlIsNumberFormat),
+    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_FN("GetDateTimeFormatConstructor",
           intrinsic_GetBuiltinIntlConstructor<GlobalObject::getOrCreateDateTimeFormatConstructor>,