1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 12:48:10 +00:00

LibJS: Change Intl's PatternPartition record to hold a String value

It was previously holding a StringView, which was either a view into a
LibUnicode-generated string or a string passed from the user.

Intl.NumberFormat will need this record to hold internally-created
strings, so a StringView will not suffice (the way the steps are laid
out, that view will ultimately end up dangling).

This shouldn't be too wasteful since the StringView it was holding was
converted to a String eventually anyways.
This commit is contained in:
Timothy Flynn 2021-11-10 12:48:07 -05:00 committed by Linus Groh
parent be69eae651
commit 0469006263
2 changed files with 7 additions and 7 deletions

View file

@ -83,14 +83,14 @@ Vector<PatternPartition> deconstruct_pattern(StringView pattern, Placeables plac
Vector<PatternPartition> result {};
// 3. For each Record { [[Type]], [[Value]] } patternPart of patternParts, do
for (auto const& pattern_part : pattern_parts) {
for (auto& pattern_part : pattern_parts) {
// a. Let part be patternPart.[[Type]].
auto part = pattern_part.type;
// b. If part is "literal", then
if (part == "literal"sv) {
// i. Append Record { [[Type]]: "literal", [[Value]]: patternPart.[[Value]] } to result.
result.append({ part, pattern_part.value });
result.append({ part, move(pattern_part.value) });
}
// c. Else,
else {
@ -219,9 +219,9 @@ String format_list(ListFormat const& list_format, Vector<String> const& list)
StringBuilder result;
// 3. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto const& part : parts) {
for (auto& part : parts) {
// a. Set result to the string-concatenation of result and part.[[Value]].
result.append(part.value);
result.append(move(part.value));
}
// 4. Return result.
@ -243,7 +243,7 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_
size_t n = 0;
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto const& part : parts) {
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(global_object, global_object.object_prototype());
@ -251,7 +251,7 @@ Array* format_list_to_parts(GlobalObject& global_object, ListFormat const& list_
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
// c. Perform ! CreateDataPropertyOrThrow(O, "value", part.[[Value]]).
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, part.value)));
MUST(object->create_data_property_or_throw(vm.names.value, js_string(vm, move(part.value))));
// d. Perform ! CreateDataPropertyOrThrow(result, ! ToString(n), O).
MUST(result->create_data_property_or_throw(n, object));