mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LibJS: Port StringIterator to String
This commit is contained in:
parent
0d47c4e7a0
commit
b6b5ddeb3b
4 changed files with 10 additions and 9 deletions
|
@ -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())
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue