Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (260975 => 260976)
--- trunk/Source/_javascript_Core/ChangeLog 2020-05-01 00:30:57 UTC (rev 260975)
+++ trunk/Source/_javascript_Core/ChangeLog 2020-05-01 01:13:03 UTC (rev 260976)
@@ -1,3 +1,24 @@
+2020-04-30 Ross Kirsling <[email protected]>
+
+ [JSC] intlBooleanOption should return TriState instead of taking an out param
+ https://bugs.webkit.org/show_bug.cgi?id=211256
+
+ Reviewed by Darin Adler and Mark Lam.
+
+ Boolean options for Intl constructors can have default values of true, false, or undefined.
+ To handle the undefined case, intlBooleanOption currently has a `bool& usesFallback` param;
+ we should have the return type simply be a TriState instead.
+
+ * runtime/IntlCollator.cpp:
+ (JSC::IntlCollator::initializeCollator):
+ * runtime/IntlDateTimeFormat.cpp:
+ (JSC::IntlDateTimeFormat::initializeDateTimeFormat):
+ * runtime/IntlNumberFormat.cpp:
+ (JSC::IntlNumberFormat::initializeNumberFormat):
+ * runtime/IntlObject.cpp:
+ (JSC::intlBooleanOption):
+ * runtime/IntlObject.h:
+
2020-04-30 Devin Rousso <[email protected]>
WebKit.WebContent process crashes when web developer tools are opened in Safari
Modified: trunk/Source/_javascript_Core/runtime/IntlCollator.cpp (260975 => 260976)
--- trunk/Source/_javascript_Core/runtime/IntlCollator.cpp 2020-05-01 00:30:57 UTC (rev 260975)
+++ trunk/Source/_javascript_Core/runtime/IntlCollator.cpp 2020-05-01 01:13:03 UTC (rev 260976)
@@ -199,23 +199,16 @@
RETURN_IF_EXCEPTION(scope, void());
opt.add("localeMatcher"_s, matcher);
- {
- String numericString;
- bool usesFallback;
- bool numeric = intlBooleanOption(globalObject, options, vm.propertyNames->numeric, usesFallback);
- RETURN_IF_EXCEPTION(scope, void());
- if (!usesFallback)
- numericString = numeric ? "true"_s : "false"_s;
- if (!numericString.isNull())
- opt.add("kn"_s, numericString);
- }
- {
- String caseFirst = intlStringOption(globalObject, options, vm.propertyNames->caseFirst, { "upper", "lower", "false" }, "caseFirst must be either \"upper\", \"lower\", or \"false\"", nullptr);
- RETURN_IF_EXCEPTION(scope, void());
- if (!caseFirst.isNull())
- opt.add("kf"_s, caseFirst);
- }
+ TriState numeric = intlBooleanOption(globalObject, options, vm.propertyNames->numeric);
+ RETURN_IF_EXCEPTION(scope, void());
+ if (numeric != MixedTriState)
+ opt.add("kn"_s, numeric == TrueTriState ? "true"_s : "false"_s);
+ String caseFirstOption = intlStringOption(globalObject, options, vm.propertyNames->caseFirst, { "upper", "lower", "false" }, "caseFirst must be either \"upper\", \"lower\", or \"false\"", nullptr);
+ RETURN_IF_EXCEPTION(scope, void());
+ if (!caseFirstOption.isNull())
+ opt.add("kf"_s, caseFirstOption);
+
auto& availableLocales = intlCollatorAvailableLocales();
auto result = resolveLocale(globalObject, availableLocales, requestedLocales, opt, IntlCollatorInternal::relevantExtensionKeys, WTF_ARRAY_LENGTH(IntlCollatorInternal::relevantExtensionKeys), localeData);
@@ -248,12 +241,9 @@
else
m_sensitivity = Sensitivity::Variant;
- bool usesFallback;
- bool ignorePunctuation = intlBooleanOption(globalObject, options, vm.propertyNames->ignorePunctuation, usesFallback);
+ TriState ignorePunctuation = intlBooleanOption(globalObject, options, vm.propertyNames->ignorePunctuation);
RETURN_IF_EXCEPTION(scope, void());
- if (usesFallback)
- ignorePunctuation = false;
- m_ignorePunctuation = ignorePunctuation;
+ m_ignorePunctuation = (ignorePunctuation == TrueTriState);
UErrorCode status = U_ZERO_ERROR;
m_collator = std::unique_ptr<UCollator, UCollatorDeleter>(ucol_open(m_locale.utf8().data(), &status));
Modified: trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp (260975 => 260976)
--- trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp 2020-05-01 00:30:57 UTC (rev 260975)
+++ trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp 2020-05-01 01:13:03 UTC (rev 260976)
@@ -466,15 +466,15 @@
opt.add("nu"_s, numberingSystem);
}
- bool isHour12Undefined;
- bool hour12 = intlBooleanOption(globalObject, options, vm.propertyNames->hour12, isHour12Undefined);
+ TriState hour12 = intlBooleanOption(globalObject, options, vm.propertyNames->hour12);
RETURN_IF_EXCEPTION(scope, void());
+ bool isHour12Undefined = (hour12 == MixedTriState);
String hourCycle = intlStringOption(globalObject, options, vm.propertyNames->hourCycle, { "h11", "h12", "h23", "h24" }, "hourCycle must be \"h11\", \"h12\", \"h23\", or \"h24\"", nullptr);
RETURN_IF_EXCEPTION(scope, void());
if (isHour12Undefined) {
// Set hour12 here to simplify hour logic later.
- hour12 = (hourCycle == "h11" || hourCycle == "h12");
+ hour12 = triState(hourCycle == "h11" || hourCycle == "h12");
if (!hourCycle.isNull())
opt.add("hc"_s, hourCycle);
} else
@@ -582,7 +582,7 @@
if (hour == "2-digit") {
if (isHour12Undefined && m_hourCycle.isNull())
skeletonBuilder.appendLiteral("jj");
- else if (hour12)
+ else if (hour12 == TrueTriState)
skeletonBuilder.appendLiteral("hh");
else
skeletonBuilder.appendLiteral("HH");
@@ -589,7 +589,7 @@
} else if (hour == "numeric") {
if (isHour12Undefined && m_hourCycle.isNull())
skeletonBuilder.append('j');
- else if (hour12)
+ else if (hour12 == TrueTriState)
skeletonBuilder.append('h');
else
skeletonBuilder.append('H');
Modified: trunk/Source/_javascript_Core/runtime/IntlNumberFormat.cpp (260975 => 260976)
--- trunk/Source/_javascript_Core/runtime/IntlNumberFormat.cpp 2020-05-01 00:30:57 UTC (rev 260975)
+++ trunk/Source/_javascript_Core/runtime/IntlNumberFormat.cpp 2020-05-01 01:13:03 UTC (rev 260976)
@@ -281,12 +281,9 @@
m_maximumSignificantDigits = maximumSignificantDigits;
}
- bool usesFallback;
- bool useGrouping = intlBooleanOption(globalObject, options, Identifier::fromString(vm, "useGrouping"), usesFallback);
+ TriState useGrouping = intlBooleanOption(globalObject, options, Identifier::fromString(vm, "useGrouping"));
RETURN_IF_EXCEPTION(scope, void());
- if (usesFallback)
- useGrouping = true;
- m_useGrouping = useGrouping;
+ m_useGrouping = useGrouping != FalseTriState;
UNumberFormatStyle style = UNUM_DEFAULT;
switch (m_style) {
Modified: trunk/Source/_javascript_Core/runtime/IntlObject.cpp (260975 => 260976)
--- trunk/Source/_javascript_Core/runtime/IntlObject.cpp 2020-05-01 00:30:57 UTC (rev 260975)
+++ trunk/Source/_javascript_Core/runtime/IntlObject.cpp 2020-05-01 01:13:03 UTC (rev 260976)
@@ -202,34 +202,25 @@
return availableLocales;
}
-bool intlBooleanOption(JSGlobalObject* globalObject, JSValue options, PropertyName property, bool& usesFallback)
+// https://tc39.es/ecma402/#sec-getoption
+TriState intlBooleanOption(JSGlobalObject* globalObject, JSValue options, PropertyName property)
{
- // GetOption (options, property, type="boolean", values, fallback)
- // https://tc39.github.io/ecma402/#sec-getoption
-
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
- if (options.isUndefined()) {
- usesFallback = true;
- return false;
- }
+ if (options.isUndefined())
+ return MixedTriState;
JSObject* opts = options.toObject(globalObject);
- RETURN_IF_EXCEPTION(scope, false);
+ RETURN_IF_EXCEPTION(scope, MixedTriState);
JSValue value = opts->get(globalObject, property);
- RETURN_IF_EXCEPTION(scope, false);
+ RETURN_IF_EXCEPTION(scope, MixedTriState);
- if (!value.isUndefined()) {
- bool booleanValue = value.toBoolean(globalObject);
- usesFallback = false;
- return booleanValue;
- }
+ if (value.isUndefined())
+ return MixedTriState;
- // Because fallback can be undefined, we let the caller handle it instead.
- usesFallback = true;
- return false;
+ return triState(value.toBoolean(globalObject));
}
String intlStringOption(JSGlobalObject* globalObject, JSValue options, PropertyName property, std::initializer_list<const char*> values, const char* notFound, const char* fallback)
Modified: trunk/Source/_javascript_Core/runtime/IntlObject.h (260975 => 260976)
--- trunk/Source/_javascript_Core/runtime/IntlObject.h 2020-05-01 00:30:57 UTC (rev 260975)
+++ trunk/Source/_javascript_Core/runtime/IntlObject.h 2020-05-01 01:13:03 UTC (rev 260976)
@@ -64,7 +64,7 @@
inline const HashSet<String>& intlPluralRulesAvailableLocales() { return intlAvailableLocales(); }
inline const HashSet<String>& intlRelativeTimeFormatAvailableLocales() { return intlAvailableLocales(); }
-bool intlBooleanOption(JSGlobalObject*, JSValue options, PropertyName, bool& usesFallback);
+TriState intlBooleanOption(JSGlobalObject*, JSValue options, PropertyName);
String intlStringOption(JSGlobalObject*, JSValue options, PropertyName, std::initializer_list<const char*> values, const char* notFound, const char* fallback);
unsigned intlNumberOption(JSGlobalObject*, JSValue options, PropertyName, unsigned minimum, unsigned maximum, unsigned fallback);
unsigned intlDefaultNumberOption(JSGlobalObject*, JSValue, PropertyName, unsigned minimum, unsigned maximum, unsigned fallback);