diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-14 23:17:49 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-16 10:12:37 +0000 |
commit | b6b5ddeb3b34e88f264bdea5d910c00851c00e8d (patch) | |
tree | efb5aedab7efeb574ef38c2813c0f3d6344c4024 /Userland | |
parent | 0d47c4e7a0b946972a4a190ebf1644eaacd329e6 (diff) | |
download | serenity-b6b5ddeb3b34e88f264bdea5d910c00851c00e8d.zip |
LibJS: Port StringIterator to String
Diffstat (limited to 'Userland')
4 files changed, 10 insertions, 9 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp index 5b3a92131d..03dd0e3dbf 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIterator.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringIterator.cpp @@ -10,12 +10,12 @@ namespace JS { -NonnullGCPtr<StringIterator> StringIterator::create(Realm& realm, DeprecatedString string) +NonnullGCPtr<StringIterator> StringIterator::create(Realm& realm, String string) { return realm.heap().allocate<StringIterator>(realm, move(string), *realm.intrinsics().string_iterator_prototype()); } -StringIterator::StringIterator(DeprecatedString string, Object& prototype) +StringIterator::StringIterator(String string, Object& prototype) : Object(ConstructWithPrototypeTag::Tag, prototype) , m_string(move(string)) , m_iterator(Utf8View(m_string).begin()) diff --git a/Userland/Libraries/LibJS/Runtime/StringIterator.h b/Userland/Libraries/LibJS/Runtime/StringIterator.h index f419caabc4..262a3e1c0f 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIterator.h +++ b/Userland/Libraries/LibJS/Runtime/StringIterator.h @@ -6,6 +6,7 @@ #pragma once +#include <AK/String.h> #include <AK/Utf8View.h> #include <LibJS/Runtime/Object.h> @@ -15,7 +16,7 @@ class StringIterator final : public Object { JS_OBJECT(StringIterator, Object); public: - static NonnullGCPtr<StringIterator> create(Realm&, DeprecatedString string); + static NonnullGCPtr<StringIterator> create(Realm&, String string); virtual ~StringIterator() override = default; @@ -23,11 +24,11 @@ public: bool done() const { return m_done; } private: - explicit StringIterator(DeprecatedString string, Object& prototype); + explicit StringIterator(String string, Object& prototype); friend class StringIteratorPrototype; - DeprecatedString m_string; + String m_string; Utf8CodePointIterator m_iterator; bool m_done { false }; }; diff --git a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp index b9932f0955..174672d79e 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp @@ -4,12 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include <AK/StringBuilder.h> #include <AK/TypeCasts.h> #include <LibJS/Runtime/Error.h> #include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/StringIteratorPrototype.h> +#include <LibJS/Runtime/ThrowableStringBuilder.h> namespace JS { @@ -42,11 +42,11 @@ JS_DEFINE_NATIVE_FUNCTION(StringIteratorPrototype::next) return create_iterator_result_object(vm, js_undefined(), true); } - StringBuilder builder; + ThrowableStringBuilder builder(vm); builder.append_code_point(*utf8_iterator); ++utf8_iterator; - return create_iterator_result_object(vm, PrimitiveString::create(vm, builder.to_deprecated_string()), false); + return create_iterator_result_object(vm, PrimitiveString::create(vm, TRY(builder.to_string())), false); } } diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index c2788deadd..a16dc23480 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -1074,7 +1074,7 @@ JS_DEFINE_NATIVE_FUNCTION(StringPrototype::symbol_iterator) auto& realm = *vm.current_realm(); auto this_object = TRY(require_object_coercible(vm, vm.this_value())); - auto string = TRY(this_object.to_deprecated_string(vm)); + auto string = TRY(this_object.to_string(vm)); return StringIterator::create(realm, string); } |