mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
LibWeb: Port TextEncoder interface from DeprecatedString to String
This commit is contained in:
parent
278061e8b9
commit
76449c21b2
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[Exposed=(Window,Worker), UseDeprecatedAKString]
|
||||
[Exposed=(Window,Worker)]
|
||||
interface TextEncoder {
|
||||
constructor();
|
||||
|
||||
|
|
Loading…
Reference in a new issue