mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
LibJS+LibWeb: Convert string view PrimitiveString instances to String
First, this adds an overload of PrimitiveString::create for StringView. This overload will throw an OOM completion if creating a String fails. This is not only a bit more convenient, but it also ensures at compile time that all PrimitiveString::create(string_view) invocations will be handled as String and OOM-aware. Next, this wraps all invocations to PrimitiveString::create(string_view) with MUST_OR_THROW_OOM. A small PrimitiveString::create(DeprecatedFlyString) overload also had to be added to disambiguate between the StringView and DeprecatedString overloads.
This commit is contained in:
parent
69a56a8e39
commit
c3abb1396c
69 changed files with 223 additions and 186 deletions
|
@ -88,7 +88,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
|
|||
// 24. If relevantExtensionKeys contains "kn", then
|
||||
if (relevant_extension_keys.span().contains_slow("kn"sv) && result.kn.has_value()) {
|
||||
// a. Set collator.[[Numeric]] to SameValue(r.[[kn]], "true").
|
||||
collator.set_numeric(same_value(PrimitiveString::create(vm, result.kn.release_value()), PrimitiveString::create(vm, "true"sv)));
|
||||
collator.set_numeric(same_value(PrimitiveString::create(vm, result.kn.release_value()), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "true"sv))));
|
||||
}
|
||||
|
||||
// 25. If relevantExtensionKeys contains "kf", then
|
||||
|
@ -105,14 +105,14 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
|
|||
// a. If usage is "sort", then
|
||||
if (collator.usage() == Collator::Usage::Sort) {
|
||||
// i. Let sensitivity be "variant".
|
||||
sensitivity = PrimitiveString::create(vm, "variant"sv);
|
||||
sensitivity = MUST_OR_THROW_OOM(PrimitiveString::create(vm, "variant"sv));
|
||||
}
|
||||
// b. Else,
|
||||
else {
|
||||
// i. Let dataLocale be r.[[dataLocale]].
|
||||
// ii. Let dataLocaleData be localeData.[[<dataLocale>]].
|
||||
// iii. Let sensitivity be dataLocaleData.[[sensitivity]].
|
||||
sensitivity = PrimitiveString::create(vm, "base"sv);
|
||||
sensitivity = MUST_OR_THROW_OOM(PrimitiveString::create(vm, "base"sv));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ ThrowCompletionOr<void> CollatorPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 10.3.2 Intl.Collator.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.collator.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.Collator"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.Collator"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_accessor(realm, vm.names.compare, compare_getter, {}, attr);
|
||||
|
@ -78,12 +78,12 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
|
|||
// d. If v is not undefined, then
|
||||
// i. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, collator->locale())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.usage, PrimitiveString::create(vm, collator->usage_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.sensitivity, PrimitiveString::create(vm, collator->sensitivity_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.usage, MUST_OR_THROW_OOM(PrimitiveString::create(vm, collator->usage_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.sensitivity, MUST_OR_THROW_OOM(PrimitiveString::create(vm, collator->sensitivity_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.ignorePunctuation, Value(collator->ignore_punctuation())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.collation, PrimitiveString::create(vm, collator->collation())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.numeric, Value(collator->numeric())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.caseFirst, PrimitiveString::create(vm, collator->case_first_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.caseFirst, MUST_OR_THROW_OOM(PrimitiveString::create(vm, collator->case_first_string()))));
|
||||
|
||||
// 5. Return options.
|
||||
return options;
|
||||
|
|
|
@ -136,7 +136,7 @@ ThrowCompletionOr<Object*> to_date_time_options(VM& vm, Value options_value, Opt
|
|||
// a. For each property name prop of « "year", "month", "day" », do
|
||||
for (auto const& property : AK::Array { vm.names.year, vm.names.month, vm.names.day }) {
|
||||
// i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric").
|
||||
TRY(options->create_data_property_or_throw(property, PrimitiveString::create(vm, "numeric"sv)));
|
||||
TRY(options->create_data_property_or_throw(property, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "numeric"sv))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ ThrowCompletionOr<Object*> to_date_time_options(VM& vm, Value options_value, Opt
|
|||
// a. For each property name prop of « "hour", "minute", "second" », do
|
||||
for (auto const& property : AK::Array { vm.names.hour, vm.names.minute, vm.names.second }) {
|
||||
// i. Perform ? CreateDataPropertyOrThrow(options, prop, "numeric").
|
||||
TRY(options->create_data_property_or_throw(property, PrimitiveString::create(vm, "numeric"sv)));
|
||||
TRY(options->create_data_property_or_throw(property, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "numeric"sv))));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -875,7 +875,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
|
||||
|
@ -1192,13 +1192,13 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
|
||||
|
||||
// d. Perform ! CreateDataPropertyOrThrow(O, "source", part.[[Source]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.source, PrimitiveString::create(vm, part.source)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.source, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.source))));
|
||||
|
||||
// e. Perform ! CreateDataProperty(result, ! ToString(n), O).
|
||||
MUST(result->create_data_property_or_throw(n, object));
|
||||
|
|
|
@ -26,7 +26,7 @@ ThrowCompletionOr<void> DateTimeFormatPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 11.3.2 Intl.DateTimeFormat.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.DateTimeFormat"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.DateTimeFormat"sv)), Attribute::Configurable);
|
||||
|
||||
define_native_accessor(realm, vm.names.format, format, nullptr, Attribute::Configurable);
|
||||
|
||||
|
@ -179,7 +179,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
|
|||
MUST(options->create_data_property_or_throw(vm.names.timeZone, PrimitiveString::create(vm, date_time_format->time_zone())));
|
||||
|
||||
if (date_time_format->has_hour_cycle()) {
|
||||
MUST(options->create_data_property_or_throw(vm.names.hourCycle, PrimitiveString::create(vm, date_time_format->hour_cycle_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.hourCycle, MUST_OR_THROW_OOM(PrimitiveString::create(vm, date_time_format->hour_cycle_string()))));
|
||||
|
||||
switch (date_time_format->hour_cycle()) {
|
||||
case ::Locale::HourCycle::H11:
|
||||
|
@ -201,10 +201,10 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
|
|||
return {};
|
||||
|
||||
if constexpr (IsIntegral<ValueType>) {
|
||||
TRY(options->create_data_property_or_throw(property, Value(*option)));
|
||||
MUST(options->create_data_property_or_throw(property, Value(*option)));
|
||||
} else {
|
||||
auto name = ::Locale::calendar_pattern_style_to_string(*option);
|
||||
TRY(options->create_data_property_or_throw(property, PrimitiveString::create(vm, name)));
|
||||
MUST(options->create_data_property_or_throw(property, MUST_OR_THROW_OOM(PrimitiveString::create(vm, name))));
|
||||
}
|
||||
|
||||
return {};
|
||||
|
@ -212,9 +212,9 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
|
|||
}
|
||||
|
||||
if (date_time_format->has_date_style())
|
||||
MUST(options->create_data_property_or_throw(vm.names.dateStyle, PrimitiveString::create(vm, date_time_format->date_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.dateStyle, MUST_OR_THROW_OOM(PrimitiveString::create(vm, date_time_format->date_style_string()))));
|
||||
if (date_time_format->has_time_style())
|
||||
MUST(options->create_data_property_or_throw(vm.names.timeStyle, PrimitiveString::create(vm, date_time_format->time_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.timeStyle, MUST_OR_THROW_OOM(PrimitiveString::create(vm, date_time_format->time_style_string()))));
|
||||
|
||||
// 6. Return options.
|
||||
return options;
|
||||
|
|
|
@ -166,7 +166,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
|
|||
return vm.throw_completion<RangeError>(ErrorType::OptionIsNotValidValue, code, "dateTimeField"sv);
|
||||
|
||||
// b. Return code.
|
||||
return PrimitiveString::create(vm, code);
|
||||
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, code));
|
||||
}
|
||||
|
||||
// 6. Assert: type is "currency".
|
||||
|
|
|
@ -26,7 +26,7 @@ ThrowCompletionOr<void> DisplayNamesPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 12.3.2 Intl.DisplayNames.prototype[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.DisplayNames"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.DisplayNames"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, vm.names.of, of, 1, attr);
|
||||
|
@ -111,7 +111,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
|
|||
}
|
||||
|
||||
if (result.has_value())
|
||||
return PrimitiveString::create(vm, result.release_value());
|
||||
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, result.release_value()));
|
||||
if (formatted_result.has_value())
|
||||
return PrimitiveString::create(vm, formatted_result.release_value());
|
||||
|
||||
|
@ -141,13 +141,13 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
|
|||
// c. Assert: v is not undefined.
|
||||
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, display_names->locale())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, display_names->style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, display_names->type_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.fallback, PrimitiveString::create(vm, display_names->fallback_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, MUST_OR_THROW_OOM(PrimitiveString::create(vm, display_names->style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, display_names->type_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.fallback, MUST_OR_THROW_OOM(PrimitiveString::create(vm, display_names->fallback_string()))));
|
||||
|
||||
// NOTE: Step 4c indicates languageDisplay must not be undefined, but it is only set when the type option is language.
|
||||
if (display_names->has_language_display())
|
||||
MUST(options->create_data_property_or_throw(vm.names.languageDisplay, PrimitiveString::create(vm, display_names->language_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.languageDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, display_names->language_display_string()))));
|
||||
|
||||
// 5. Return options.
|
||||
return options;
|
||||
|
|
|
@ -492,14 +492,14 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
// ii. Else,
|
||||
else {
|
||||
// 1. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, "unit"sv)));
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.style, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "unit"sv))));
|
||||
|
||||
// 2. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, number_format_unit)));
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.unit, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format_unit))));
|
||||
|
||||
// 3. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
|
||||
auto unicode_style = ::Locale::style_to_string(static_cast<::Locale::Style>(style));
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, PrimitiveString::create(vm, unicode_style)));
|
||||
MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, unicode_style))));
|
||||
|
||||
// 4. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
|
||||
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)).ptr());
|
||||
|
@ -526,7 +526,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
auto list_format_options = Object::create(realm, nullptr);
|
||||
|
||||
// 5. Perform ! CreateDataPropertyOrThrow(lfOpts, "type", "unit").
|
||||
MUST(list_format_options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, "unit"sv)));
|
||||
MUST(list_format_options->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, "unit"sv))));
|
||||
|
||||
// 6. Let listStyle be durationFormat.[[Style]].
|
||||
auto list_style = duration_format.style();
|
||||
|
@ -540,7 +540,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
|
|||
auto unicode_list_style = ::Locale::style_to_string(static_cast<::Locale::Style>(list_style));
|
||||
|
||||
// 8. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle).
|
||||
MUST(list_format_options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, unicode_list_style)));
|
||||
MUST(list_format_options->create_data_property_or_throw(vm.names.style, MUST_OR_THROW_OOM(PrimitiveString::create(vm, unicode_list_style))));
|
||||
|
||||
// 9. Let lf be ! Construct(%ListFormat%, « durationFormat.[[Locale]], lfOpts »).
|
||||
auto* list_format = static_cast<ListFormat*>(MUST(construct(vm, *realm.intrinsics().intl_list_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), list_format_options)).ptr());
|
||||
|
|
|
@ -25,7 +25,7 @@ ThrowCompletionOr<void> DurationFormatPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 1.4.2 Intl.DurationFormat.prototype [ @@toStringTag ], https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.DurationFormat"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.DurationFormat"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, vm.names.format, format, 1, attr);
|
||||
|
@ -88,7 +88,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(obj, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, part.value)));
|
||||
|
@ -121,27 +121,27 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
|
|||
// c. Assert: v is not undefined.
|
||||
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, duration_format->locale())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, duration_format->style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.years, PrimitiveString::create(vm, duration_format->years_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.yearsDisplay, PrimitiveString::create(vm, duration_format->years_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.months, PrimitiveString::create(vm, duration_format->months_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.monthsDisplay, PrimitiveString::create(vm, duration_format->months_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.weeks, PrimitiveString::create(vm, duration_format->weeks_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.weeksDisplay, PrimitiveString::create(vm, duration_format->weeks_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.days, PrimitiveString::create(vm, duration_format->days_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.daysDisplay, PrimitiveString::create(vm, duration_format->days_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.hours, PrimitiveString::create(vm, duration_format->hours_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.hoursDisplay, PrimitiveString::create(vm, duration_format->hours_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.minutes, PrimitiveString::create(vm, duration_format->minutes_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.minutesDisplay, PrimitiveString::create(vm, duration_format->minutes_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.seconds, PrimitiveString::create(vm, duration_format->seconds_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.secondsDisplay, PrimitiveString::create(vm, duration_format->seconds_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.milliseconds, PrimitiveString::create(vm, duration_format->milliseconds_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.millisecondsDisplay, PrimitiveString::create(vm, duration_format->milliseconds_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.microseconds, PrimitiveString::create(vm, duration_format->microseconds_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.microsecondsDisplay, PrimitiveString::create(vm, duration_format->microseconds_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.nanoseconds, PrimitiveString::create(vm, duration_format->nanoseconds_style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.nanosecondsDisplay, PrimitiveString::create(vm, duration_format->nanoseconds_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.years, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->years_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.yearsDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->years_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.months, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->months_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.monthsDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->months_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.weeks, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->weeks_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.weeksDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->weeks_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.days, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->days_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.daysDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->days_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.hours, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->hours_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.hoursDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->hours_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.minutes, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->minutes_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.minutesDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->minutes_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.seconds, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->seconds_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.secondsDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->seconds_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.milliseconds, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->milliseconds_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.millisecondsDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->milliseconds_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.microseconds, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->microseconds_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.microsecondsDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->microseconds_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.nanoseconds, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->nanoseconds_style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.nanosecondsDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, duration_format->nanoseconds_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.fractionalDigits, duration_format->has_fractional_digits() ? Value(duration_format->fractional_digits()) : js_undefined()));
|
||||
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, PrimitiveString::create(vm, duration_format->numbering_system())));
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ ThrowCompletionOr<void> Intl::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 8.1.1 Intl[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl-toStringTag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_intrinsic_accessor(vm.names.Collator, attr, [](auto& realm) -> Value { return realm.intrinsics().intl_collator_constructor(); });
|
||||
|
@ -157,7 +157,9 @@ JS_DEFINE_NATIVE_FUNCTION(Intl::supported_values_of)
|
|||
}
|
||||
|
||||
// 9. Return CreateArrayFromList( list ).
|
||||
return Array::create_from<StringView>(realm, list, [&](auto value) { return PrimitiveString::create(vm, value); });
|
||||
return MUST_OR_THROW_OOM(Array::try_create_from<StringView>(vm, realm, list, [&](auto value) {
|
||||
return PrimitiveString::create(vm, value);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ ThrowCompletionOr<Array*> format_list_to_parts(VM& vm, ListFormat const& list_fo
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
|
||||
|
|
|
@ -25,7 +25,7 @@ ThrowCompletionOr<void> ListFormatPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 13.3.2 Intl.ListFormat.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype-toStringTag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.ListFormat"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.ListFormat"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, vm.names.format, format, 1, attr);
|
||||
|
@ -86,8 +86,8 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
|
|||
// c. Assert: v is not undefined.
|
||||
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, list_format->locale())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, list_format->type_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, list_format->style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, list_format->type_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, MUST_OR_THROW_OOM(PrimitiveString::create(vm, list_format->style_string()))));
|
||||
|
||||
// 5. Return options.
|
||||
return options;
|
||||
|
|
|
@ -31,7 +31,7 @@ ThrowCompletionOr<void> LocalePrototype::initialize(Realm& realm)
|
|||
define_native_function(realm, vm.names.toString, to_string, 0, attr);
|
||||
|
||||
// 14.3.2 Intl.Locale.prototype[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.Locale.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.Locale"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.Locale"sv)), Attribute::Configurable);
|
||||
|
||||
define_native_accessor(realm, vm.names.baseName, base_name, {}, Attribute::Configurable);
|
||||
define_native_accessor(realm, vm.names.calendar, calendar, {}, Attribute::Configurable);
|
||||
|
@ -266,7 +266,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
|
|||
auto direction = MUST_OR_THROW_OOM(character_direction_of_locale(vm, *locale_object));
|
||||
|
||||
// 5. Perform ! CreateDataPropertyOrThrow(info, "direction", dir).
|
||||
MUST(info->create_data_property_or_throw(vm.names.direction, PrimitiveString::create(vm, direction)));
|
||||
MUST(info->create_data_property_or_throw(vm.names.direction, MUST_OR_THROW_OOM(PrimitiveString::create(vm, direction))));
|
||||
|
||||
// 6. Return info.
|
||||
return info;
|
||||
|
|
|
@ -243,15 +243,15 @@ void NumberFormatBase::set_trailing_zero_display(StringView trailing_zero_displa
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Value NumberFormat::use_grouping_to_value(VM& vm) const
|
||||
ThrowCompletionOr<Value> NumberFormat::use_grouping_to_value(VM& vm) const
|
||||
{
|
||||
switch (m_use_grouping) {
|
||||
case UseGrouping::Always:
|
||||
return PrimitiveString::create(vm, "always"sv);
|
||||
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, "always"sv));
|
||||
case UseGrouping::Auto:
|
||||
return PrimitiveString::create(vm, "auto"sv);
|
||||
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, "auto"sv));
|
||||
case UseGrouping::Min2:
|
||||
return PrimitiveString::create(vm, "min2"sv);
|
||||
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, "min2"sv));
|
||||
case UseGrouping::False:
|
||||
return Value(false);
|
||||
default:
|
||||
|
@ -948,7 +948,7 @@ ThrowCompletionOr<Array*> format_numeric_to_parts(VM& vm, NumberFormat& number_f
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
|
||||
|
@ -1932,13 +1932,13 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& nu
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
|
||||
|
||||
// d. Perform ! CreateDataPropertyOrThrow(O, "source", part.[[Source]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.source, PrimitiveString::create(vm, part.source)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.source, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.source))));
|
||||
|
||||
// e. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).
|
||||
MUST(result->create_data_property_or_throw(n, object));
|
||||
|
|
|
@ -210,7 +210,7 @@ public:
|
|||
void set_unit_display(StringView unit_display) { m_unit_display = ::Locale::style_from_string(unit_display); }
|
||||
|
||||
UseGrouping use_grouping() const { return m_use_grouping; }
|
||||
Value use_grouping_to_value(VM&) const;
|
||||
ThrowCompletionOr<Value> use_grouping_to_value(VM&) const;
|
||||
void set_use_grouping(StringOrBoolean const& use_grouping);
|
||||
|
||||
Notation notation() const { return m_notation; }
|
||||
|
|
|
@ -26,7 +26,7 @@ ThrowCompletionOr<void> NumberFormatPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 15.3.2 Intl.NumberFormat.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.numberformat.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.NumberFormat"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.NumberFormat"sv)), Attribute::Configurable);
|
||||
|
||||
define_native_accessor(realm, vm.names.format, format, nullptr, Attribute::Configurable);
|
||||
|
||||
|
@ -156,17 +156,17 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
|
|||
// i. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, number_format->locale())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, PrimitiveString::create(vm, number_format->numbering_system())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, number_format->style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->style_string()))));
|
||||
if (number_format->has_currency())
|
||||
MUST(options->create_data_property_or_throw(vm.names.currency, PrimitiveString::create(vm, number_format->currency())));
|
||||
if (number_format->has_currency_display())
|
||||
MUST(options->create_data_property_or_throw(vm.names.currencyDisplay, PrimitiveString::create(vm, number_format->currency_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.currencyDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->currency_display_string()))));
|
||||
if (number_format->has_currency_sign())
|
||||
MUST(options->create_data_property_or_throw(vm.names.currencySign, PrimitiveString::create(vm, number_format->currency_sign_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.currencySign, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->currency_sign_string()))));
|
||||
if (number_format->has_unit())
|
||||
MUST(options->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, number_format->unit())));
|
||||
if (number_format->has_unit_display())
|
||||
MUST(options->create_data_property_or_throw(vm.names.unitDisplay, PrimitiveString::create(vm, number_format->unit_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.unitDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->unit_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.minimumIntegerDigits, Value(number_format->min_integer_digits())));
|
||||
if (number_format->has_min_fraction_digits())
|
||||
MUST(options->create_data_property_or_throw(vm.names.minimumFractionDigits, Value(number_format->min_fraction_digits())));
|
||||
|
@ -176,30 +176,30 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
|
|||
MUST(options->create_data_property_or_throw(vm.names.minimumSignificantDigits, Value(number_format->min_significant_digits())));
|
||||
if (number_format->has_max_significant_digits())
|
||||
MUST(options->create_data_property_or_throw(vm.names.maximumSignificantDigits, Value(number_format->max_significant_digits())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.useGrouping, number_format->use_grouping_to_value(vm)));
|
||||
MUST(options->create_data_property_or_throw(vm.names.notation, PrimitiveString::create(vm, number_format->notation_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.useGrouping, MUST_OR_THROW_OOM(number_format->use_grouping_to_value(vm))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.notation, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->notation_string()))));
|
||||
if (number_format->has_compact_display())
|
||||
MUST(options->create_data_property_or_throw(vm.names.compactDisplay, PrimitiveString::create(vm, number_format->compact_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.signDisplay, PrimitiveString::create(vm, number_format->sign_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.roundingMode, PrimitiveString::create(vm, number_format->rounding_mode_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.compactDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->compact_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.signDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->sign_display_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.roundingMode, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->rounding_mode_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.roundingIncrement, Value(number_format->rounding_increment())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.trailingZeroDisplay, PrimitiveString::create(vm, number_format->trailing_zero_display_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.trailingZeroDisplay, MUST_OR_THROW_OOM(PrimitiveString::create(vm, number_format->trailing_zero_display_string()))));
|
||||
|
||||
switch (number_format->rounding_type()) {
|
||||
// 6. If nf.[[RoundingType]] is morePrecision, then
|
||||
case NumberFormatBase::RoundingType::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;
|
||||
// 7. Else if nf.[[RoundingType]] is lessPrecision, then
|
||||
case NumberFormatBase::RoundingType::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;
|
||||
// 8. Else,
|
||||
default:
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ ThrowCompletionOr<void> PluralRulesPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 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;
|
||||
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]].
|
||||
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
|
||||
|
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
|
|||
|
||||
// 6. Return ? ResolvePluralRange(pr, 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
|
||||
|
@ -97,7 +97,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
|
|||
// c. If v is not undefined, then
|
||||
// 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.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())));
|
||||
if (plural_rules->has_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())));
|
||||
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.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.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]].
|
||||
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));
|
||||
});
|
||||
}));
|
||||
|
||||
// 6. Perform ! CreateDataProperty(options, "pluralCategories", CreateArrayFromList(pluralCategories)).
|
||||
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
|
||||
case NumberFormatBase::RoundingType::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;
|
||||
// 8. Else if pr.[[RoundingType]] is lessPrecision, then
|
||||
case NumberFormatBase::RoundingType::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;
|
||||
// 9. Else,
|
||||
default:
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeForm
|
|||
auto object = Object::create(realm, realm.intrinsics().object_prototype());
|
||||
|
||||
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, part.type)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.type, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.type))));
|
||||
|
||||
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.value, PrimitiveString::create(vm, move(part.value))));
|
||||
|
@ -270,7 +270,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeForm
|
|||
// d. If part.[[Unit]] is not empty, then
|
||||
if (!part.unit.is_empty()) {
|
||||
// i. Perform ! CreateDataPropertyOrThrow(O, "unit", part.[[Unit]]).
|
||||
MUST(object->create_data_property_or_throw(vm.names.unit, PrimitiveString::create(vm, part.unit)));
|
||||
MUST(object->create_data_property_or_throw(vm.names.unit, MUST_OR_THROW_OOM(PrimitiveString::create(vm, part.unit))));
|
||||
}
|
||||
|
||||
// e. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).
|
||||
|
|
|
@ -23,7 +23,7 @@ ThrowCompletionOr<void> RelativeTimeFormatPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 17.3.2 Intl.RelativeTimeFormat.prototype[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype-toStringTag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.RelativeTimeFormat"sv), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.RelativeTimeFormat"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, vm.names.format, format, 2, attr);
|
||||
|
@ -86,8 +86,8 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
|
|||
// c. Assert: v is not undefined.
|
||||
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, relative_time_format->locale())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, relative_time_format->style_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.numeric, PrimitiveString::create(vm, relative_time_format->numeric_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.style, MUST_OR_THROW_OOM(PrimitiveString::create(vm, relative_time_format->style_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.numeric, MUST_OR_THROW_OOM(PrimitiveString::create(vm, relative_time_format->numeric_string()))));
|
||||
MUST(options->create_data_property_or_throw(vm.names.numberingSystem, PrimitiveString::create(vm, relative_time_format->numbering_system())));
|
||||
|
||||
// 5. Return options.
|
||||
|
|
|
@ -25,7 +25,7 @@ ThrowCompletionOr<void> SegmentIteratorPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 18.6.2.2 %SegmentIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma402/#sec-%segmentiteratorprototype%.@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Segmenter String Iterator"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Segmenter String Iterator"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, vm.names.next, next, 0, attr);
|
||||
|
|
|
@ -24,7 +24,7 @@ ThrowCompletionOr<void> SegmenterPrototype::initialize(Realm& realm)
|
|||
auto& vm = this->vm();
|
||||
|
||||
// 18.3.2 Intl.Segmenter.prototype [ @@toStringTag ], https://tc39.es/ecma402/#sec-intl.segmenter.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Intl.Segmenter"), Attribute::Configurable);
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Intl.Segmenter"sv)), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_native_function(realm, vm.names.resolvedOptions, resolved_options, 0, attr);
|
||||
|
@ -51,7 +51,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
|
|||
// c. Assert: v is not undefined.
|
||||
// d. Perform ! CreateDataPropertyOrThrow(options, p, v).
|
||||
MUST(options->create_data_property_or_throw(vm.names.locale, PrimitiveString::create(vm, segmenter->locale())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.granularity, PrimitiveString::create(vm, segmenter->segmenter_granularity_string())));
|
||||
MUST(options->create_data_property_or_throw(vm.names.granularity, MUST_OR_THROW_OOM(PrimitiveString::create(vm, segmenter->segmenter_granularity_string()))));
|
||||
|
||||
// 5. Return options.
|
||||
return options;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue