# HG changeset patch # User Matthew Gaudet # Date 1524496024 14400 # Mon Apr 23 11:07:04 2018 -0400 # Node ID 83ea97f7f8d3aca75d44c6818780cb3d42301d44 # Parent 228aa3f16cde41317ab414e189df23275010fb9f Bug 1437842: [Part 6] Convert IsNumberFormat to GuardToNumberFormat r=jandem diff --git a/js/src/builtin/intl/CommonFunctions.js b/js/src/builtin/intl/CommonFunctions.js --- a/js/src/builtin/intl/CommonFunctions.js +++ b/js/src/builtin/intl/CommonFunctions.js @@ -1466,17 +1466,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: @@ -1533,27 +1533,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; } diff --git a/js/src/builtin/intl/NumberFormat.js b/js/src/builtin/intl/NumberFormat.js --- 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. diff --git a/js/src/jit/InlinableNatives.h b/js/src/jit/InlinableNatives.h --- 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) \ diff --git a/js/src/jit/MCallOptimize.cpp b/js/src/jit/MCallOptimize.cpp --- a/js/src/jit/MCallOptimize.cpp +++ b/js/src/jit/MCallOptimize.cpp @@ -121,18 +121,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); diff --git a/js/src/vm/SelfHosting.cpp b/js/src/vm/SelfHosting.cpp --- a/js/src/vm/SelfHosting.cpp +++ b/js/src/vm/SelfHosting.cpp @@ -2520,19 +2520,19 @@ static const JSFunctionSpec intrinsic_fu JS_FN("intl_toLocaleUpperCase", intl_toLocaleUpperCase, 2,0), JS_INLINABLE_FN("GuardToCollator", intrinsic_GuardToBuiltin, 1,0, IntlGuardToCollator), JS_INLINABLE_FN("IsDateTimeFormat", intrinsic_IsInstanceOfBuiltin, 1,0, IntlIsDateTimeFormat), - JS_INLINABLE_FN("IsNumberFormat", - intrinsic_IsInstanceOfBuiltin, 1,0, - IntlIsNumberFormat), + JS_INLINABLE_FN("GuardToNumberFormat", + intrinsic_GuardToBuiltin, 1,0, + IntlGuardToNumberFormat), JS_INLINABLE_FN("IsPluralRules", intrinsic_IsInstanceOfBuiltin, 1,0, IntlIsPluralRules), JS_INLINABLE_FN("IsRelativeTimeFormat", intrinsic_IsInstanceOfBuiltin, 1,0, IntlIsRelativeTimeFormat), JS_FN("GetDateTimeFormatConstructor", intrinsic_GetBuiltinIntlConstructor,