summaryrefslogtreecommitdiff
path: root/js/src/builtin
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2023-06-18 21:58:05 +0200
committerMartok <martok@martoks-place.de>2023-06-29 22:27:29 +0200
commit388733cd1d826d53baf12e1b0d4b7fba24013d44 (patch)
treec8124e73c252f457c8cfb6211338507f7bf16bec /js/src/builtin
parent35f1a49cf213aa1527d818e1f2593135d4ddc4d8 (diff)
downloaduxp-388733cd1d826d53baf12e1b0d4b7fba24013d44.tar.gz
Issue #2259 - Introduce helper for self-hosted hasOwnProperty calls in intl
Diffstat (limited to 'js/src/builtin')
-rw-r--r--js/src/builtin/intl/CommonFunctions.js22
-rw-r--r--js/src/builtin/intl/DateTimeFormat.js4
-rw-r--r--js/src/builtin/intl/NumberFormat.js4
-rw-r--r--js/src/builtin/intl/PluralRules.js2
4 files changed, 20 insertions, 12 deletions
diff --git a/js/src/builtin/intl/CommonFunctions.js b/js/src/builtin/intl/CommonFunctions.js
index 48337e666a..5a963edfbf 100644
--- a/js/src/builtin/intl/CommonFunctions.js
+++ b/js/src/builtin/intl/CommonFunctions.js
@@ -5,6 +5,14 @@
/* Portions Copyright Norbert Lindenberg 2011-2012. */
+
+/**
+ * Shorthand for hasOwnProperty.
+ */
+function hasOwn(propName, object) {
+ return callFunction(std_Object_hasOwnProperty, object, propName);
+}
+
/**
* Holder object for encapsulating regexp instances.
*
@@ -346,7 +354,7 @@ function CanonicalizeLanguageTag(locale) {
locale = callFunction(std_String_toLowerCase, locale);
// Handle mappings for complete tags.
- if (callFunction(std_Object_hasOwnProperty, langTagMappings, locale))
+ if (hasOwn(locale, langTagMappings))
return langTagMappings[locale];
var subtags = StringSplitString(ToString(locale), "-");
@@ -378,7 +386,7 @@ function CanonicalizeLanguageTag(locale) {
subtag = callFunction(std_String_toUpperCase, subtag);
}
}
- if (callFunction(std_Object_hasOwnProperty, langSubtagMappings, subtag)) {
+ if (hasOwn(subtag, langSubtagMappings)) {
// Replace deprecated subtags with their preferred values.
// "BU" -> "MM"
// This has to come after we capitalize region codes because
@@ -388,7 +396,7 @@ function CanonicalizeLanguageTag(locale) {
// Note that the script generating langSubtagMappings makes sure
// that no regular subtag mapping will replace an extlang code.
subtag = langSubtagMappings[subtag];
- } else if (callFunction(std_Object_hasOwnProperty, extlangMappings, subtag)) {
+ } else if (hasOwn(subtag, extlangMappings)) {
// Replace deprecated extlang subtags with their preferred values,
// and remove the preceding subtag if it's a redundant prefix.
// "zh-nan" -> "nan"
@@ -516,7 +524,7 @@ function DefaultLocaleIgnoringAvailableLocales() {
// remove any present in the candidate.
candidate = removeUnicodeExtensions(candidate);
- if (callFunction(std_Object_hasOwnProperty, oldStyleLanguageTagMappings, candidate))
+ if (hasOwn(candidate, oldStyleLanguageTagMappings))
candidate = oldStyleLanguageTagMappings[candidate];
}
@@ -1163,14 +1171,14 @@ function isInitializedIntlObject(obj) {
#ifdef DEBUG
var internals = callFunction(std_WeakMap_get, internalsMap, obj);
if (IsObject(internals)) {
- assert(callFunction(std_Object_hasOwnProperty, internals, "type"), "missing type");
+ assert(hasOwn("type", internals), "missing type");
var type = internals.type;
assert(type === "partial" || type === "Collator" ||
type === "DateTimeFormat" || type === "NumberFormat" ||
type === "PluralRules" || type === "RelativeTimeFormat",
"unexpected type");
- assert(callFunction(std_Object_hasOwnProperty, internals, "lazyData"), "missing lazyData");
- assert(callFunction(std_Object_hasOwnProperty, internals, "internalProps"), "missing internalProps");
+ assert(hasOwn("lazyData", internals), "missing lazyData");
+ assert(hasOwn("internalProps", internals), "missing internalProps");
} else {
assert(internals === undefined, "bad mapping for |obj|");
}
diff --git a/js/src/builtin/intl/DateTimeFormat.js b/js/src/builtin/intl/DateTimeFormat.js
index b7a71bdd6b..e0167cda30 100644
--- a/js/src/builtin/intl/DateTimeFormat.js
+++ b/js/src/builtin/intl/DateTimeFormat.js
@@ -623,7 +623,7 @@ function BasicFormatMatcher(options, formats) {
formatProp = undefined;
// Steps 11.c.ii-iii.
- if (callFunction(std_Object_hasOwnProperty, format, property))
+ if (hasOwn(property, format))
formatProp = format[property];
if (optionsProp === undefined && formatProp !== undefined) {
@@ -886,7 +886,7 @@ function resolveICUPattern(pattern, result) {
default:
// skip other pattern characters and literal text
}
- if (callFunction(std_Object_hasOwnProperty, icuPatternCharToComponent, c))
+ if (hasOwn(c, icuPatternCharToComponent))
_DefineDataProperty(result, icuPatternCharToComponent[c], value);
if (c === "h" || c === "K")
_DefineDataProperty(result, "hour12", true);
diff --git a/js/src/builtin/intl/NumberFormat.js b/js/src/builtin/intl/NumberFormat.js
index c97395880d..639f8a9dde 100644
--- a/js/src/builtin/intl/NumberFormat.js
+++ b/js/src/builtin/intl/NumberFormat.js
@@ -366,7 +366,7 @@ function CurrencyDigits(currency) {
assert(typeof currency === "string", "CurrencyDigits");
assert(regexp_test_no_statics(getCurrencyDigitsRE(), currency), "CurrencyDigits");
- if (callFunction(std_Object_hasOwnProperty, currencyDigits, currency))
+ if (hasOwn(currency, currencyDigits))
return currencyDigits[currency];
return 2;
}
@@ -502,7 +502,7 @@ function Intl_NumberFormat_resolvedOptions() {
];
for (var i = 0; i < optionalProperties.length; i++) {
var p = optionalProperties[i];
- if (callFunction(std_Object_hasOwnProperty, internals, p))
+ if (hasOwn(p, internals))
_DefineDataProperty(result, p, internals[p]);
}
return result;
diff --git a/js/src/builtin/intl/PluralRules.js b/js/src/builtin/intl/PluralRules.js
index 0ba289d85e..d271a8d397 100644
--- a/js/src/builtin/intl/PluralRules.js
+++ b/js/src/builtin/intl/PluralRules.js
@@ -223,7 +223,7 @@ function Intl_PluralRules_resolvedOptions() {
for (var i = 0; i < optionalProperties.length; i++) {
var p = optionalProperties[i];
- if (callFunction(std_Object_hasOwnProperty, internals, p))
+ if (hasOwn(p, internals))
_DefineDataProperty(result, p, internals[p]);
}
return result;