|
@@ -25,7 +25,7 @@ ThrowCompletionOr<void> PluralRulesPrototype::initialize(Realm& realm)
|
|
auto& vm = this->vm();
|
|
auto& vm = this->vm();
|
|
|
|
|
|
// 16.3.2 Intl.PluralRules.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.pluralrules.prototype-tostringtag
|
|
// 16.3.2 Intl.PluralRules.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.pluralrules.prototype-tostringtag
|
|
- define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.PluralRules"sv), Attribute::Configurable);
|
|
|
|
|
|
+ define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.PluralRules"sv)), Attribute::Configurable);
|
|
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
define_native_function(realm, vm.names.select, select, 1, attr);
|
|
define_native_function(realm, vm.names.select, select, 1, attr);
|
|
@@ -48,7 +48,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select)
|
|
|
|
|
|
// 4. Return ! ResolvePlural(pr, n).[[PluralCategory]].
|
|
// 4. Return ! ResolvePlural(pr, n).[[PluralCategory]].
|
|
auto plurality = MUST_OR_THROW_OOM(resolve_plural(vm, *plural_rules, number));
|
|
auto plurality = MUST_OR_THROW_OOM(resolve_plural(vm, *plural_rules, number));
|
|
- return PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality.plural_category));
|
|
|
|
|
|
+ return MUST_OR_THROW_OOM(PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality.plural_category)));
|
|
}
|
|
}
|
|
|
|
|
|
// 1.3.4 Intl.PluralRules.prototype.selectRange ( start, end ), https://tc39.es/proposal-intl-numberformat-v3/out/pluralrules/proposed.html#sec-intl.pluralrules.prototype.selectrange
|
|
// 1.3.4 Intl.PluralRules.prototype.selectRange ( start, end ), https://tc39.es/proposal-intl-numberformat-v3/out/pluralrules/proposed.html#sec-intl.pluralrules.prototype.selectrange
|
|
@@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
|
|
|
|
|
|
// 6. Return ? ResolvePluralRange(pr, x, y).
|
|
// 6. Return ? ResolvePluralRange(pr, x, y).
|
|
auto plurality = TRY(resolve_plural_range(vm, *plural_rules, x, y));
|
|
auto plurality = TRY(resolve_plural_range(vm, *plural_rules, x, y));
|
|
- return PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality));
|
|
|
|
|
|
+ return MUST_OR_THROW_OOM(PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality)));
|
|
}
|
|
}
|
|
|
|
|
|
// 16.3.4 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions
|
|
// 16.3.4 Intl.PluralRules.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.resolvedoptions
|
|
@@ -97,7 +97,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
|
// c. If v is not undefined, then
|
|
// c. If v is not undefined, then
|
|
// i. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
|
// i. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
|
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, plural_rules->locale())));
|
|
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, plural_rules->locale())));
|
|
- MUST(options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, plural_rules->type_string())));
|
|
|
|
|
|
+ MUST(options->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, plural_rules->type_string()))));
|
|
MUST(options->create_data_property_or_throw(vm.names.minimumIntegerDigits, Value(plural_rules->min_integer_digits())));
|
|
MUST(options->create_data_property_or_throw(vm.names.minimumIntegerDigits, Value(plural_rules->min_integer_digits())));
|
|
if (plural_rules->has_min_fraction_digits())
|
|
if (plural_rules->has_min_fraction_digits())
|
|
MUST(options->create_data_property_or_throw(vm.names.minimumFractionDigits, Value(plural_rules->min_fraction_digits())));
|
|
MUST(options->create_data_property_or_throw(vm.names.minimumFractionDigits, Value(plural_rules->min_fraction_digits())));
|
|
@@ -107,16 +107,16 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
|
MUST(options->create_data_property_or_throw(vm.names.minimumSignificantDigits, Value(plural_rules->min_significant_digits())));
|
|
MUST(options->create_data_property_or_throw(vm.names.minimumSignificantDigits, Value(plural_rules->min_significant_digits())));
|
|
if (plural_rules->has_max_significant_digits())
|
|
if (plural_rules->has_max_significant_digits())
|
|
MUST(options->create_data_property_or_throw(vm.names.maximumSignificantDigits, Value(plural_rules->max_significant_digits())));
|
|
MUST(options->create_data_property_or_throw(vm.names.maximumSignificantDigits, Value(plural_rules->max_significant_digits())));
|
|
- MUST(options->create_data_property_or_throw(vm.names.roundingMode, PrimitiveString::create(vm, plural_rules->rounding_mode_string())));
|
|
|
|
|
|
+ MUST(options->create_data_property_or_throw(vm.names.roundingMode, MUST_OR_THROW_OOM(PrimitiveString::create(vm, plural_rules->rounding_mode_string()))));
|
|
MUST(options->create_data_property_or_throw(vm.names.roundingIncrement, Value(plural_rules->rounding_increment())));
|
|
MUST(options->create_data_property_or_throw(vm.names.roundingIncrement, Value(plural_rules->rounding_increment())));
|
|
- MUST(options->create_data_property_or_throw(vm.names.trailingZeroDisplay, PrimitiveString::create(vm, plural_rules->trailing_zero_display_string())));
|
|
|
|
|
|
+ MUST(options->create_data_property_or_throw(vm.names.trailingZeroDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, plural_rules->trailing_zero_display_string()))));
|
|
|
|
|
|
// 5. Let pluralCategories be a List of Strings containing all possible results of PluralRuleSelect for the selected locale pr.[[Locale]].
|
|
// 5. Let pluralCategories be a List of Strings containing all possible results of PluralRuleSelect for the selected locale pr.[[Locale]].
|
|
auto available_categories = ::Locale::available_plural_categories(plural_rules->locale(), plural_rules->type());
|
|
auto available_categories = ::Locale::available_plural_categories(plural_rules->locale(), plural_rules->type());
|
|
|
|
|
|
- auto plural_categories = Array::create_from<::Locale::PluralCategory>(realm, available_categories, [&](auto category) {
|
|
|
|
|
|
+ auto plural_categories = MUST_OR_THROW_OOM(Array::try_create_from<::Locale::PluralCategory>(vm, realm, available_categories, [&](auto category) {
|
|
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(category));
|
|
return PrimitiveString::create(vm, ::Locale::plural_category_to_string(category));
|
|
- });
|
|
|
|
|
|
+ }));
|
|
|
|
|
|
// 6. Perform ! CreateDataProperty(options, "pluralCategories", CreateArrayFromList(pluralCategories)).
|
|
// 6. Perform ! CreateDataProperty(options, "pluralCategories", CreateArrayFromList(pluralCategories)).
|
|
MUST(options->create_data_property_or_throw(vm.names.pluralCategories, plural_categories));
|
|
MUST(options->create_data_property_or_throw(vm.names.pluralCategories, plural_categories));
|
|
@@ -125,17 +125,17 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
|
// 7. If pr.[[RoundingType]] is morePrecision, then
|
|
// 7. If pr.[[RoundingType]] is morePrecision, then
|
|
case NumberFormatBase::RoundingType::MorePrecision:
|
|
case NumberFormatBase::RoundingType::MorePrecision:
|
|
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "morePrecision").
|
|
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "morePrecision").
|
|
- MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "morePrecision"sv)));
|
|
|
|
|
|
+ MUST(options->create_data_property_or_throw(vm.names.roundingPriority, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "morePrecision"sv))));
|
|
break;
|
|
break;
|
|
// 8. Else if pr.[[RoundingType]] is lessPrecision, then
|
|
// 8. Else if pr.[[RoundingType]] is lessPrecision, then
|
|
case NumberFormatBase::RoundingType::LessPrecision:
|
|
case NumberFormatBase::RoundingType::LessPrecision:
|
|
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "lessPrecision").
|
|
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "lessPrecision").
|
|
- MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "lessPrecision"sv)));
|
|
|
|
|
|
+ MUST(options->create_data_property_or_throw(vm.names.roundingPriority, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "lessPrecision"sv))));
|
|
break;
|
|
break;
|
|
// 9. Else,
|
|
// 9. Else,
|
|
default:
|
|
default:
|
|
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "auto").
|
|
// a. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "auto").
|
|
- MUST(options->create_data_property_or_throw(vm.names.roundingPriority, PrimitiveString::create(vm, "auto"sv)));
|
|
|
|
|
|
+ MUST(options->create_data_property_or_throw(vm.names.roundingPriority, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "auto"sv))));
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|