summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-27 15:57:43 -0500
committerLinus Groh <mail@linusgroh.de>2023-01-28 00:13:59 +0000
commit8dc4e05ecfc1d5176acf2d64012685dd52ee12bc (patch)
tree0c2bbc670ed25bbbd1e2e076383d0f599e7c3190
parent4c8f7d76c4160cf283ec7c901fc55ab909b2fb0f (diff)
downloadserenity-8dc4e05ecfc1d5176acf2d64012685dd52ee12bc.zip
LibJS: Port Intl.DurationFormat to String
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp10
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h7
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp4
-rw-r--r--Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp7
4 files changed, 14 insertions, 14 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
index 98aad7d72d..f7cfc73856 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.cpp
@@ -268,10 +268,10 @@ bool is_valid_duration_record(Temporal::DurationRecord const& record)
}
// 1.1.6 GetDurationUnitOptions ( unit, options, baseStyle, stylesList, digitalBase, prevStyle ), https://tc39.es/proposal-intl-duration-format/#sec-getdurationunitoptions
-ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, DeprecatedString const& unit, Object const& options, StringView base_style, Span<StringView const> styles_list, StringView digital_base, StringView previous_style)
+ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, String const& unit, Object const& options, StringView base_style, Span<StringView const> styles_list, StringView digital_base, StringView previous_style)
{
// 1. Let style be ? GetOption(options, unit, string, stylesList, undefined).
- auto style_value = TRY(get_option(vm, options, unit, OptionType::String, styles_list, Empty {}));
+ auto style_value = TRY(get_option(vm, options, unit.to_deprecated_string(), OptionType::String, styles_list, Empty {}));
// 2. Let displayDefault be "always".
auto display_default = "always"sv;
@@ -312,10 +312,10 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, Depreca
}
// 4. Let displayField be the string-concatenation of unit and "Display".
- auto display_field = DeprecatedString::formatted("{}Display", unit);
+ auto display_field = TRY_OR_THROW_OOM(vm, String::formatted("{}Display", unit));
// 5. Let display be ? GetOption(options, displayField, string, ยซ "auto", "always" ยป, displayDefault).
- auto display = TRY(get_option(vm, options, display_field, OptionType::String, { "auto"sv, "always"sv }, display_default));
+ auto display = TRY(get_option(vm, options, display_field.to_deprecated_string(), OptionType::String, { "auto"sv, "always"sv }, display_default));
// 6. If prevStyle is "numeric" or "2-digit", then
if (previous_style == "numeric"sv || previous_style == "2-digit"sv) {
@@ -332,7 +332,7 @@ ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM& vm, Depreca
}
// 7. Return the Record { [[Style]]: style, [[Display]]: display }.
- return DurationUnitOptions { .style = move(style), .display = TRY(display.as_string().deprecated_string()) };
+ return DurationUnitOptions { .style = TRY_OR_THROW_OOM(vm, String::from_utf8(style)), .display = TRY(display.as_string().utf8_string()) };
}
// 1.1.7 PartitionDurationFormatPattern ( durationFormat, duration ), https://tc39.es/proposal-intl-duration-format/#sec-partitiondurationformatpattern
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h
index c298a73392..a3816044f1 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormat.h
@@ -8,7 +8,6 @@
#pragma once
#include <AK/Array.h>
-#include <AK/DeprecatedString.h>
#include <AK/String.h>
#include <LibJS/Runtime/Intl/AbstractOperations.h>
#include <LibJS/Runtime/Object.h>
@@ -218,14 +217,14 @@ static constexpr AK::Array<DurationInstanceComponent, 10> duration_instances_com
};
struct DurationUnitOptions {
- DeprecatedString style;
- DeprecatedString display;
+ String style;
+ String display;
};
ThrowCompletionOr<Temporal::DurationRecord> to_duration_record(VM&, Value input);
i8 duration_record_sign(Temporal::DurationRecord const&);
bool is_valid_duration_record(Temporal::DurationRecord const&);
-ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM&, DeprecatedString const& unit, Object const& options, StringView base_style, Span<StringView const> styles_list, StringView digital_base, StringView previous_style);
+ThrowCompletionOr<DurationUnitOptions> get_duration_unit_options(VM&, String const& unit, Object const& options, StringView base_style, Span<StringView const> styles_list, StringView digital_base, StringView previous_style);
ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM&, DurationFormat const&, Temporal::DurationRecord const& duration);
}
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp
index 12161f3867..67d254f24c 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatConstructor.cpp
@@ -99,7 +99,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DurationFormatConstructor::construct(Fun
duration_format->set_data_locale(move(result.data_locale));
// 16. Let prevStyle be the empty String.
- auto previous_style = DeprecatedString::empty();
+ String previous_style {};
// 17. For each row of Table 1, except the header row, in table order, do
for (auto const& duration_instances_component : duration_instances_components) {
@@ -110,7 +110,7 @@ ThrowCompletionOr<NonnullGCPtr<Object>> DurationFormatConstructor::construct(Fun
auto display_slot = duration_instances_component.set_display_slot;
// c. Let unit be the Unit value.
- auto unit = duration_instances_component.unit;
+ auto unit = TRY_OR_THROW_OOM(vm, String::from_utf8(duration_instances_component.unit));
// d. Let valueList be the Values value.
auto value_list = duration_instances_component.values;
diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
index d9d47c11fd..da2c9a8ae7 100644
--- a/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
+++ b/Userland/Libraries/LibJS/Runtime/Intl/DurationFormatPrototype.cpp
@@ -8,6 +8,7 @@
#include <LibJS/Runtime/Array.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Intl/DurationFormatPrototype.h>
+#include <LibJS/Runtime/ThrowableStringBuilder.h>
namespace JS::Intl {
@@ -46,16 +47,16 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
auto parts = MUST_OR_THROW_OOM(partition_duration_format_pattern(vm, *duration_format, record));
// 5. Let result be a new empty String.
- StringBuilder result;
+ ThrowableStringBuilder result(vm);
// 6. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto const& part : parts) {
// a. Set result to the string-concatenation of result and part.[[Value]].
- result.append(part.value);
+ MUST_OR_THROW_OOM(result.append(part.value));
}
// 7. Return result.
- return PrimitiveString::create(vm, result.to_deprecated_string());
+ return PrimitiveString::create(vm, MUST_OR_THROW_OOM(result.to_string()));
}
// 1.4.4 Intl.DurationFormat.prototype.formatToParts ( duration ), https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype.formatToParts