Commit 96f67bb1 authored by Frank Tang's avatar Frank Tang Committed by V8 LUCI CQ

[Intl] Sync to intl-numberformat-v3 PR107

Return fallback while the useGrouping is "true" or "false"
but throw RangeError not in the list.

https://github.com/tc39/proposal-intl-numberformat-v3/pull/107

Bug: v8:13271
Change-Id: Ia325cd8fe74ff9fb501fd765e9ec2d94f8c97e38
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3886070Reviewed-by: 's avatarShu-yu Guo <syg@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83282}
parent 4b0e8569
...@@ -76,8 +76,8 @@ V8_WARN_UNUSED_RESULT static Maybe<T> GetStringOrBooleanOption( ...@@ -76,8 +76,8 @@ V8_WARN_UNUSED_RESULT static Maybe<T> GetStringOrBooleanOption(
const std::vector<T>& enum_values, T true_value, T false_value, const std::vector<T>& enum_values, T true_value, T false_value,
T fallback_value) { T fallback_value) {
DCHECK_EQ(str_values.size(), enum_values.size()); DCHECK_EQ(str_values.size(), enum_values.size());
Handle<String> property_str = Factory* factory = isolate->factory();
isolate->factory()->NewStringFromAsciiChecked(property); Handle<String> property_str = factory->NewStringFromAsciiChecked(property);
// 1. Let value be ? Get(options, property). // 1. Let value be ? Get(options, property).
Handle<Object> value; Handle<Object> value;
...@@ -104,8 +104,14 @@ V8_WARN_UNUSED_RESULT static Maybe<T> GetStringOrBooleanOption( ...@@ -104,8 +104,14 @@ V8_WARN_UNUSED_RESULT static Maybe<T> GetStringOrBooleanOption(
// 6. Let value be ? ToString(value). // 6. Let value be ? ToString(value).
ASSIGN_RETURN_ON_EXCEPTION_VALUE( ASSIGN_RETURN_ON_EXCEPTION_VALUE(
isolate, value_str, Object::ToString(isolate, value), Nothing<T>()); isolate, value_str, Object::ToString(isolate, value), Nothing<T>());
// If values does not contain an element equal to value, return fallback. // 7. If value is *"true"* or *"false"*, return _fallback_.
// 8. Return value. if (String::Equals(isolate, value_str, factory->true_string()) ||
String::Equals(isolate, value_str, factory->false_string())) {
return Just(fallback_value);
}
// 8. If values does not contain an element equal to _value_, throw a
// *RangeError* exception.
// 9. Return value.
value_str = String::Flatten(isolate, value_str); value_str = String::Flatten(isolate, value_str);
{ {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
...@@ -127,7 +133,11 @@ V8_WARN_UNUSED_RESULT static Maybe<T> GetStringOrBooleanOption( ...@@ -127,7 +133,11 @@ V8_WARN_UNUSED_RESULT static Maybe<T> GetStringOrBooleanOption(
} }
} }
} // end of no_gc } // end of no_gc
return Just(fallback_value); THROW_NEW_ERROR_RETURN_VALUE(
isolate,
NewRangeError(MessageTemplate::kValueOutOfRange, value,
factory->NewStringFromAsciiChecked(method), property_str),
Nothing<T>());
} }
// ECMA402 9.2.10. GetOption( options, property, type, values, fallback) // ECMA402 9.2.10. GetOption( options, property, type, values, fallback)
......
...@@ -11,21 +11,32 @@ let validUseGrouping = [ ...@@ -11,21 +11,32 @@ let validUseGrouping = [
false, false,
]; ];
let fallbackUseGrouping = [
"true",
"false",
];
let invalidUseGrouping = [ let invalidUseGrouping = [
"min-2", "min-2",
"true",
]; ];
validUseGrouping.forEach(function(useGrouping) { validUseGrouping.forEach(function(useGrouping) {
let nf = new Intl.NumberFormat(undefined, {useGrouping}); let nf = new Intl.NumberFormat(undefined, {useGrouping});
assertEquals(useGrouping, nf.resolvedOptions().useGrouping); assertEquals(useGrouping, nf.resolvedOptions().useGrouping);
}); });
invalidUseGrouping.forEach(function(useGrouping) { fallbackUseGrouping.forEach(function(useGrouping) {
let nf = new Intl.NumberFormat(undefined, {useGrouping}); let nf = new Intl.NumberFormat(undefined, {useGrouping});
assertEquals("auto", nf.resolvedOptions().useGrouping); assertEquals("auto", nf.resolvedOptions().useGrouping);
}); });
invalidUseGrouping.forEach(function(useGrouping) {
assertThrows(
() => new Intl.NumberFormat(undefined, {useGrouping}),
RangeError);
});
// useGrouping: undefined get "auto" // useGrouping: undefined get "auto"
assertEquals("auto", assertEquals("auto",
(new Intl.NumberFormat()).resolvedOptions().useGrouping); (new Intl.NumberFormat()).resolvedOptions().useGrouping);
......
...@@ -565,8 +565,8 @@ ...@@ -565,8 +565,8 @@
'staging/Intl402/Temporal/old/yearmonth-toLocaleString': [FAIL], 'staging/Intl402/Temporal/old/yearmonth-toLocaleString': [FAIL],
'staging/Intl402/Temporal/old/zoneddatetime-toLocaleString': [FAIL], 'staging/Intl402/Temporal/old/zoneddatetime-toLocaleString': [FAIL],
# https://github.com/tc39/proposal-intl-numberformat-v3/pull/107 # https://github.com/tc39/test262/pull/3659
'intl402/NumberFormat/test-option-useGrouping': [FAIL], 'intl402/NumberFormat/test-option-useGrouping-extended': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=11660 # https://bugs.chromium.org/p/v8/issues/detail?id=11660
'intl402/DurationFormat/prototype/prototype_attributes': [FAIL], 'intl402/DurationFormat/prototype/prototype_attributes': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment