Browse Source

LibJS: Port StringIterator to String

Timothy Flynn 2 years ago
parent
commit
b6b5ddeb3b

+ 2 - 2
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())

+ 4 - 3
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 };
 };

+ 3 - 3
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);
 }
 
 }

+ 1 - 1
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);
 }