mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:17:41 +00:00
LibWeb: Port TextEncoder interface from DeprecatedString to String
This commit is contained in:
parent
278061e8b9
commit
76449c21b2
3 changed files with 7 additions and 7 deletions
|
@ -31,7 +31,7 @@ void TextEncoder::initialize(JS::Realm& realm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encode
|
// 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.
|
// 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.
|
// 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.
|
// 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_length = byte_buffer.size();
|
||||||
auto array_buffer = JS::ArrayBuffer::create(realm(), move(byte_buffer));
|
auto array_buffer = JS::ArrayBuffer::create(realm(), move(byte_buffer));
|
||||||
return JS::Uint8Array::create(realm(), array_length, *array_buffer);
|
return JS::Uint8Array::create(realm(), array_length, *array_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
|
// 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;
|
return encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@ public:
|
||||||
|
|
||||||
virtual ~TextEncoder() override;
|
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:
|
protected:
|
||||||
// https://encoding.spec.whatwg.org/#dom-textencoder
|
// https://encoding.spec.whatwg.org/#dom-textencoder
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[Exposed=(Window,Worker), UseDeprecatedAKString]
|
[Exposed=(Window,Worker)]
|
||||||
interface TextEncoder {
|
interface TextEncoder {
|
||||||
constructor();
|
constructor();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue