mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:57:36 +00:00
LibWeb: Implement TextEncoder.prototype.encoding
This commit is contained in:
parent
f37d00c07b
commit
f8387dea26
4 changed files with 23 additions and 1 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/FlyString.h>
|
||||||
#include <LibJS/Runtime/TypedArray.h>
|
#include <LibJS/Runtime/TypedArray.h>
|
||||||
#include <LibWeb/Bindings/Wrapper.h>
|
#include <LibWeb/Bindings/Wrapper.h>
|
||||||
#include <LibWeb/Encoding/TextEncoder.h>
|
#include <LibWeb/Encoding/TextEncoder.h>
|
||||||
|
@ -33,4 +34,11 @@ JS::Uint8Array* TextEncoder::encode(String const& input) const
|
||||||
return typed_array;
|
return typed_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
|
||||||
|
FlyString const& TextEncoder::encoding()
|
||||||
|
{
|
||||||
|
static FlyString encoding = "utf-8"sv;
|
||||||
|
return encoding;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@ public:
|
||||||
|
|
||||||
JS::Uint8Array* encode(String const& input) const;
|
JS::Uint8Array* encode(String const& input) const;
|
||||||
|
|
||||||
|
static FlyString const& encoding();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// https://encoding.spec.whatwg.org/#dom-textencoder
|
// https://encoding.spec.whatwg.org/#dom-textencoder
|
||||||
TextEncoder() = default;
|
TextEncoder() = default;
|
||||||
|
|
|
@ -5,5 +5,5 @@ interface TextEncoder {
|
||||||
[NewObject] Uint8Array encode(optional USVString input = "");
|
[NewObject] Uint8Array encode(optional USVString input = "");
|
||||||
// TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination);
|
// TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination);
|
||||||
|
|
||||||
// readonly attribute DOMString encoding;
|
readonly attribute DOMString encoding;
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
describe("normal behavior", () => {
|
||||||
|
loadLocalPage("/res/html/misc/blank.html");
|
||||||
|
|
||||||
|
afterInitialPageLoad(page => {
|
||||||
|
test("Basic functionality", () => {
|
||||||
|
const textEncoder = new page.TextEncoder();
|
||||||
|
|
||||||
|
expect(textEncoder.encoding).toBe("utf-8");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
waitForPageToLoad();
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue