From c1e99fca1adf0b18118d1f18c9cd7a9721e2b91e Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 9 Aug 2021 09:06:45 -0400 Subject: [PATCH] LibJS: Replace Vector usage in PrimitiveString wth Utf16String This commit does not go out of its way to reduce copying of the string data yet, but is a minimum set of changes to compile LibJS after making PrimitiveString hold a Utf16String. --- .../LibJS/Runtime/AbstractOperations.cpp | 3 +- .../LibJS/Runtime/PrimitiveString.cpp | 32 +++------ .../Libraries/LibJS/Runtime/PrimitiveString.h | 12 ++-- .../LibJS/Runtime/RegExpPrototype.cpp | 21 +++--- .../LibJS/Runtime/RegExpStringIterator.cpp | 4 +- .../LibJS/Runtime/RegExpStringIterator.h | 9 +-- .../Runtime/RegExpStringIteratorPrototype.cpp | 1 + .../LibJS/Runtime/StringConstructor.cpp | 5 +- .../LibJS/Runtime/StringPrototype.cpp | 72 +++++++++---------- Userland/Libraries/LibJS/Runtime/Value.cpp | 5 +- Userland/Libraries/LibJS/Runtime/Value.h | 3 +- 11 files changed, 80 insertions(+), 87 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp index 11b96779e6..d637785a15 100644 --- a/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/AbstractOperations.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace JS { @@ -576,7 +577,7 @@ String get_substitution(GlobalObject& global_object, Utf16View const& matched, U auto replace_string = replacement.to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View replace_view { replace_string }; + auto replace_view = replace_string.view(); StringBuilder result; diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp index 1d7e74cee2..17c947c349 100644 --- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp +++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.cpp @@ -17,7 +17,7 @@ PrimitiveString::PrimitiveString(String string) { } -PrimitiveString::PrimitiveString(Vector string) +PrimitiveString::PrimitiveString(Utf16String string) : m_utf16_string(move(string)) , m_has_utf16_string(true) { @@ -30,16 +30,16 @@ PrimitiveString::~PrimitiveString() String const& PrimitiveString::string() const { if (!m_has_utf8_string) { - m_utf8_string = utf16_string_view().to_utf8(Utf16View::AllowInvalidCodeUnits::Yes); + m_utf8_string = m_utf16_string.to_utf8(); m_has_utf8_string = true; } return m_utf8_string; } -Vector const& PrimitiveString::utf16_string() const +Utf16String const& PrimitiveString::utf16_string() const { if (!m_has_utf16_string) { - m_utf16_string = AK::utf8_to_utf16(m_utf8_string); + m_utf16_string = Utf16String(m_utf8_string); m_has_utf16_string = true; } return m_utf16_string; @@ -47,24 +47,12 @@ Vector const& PrimitiveString::utf16_string() const Utf16View PrimitiveString::utf16_string_view() const { - return Utf16View { utf16_string() }; + return utf16_string().view(); } PrimitiveString* js_string(Heap& heap, Utf16View const& view) { - if (view.is_empty()) - return &heap.vm().empty_string(); - - if (view.length_in_code_units() == 1) { - u16 code_unit = view.code_unit_at(0); - if (is_ascii(code_unit)) - return &heap.vm().single_ascii_character_string(static_cast(code_unit)); - } - - Vector string; - string.ensure_capacity(view.length_in_code_units()); - string.append(view.data(), view.length_in_code_units()); - return js_string(heap, move(string)); + return js_string(heap, Utf16String(view)); } PrimitiveString* js_string(VM& vm, Utf16View const& view) @@ -72,13 +60,13 @@ PrimitiveString* js_string(VM& vm, Utf16View const& view) return js_string(vm.heap(), view); } -PrimitiveString* js_string(Heap& heap, Vector string) +PrimitiveString* js_string(Heap& heap, Utf16String string) { if (string.is_empty()) return &heap.vm().empty_string(); - if (string.size() == 1) { - u16 code_unit = string.at(0); + if (string.length_in_code_units() == 1) { + u16 code_unit = string.code_unit_at(0); if (is_ascii(code_unit)) return &heap.vm().single_ascii_character_string(static_cast(code_unit)); } @@ -86,7 +74,7 @@ PrimitiveString* js_string(Heap& heap, Vector string) return heap.allocate_without_global_object(move(string)); } -PrimitiveString* js_string(VM& vm, Vector string) +PrimitiveString* js_string(VM& vm, Utf16String string) { return js_string(vm.heap(), move(string)); } diff --git a/Userland/Libraries/LibJS/Runtime/PrimitiveString.h b/Userland/Libraries/LibJS/Runtime/PrimitiveString.h index 945205d51f..5f27e63b50 100644 --- a/Userland/Libraries/LibJS/Runtime/PrimitiveString.h +++ b/Userland/Libraries/LibJS/Runtime/PrimitiveString.h @@ -7,15 +7,15 @@ #pragma once #include -#include #include +#include namespace JS { class PrimitiveString final : public Cell { public: explicit PrimitiveString(String); - explicit PrimitiveString(Vector); + explicit PrimitiveString(Utf16String); virtual ~PrimitiveString(); PrimitiveString(PrimitiveString const&) = delete; @@ -23,7 +23,7 @@ public: String const& string() const; - Vector const& utf16_string() const; + Utf16String const& utf16_string() const; Utf16View utf16_string_view() const; private: @@ -32,15 +32,15 @@ private: mutable String m_utf8_string; mutable bool m_has_utf8_string { false }; - mutable Vector m_utf16_string; + mutable Utf16String m_utf16_string; mutable bool m_has_utf16_string { false }; }; PrimitiveString* js_string(Heap&, Utf16View const&); PrimitiveString* js_string(VM&, Utf16View const&); -PrimitiveString* js_string(Heap&, Vector); -PrimitiveString* js_string(VM&, Vector); +PrimitiveString* js_string(Heap&, Utf16String); +PrimitiveString* js_string(VM&, Utf16String); PrimitiveString* js_string(Heap&, String); PrimitiveString* js_string(VM&, String); diff --git a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp index 75d2d1b359..cb9311f98a 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpPrototype.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace JS { @@ -414,7 +415,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::exec) auto string = vm.argument(0).to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View string_view { string }; + auto string_view = string.view(); return regexp_builtin_exec(global_object, *regexp_object, string_view); } @@ -429,7 +430,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::test) auto string = vm.argument(0).to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View string_view { string }; + auto string_view = string.view(); auto match = regexp_exec(global_object, *regexp_object, string_view); if (vm.exception()) @@ -472,7 +473,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_match) auto string = vm.argument(0).to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View string_view { string }; + auto string_view = string.view(); auto global_value = regexp_object->get(vm.names.global); if (vm.exception()) @@ -597,7 +598,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) auto string = string_value.to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View string_view { string }; + auto string_view = string.view(); if (!replace_value.is_function()) { auto replace_string = replace_value.to_string(global_object); @@ -672,7 +673,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) auto matched = matched_value.to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View matched_view { matched }; + auto matched_length = matched.length_in_code_units(); auto position_value = result.get(vm.names.index); if (vm.exception()) @@ -711,7 +712,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) if (replace_value.is_function()) { MarkedValueList replacer_args(vm.heap()); - replacer_args.append(js_string(vm, matched_view)); + replacer_args.append(js_string(vm, move(matched))); replacer_args.extend(move(captures)); replacer_args.append(Value(position)); replacer_args.append(js_string(vm, string_view)); @@ -734,7 +735,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) return {}; } - replacement = get_substitution(global_object, matched_view, string_view, position, captures, named_captures_object, replace_value); + replacement = get_substitution(global_object, matched.view(), string_view, position, captures, named_captures_object, replace_value); if (vm.exception()) return {}; } @@ -748,7 +749,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_replace) builder.append(replacement); accumulated_result = builder.build(); - next_source_position = position + matched_view.length_in_code_units(); + next_source_position = position + matched_length; } } @@ -774,7 +775,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_search) auto string = vm.argument(0).to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View string_view { string }; + auto string_view = string.view(); auto previous_last_index = regexp_object->get(vm.names.lastIndex); if (vm.exception()) @@ -822,7 +823,7 @@ JS_DEFINE_NATIVE_FUNCTION(RegExpPrototype::symbol_split) auto string = vm.argument(0).to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View string_view { string }; + auto string_view = string.view(); auto* constructor = species_constructor(global_object, *regexp_object, *global_object.regexp_constructor()); if (vm.exception()) diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp index 2a6508811e..93d6e24603 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.cpp @@ -10,12 +10,12 @@ namespace JS { // 22.2.7.1 CreateRegExpStringIterator ( R, S, global, fullUnicode ), https://tc39.es/ecma262/#sec-createregexpstringiterator -RegExpStringIterator* RegExpStringIterator::create(GlobalObject& global_object, Object& regexp_object, Vector string, bool global, bool unicode) +RegExpStringIterator* RegExpStringIterator::create(GlobalObject& global_object, Object& regexp_object, Utf16String string, bool global, bool unicode) { return global_object.heap().allocate(global_object, *global_object.regexp_string_iterator_prototype(), regexp_object, move(string), global, unicode); } -RegExpStringIterator::RegExpStringIterator(Object& prototype, Object& regexp_object, Vector string, bool global, bool unicode) +RegExpStringIterator::RegExpStringIterator(Object& prototype, Object& regexp_object, Utf16String string, bool global, bool unicode) : Object(prototype) , m_regexp_object(regexp_object) , m_string(move(string)) diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h index 849d3a0669..760563a277 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h +++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIterator.h @@ -8,6 +8,7 @@ #include #include +#include namespace JS { @@ -15,13 +16,13 @@ class RegExpStringIterator final : public Object { JS_OBJECT(RegExpStringIterator, Object); public: - static RegExpStringIterator* create(GlobalObject&, Object& regexp_object, Vector string, bool global, bool unicode); + static RegExpStringIterator* create(GlobalObject&, Object& regexp_object, Utf16String string, bool global, bool unicode); - explicit RegExpStringIterator(Object& prototype, Object& regexp_object, Vector string, bool global, bool unicode); + explicit RegExpStringIterator(Object& prototype, Object& regexp_object, Utf16String string, bool global, bool unicode); virtual ~RegExpStringIterator() override = default; Object& regexp_object() { return m_regexp_object; } - Utf16View string() const { return Utf16View { m_string }; } + Utf16View string() const { return m_string.view(); } bool global() const { return m_global; } bool unicode() const { return m_unicode; } @@ -32,7 +33,7 @@ private: virtual void visit_edges(Cell::Visitor&) override; Object& m_regexp_object; - Vector m_string; + Utf16String m_string; bool m_global { false }; bool m_unicode { false }; bool m_done { false }; diff --git a/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp index f2d9da2458..063d4618bb 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpStringIteratorPrototype.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace JS { diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp index f222e1b004..1273bb92ea 100644 --- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace JS { @@ -135,7 +136,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_char_code) string.append(code_unit); } - return js_string(vm, move(string)); + return js_string(vm, Utf16String(move(string))); } // 22.1.2.2 String.fromCodePoint ( ...codePoints ), https://tc39.es/ecma262/#sec-string.fromcodepoint @@ -161,7 +162,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringConstructor::from_code_point) AK::code_point_to_utf16(string, static_cast(code_point)); } - return js_string(vm, move(string)); + return js_string(vm, Utf16String(move(string))); } } diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index 7ac6f43b77..9f0a07dc30 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -33,7 +34,7 @@ static Optional ak_string_from(VM& vm, GlobalObject& global_object) return this_value.to_string(global_object); } -static Vector utf16_string_from(VM& vm, GlobalObject& global_object) +static Utf16String utf16_string_from(VM& vm, GlobalObject& global_object) { auto this_value = require_object_coercible(global_object, vm.this_value(global_object)); if (vm.exception()) @@ -186,7 +187,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_at) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); if (position < 0 || position >= utf16_string_view.length_in_code_units()) return js_string(vm, String::empty()); @@ -203,7 +204,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::char_code_at) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); if (position < 0 || position >= utf16_string_view.length_in_code_units()) return js_nan(); @@ -220,7 +221,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::code_point_at) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); if (position < 0 || position >= utf16_string_view.length_in_code_units()) return js_undefined(); @@ -283,10 +284,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::starts_with) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto string_length = utf16_string_view.length_in_code_units(); - Utf16View utf16_search_view { search_string }; + auto utf16_search_view = search_string.view(); auto search_length = utf16_search_view.length_in_code_units(); size_t start = 0; @@ -329,10 +330,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::ends_with) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto string_length = utf16_string_view.length_in_code_units(); - Utf16View utf16_search_view { search_string }; + auto utf16_search_view = search_string.view(); auto search_length = utf16_search_view.length_in_code_units(); size_t end = string_length; @@ -365,8 +366,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::index_of) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; - Utf16View utf16_search_view { search_string }; + auto utf16_string_view = string.view(); + auto utf16_search_view = search_string.view(); size_t start = 0; if (vm.argument_count() > 1) { @@ -448,15 +449,14 @@ static Value pad_string(GlobalObject& global_object, String const& string, PadPl { auto& vm = global_object.vm(); - auto utf16_string = AK::utf8_to_utf16(string); - Utf16View utf16_string_view { utf16_string }; - auto string_length = utf16_string_view.length_in_code_units(); + Utf16String utf16_string(string); + auto string_length = utf16_string.length_in_code_units(); auto max_length = vm.argument(0).to_length(global_object); if (vm.exception()) return {}; if (max_length <= string_length) - return js_string(vm, utf16_string_view); + return js_string(vm, move(utf16_string)); String fill_string = " "; if (!vm.argument(1).is_undefined()) { @@ -464,11 +464,11 @@ static Value pad_string(GlobalObject& global_object, String const& string, PadPl if (vm.exception()) return {}; if (fill_string.is_empty()) - return js_string(vm, utf16_string_view); + return js_string(vm, move(utf16_string)); } - auto utf16_fill_string = AK::utf8_to_utf16(fill_string); - Utf16View utf16_fill_view { utf16_fill_string }; + Utf16String utf16_fill_string(fill_string); + auto utf16_fill_view = utf16_fill_string.view(); auto fill_code_units = utf16_fill_view.length_in_code_units(); auto fill_length = max_length - string_length; @@ -558,7 +558,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substring) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto string_length = static_cast(utf16_string_view.length_in_code_units()); auto start = vm.argument(0).to_integer_or_infinity(global_object); @@ -588,7 +588,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::substr) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto size = utf16_string_view.length_in_code_units(); auto int_start = vm.argument(0).to_integer_or_infinity(global_object); @@ -637,8 +637,8 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::includes) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; - Utf16View utf16_search_view { search_string }; + auto utf16_string_view = string.view(); + auto utf16_search_view = search_string.view(); size_t start = 0; if (!vm.argument(1).is_undefined()) { @@ -659,7 +659,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::slice) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto string_length = static_cast(utf16_string_view.length_in_code_units()); auto int_start = vm.argument(0).to_integer_or_infinity(global_object); @@ -730,10 +730,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::split) if (limit == 0) return array; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto string_length = utf16_string_view.length_in_code_units(); - Utf16View utf16_separator_view { separator }; + auto utf16_separator_view = separator.view(); auto separator_length = utf16_separator_view.length_in_code_units(); if (separator_argument.is_undefined()) { @@ -782,10 +782,10 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::last_index_of) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto string_length = utf16_string_view.length_in_code_units(); - Utf16View utf16_search_view { search_string }; + auto utf16_search_view = search_string.view(); auto search_length = utf16_search_view.length_in_code_units(); auto position = vm.argument(1).to_number(global_object); @@ -822,7 +822,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::at) if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto length = utf16_string_view.length_in_code_units(); auto relative_index = vm.argument(0).to_integer_or_infinity(global_object); @@ -873,7 +873,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match) auto string = this_object.to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto rx = regexp_create(global_object, regexp, js_undefined()); if (!rx) @@ -916,7 +916,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::match_all) auto string = this_object.to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto rx = regexp_create(global_object, regexp, js_string(vm, "g")); if (!rx) @@ -951,13 +951,13 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace) auto replace_string = replace_value.to_utf16_string(global_object); if (vm.exception()) return {}; - replace_value = js_string(vm, Utf16View { replace_string }); + replace_value = js_string(vm, move(replace_string)); if (vm.exception()) return {}; } - Utf16View utf16_string_view { string }; - Utf16View utf16_search_view { search_string }; + auto utf16_string_view = string.view(); + auto utf16_search_view = search_string.view(); Optional position = string_index_of(utf16_string_view, utf16_search_view, 0); if (!position.has_value()) @@ -1042,15 +1042,15 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::replace_all) auto replace_string = replace_value.to_utf16_string(global_object); if (vm.exception()) return {}; - replace_value = js_string(vm, Utf16View { replace_string }); + replace_value = js_string(vm, move(replace_string)); if (vm.exception()) return {}; } - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto string_length = utf16_string_view.length_in_code_units(); - Utf16View utf16_search_view { search_string }; + auto utf16_search_view = search_string.view(); auto search_length = utf16_search_view.length_in_code_units(); Vector match_positions; @@ -1114,7 +1114,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::search) auto string = this_object.to_utf16_string(global_object); if (vm.exception()) return {}; - Utf16View utf16_string_view { string }; + auto utf16_string_view = string.view(); auto rx = regexp_create(global_object, regexp, js_undefined()); if (!rx) diff --git a/Userland/Libraries/LibJS/Runtime/Value.cpp b/Userland/Libraries/LibJS/Runtime/Value.cpp index 13d3b4b3fc..db3e22cb9c 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.cpp +++ b/Userland/Libraries/LibJS/Runtime/Value.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -363,7 +362,7 @@ String Value::to_string(GlobalObject& global_object, bool legacy_null_to_empty_s } } -Vector Value::to_utf16_string(GlobalObject& global_object) const +Utf16String Value::to_utf16_string(GlobalObject& global_object) const { if (m_type == Type::String) return m_value.as_string->utf16_string(); @@ -372,7 +371,7 @@ Vector Value::to_utf16_string(GlobalObject& global_object) const if (global_object.vm().exception()) return {}; - return AK::utf8_to_utf16(utf8_string); + return Utf16String(utf8_string); } // 7.1.2 ToBoolean ( argument ), https://tc39.es/ecma262/#sec-toboolean diff --git a/Userland/Libraries/LibJS/Runtime/Value.h b/Userland/Libraries/LibJS/Runtime/Value.h index 187848ee3a..895a83c2d1 100644 --- a/Userland/Libraries/LibJS/Runtime/Value.h +++ b/Userland/Libraries/LibJS/Runtime/Value.h @@ -18,6 +18,7 @@ #include #include #include +#include #include // 2 ** 53 - 1 @@ -246,7 +247,7 @@ public: u64 encoded() const { return m_value.encoded; } String to_string(GlobalObject&, bool legacy_null_to_empty_string = false) const; - Vector to_utf16_string(GlobalObject&) const; + Utf16String to_utf16_string(GlobalObject&) const; PrimitiveString* to_primitive_string(GlobalObject&); Value to_primitive(GlobalObject&, PreferredType preferred_type = PreferredType::Default) const; Object* to_object(GlobalObject&) const;