LibWeb: Port TextEncoder interface from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-09-06 16:10:23 +12:00 committed by Tim Flynn
parent 278061e8b9
commit 76449c21b2
Notes: sideshowbarker 2024-07-18 00:41:35 +09:00
3 changed files with 7 additions and 7 deletions

View File

@ -31,7 +31,7 @@ void TextEncoder::initialize(JS::Realm& realm)
}
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
JS::Uint8Array* TextEncoder::encode(DeprecatedString const& input) const
JS::Uint8Array* TextEncoder::encode(String const& input) const
{
// NOTE: The AK::DeprecatedString returned from PrimitiveString::string() is always UTF-8, regardless of the internal string type, so most of these steps are no-ops.
@ -43,16 +43,16 @@ JS::Uint8Array* TextEncoder::encode(DeprecatedString const& input) const
// 3. Assert: result is not an error.
// 4. If result is finished, then convert output into a byte sequence and return a Uint8Array object wrapping an ArrayBuffer containing output.
auto byte_buffer = input.to_byte_buffer();
auto byte_buffer = MUST(ByteBuffer::copy(input.bytes()));
auto array_length = byte_buffer.size();
auto array_buffer = JS::ArrayBuffer::create(realm(), move(byte_buffer));
return JS::Uint8Array::create(realm(), array_length, *array_buffer);
}
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
DeprecatedFlyString const& TextEncoder::encoding()
FlyString const& TextEncoder::encoding()
{
static DeprecatedFlyString encoding = "utf-8"sv;
static const FlyString encoding = "utf-8"_fly_string;
return encoding;
}

View File

@ -24,9 +24,9 @@ public:
virtual ~TextEncoder() override;
JS::Uint8Array* encode(DeprecatedString const& input) const;
JS::Uint8Array* encode(String const& input) const;
static DeprecatedFlyString const& encoding();
static FlyString const& encoding();
protected:
// https://encoding.spec.whatwg.org/#dom-textencoder

View File

@ -1,4 +1,4 @@
[Exposed=(Window,Worker), UseDeprecatedAKString]
[Exposed=(Window,Worker)]
interface TextEncoder {
constructor();