1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:07:44 +00:00

LibJS: Replace standalone js_string() with PrimitiveString::create()

Note that js_rope_string() has been folded into this, the old name was
misleading - it would not always create a rope string, only if both
sides are not empty strings. Use a three-argument create() overload
instead.
This commit is contained in:
Linus Groh 2022-12-06 22:17:27 +00:00
parent 5db38d7ba1
commit 525f22d018
144 changed files with 656 additions and 672 deletions

View file

@ -401,7 +401,7 @@ Vector<PatternPartition> partition_duration_format_pattern(VM& vm, DurationForma
// i. If style is "2-digit" or "numeric", then
if (style == DurationFormat::ValueStyle::TwoDigit || style == DurationFormat::ValueStyle::Numeric) {
// 1. Let nf be ! Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)));
// 2. Let dataLocale be durationFormat.[[DataLocale]].
auto const& data_locale = duration_format.data_locale();
@ -455,17 +455,17 @@ Vector<PatternPartition> partition_duration_format_pattern(VM& vm, DurationForma
// ii. Else,
else {
// 1. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
MUST(number_format_options->create_data_property_or_throw(vm.names.style, js_string(vm, "unit"sv)));
MUST(number_format_options->create_data_property_or_throw(vm.names.style, PrimitiveString::create(vm, "unit"sv)));
// 2. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
MUST(number_format_options->create_data_property_or_throw(vm.names.unit, js_string(vm, number_format_unit)));
MUST(number_format_options->create_data_property_or_throw(vm.names.unit, 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, js_string(vm, unicode_style)));
MUST(number_format_options->create_data_property_or_throw(vm.names.unitDisplay, 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(), js_string(vm, duration_format.locale()), number_format_options)));
auto* number_format = static_cast<NumberFormat*>(MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), number_format_options)));
// 5. Let parts be ! PartitionNumberPattern(nf, 𝔽(value)).
auto parts = partition_number_pattern(vm, *number_format, MathematicalValue(value));
@ -489,7 +489,7 @@ Vector<PatternPartition> partition_duration_format_pattern(VM& vm, DurationForma
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, js_string(vm, "unit"sv)));
MUST(list_format_options->create_data_property_or_throw(vm.names.type, PrimitiveString::create(vm, "unit"sv)));
// 6. Let listStyle be durationFormat.[[Style]].
auto list_style = duration_format.style();
@ -503,10 +503,10 @@ Vector<PatternPartition> partition_duration_format_pattern(VM& vm, DurationForma
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, js_string(vm, unicode_list_style)));
MUST(list_format_options->create_data_property_or_throw(vm.names.style, 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(), js_string(vm, duration_format.locale()), list_format_options)));
auto* list_format = static_cast<ListFormat*>(MUST(construct(vm, *realm.intrinsics().intl_list_format_constructor(), PrimitiveString::create(vm, duration_format.locale()), list_format_options)));
// FIXME: CreatePartsFromList expects a list of strings and creates a list of Pattern Partition records, but we already created a list of Pattern Partition records
// so we try to hack something together from it that looks mostly right