mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb: Add constructor options to TextDecoder
This commit is contained in:
parent
9ed8c0b183
commit
f1ead552ce
Notes:
sideshowbarker
2024-07-17 04:21:32 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/f1ead552ce Pull-request: https://github.com/SerenityOS/serenity/pull/21351
5 changed files with 47 additions and 15 deletions
|
@ -3227,6 +3227,7 @@ void generate_namespace_implementation(IDL::Interface const& interface, StringBu
|
|||
using namespace Web::CSS;
|
||||
using namespace Web::DOM;
|
||||
using namespace Web::DOMParsing;
|
||||
using namespace Web::Encoding;
|
||||
using namespace Web::Fetch;
|
||||
using namespace Web::FileAPI;
|
||||
using namespace Web::Geometry;
|
||||
|
@ -3444,6 +3445,7 @@ void generate_constructor_implementation(IDL::Interface const& interface, String
|
|||
using namespace Web::CSS;
|
||||
using namespace Web::DOM;
|
||||
using namespace Web::DOMParsing;
|
||||
using namespace Web::Encoding;
|
||||
using namespace Web::Fetch;
|
||||
using namespace Web::FileAPI;
|
||||
using namespace Web::Geometry;
|
||||
|
@ -3829,6 +3831,7 @@ using namespace Web::Crypto;
|
|||
using namespace Web::CSS;
|
||||
using namespace Web::DOM;
|
||||
using namespace Web::DOMParsing;
|
||||
using namespace Web::Encoding;
|
||||
using namespace Web::Fetch;
|
||||
using namespace Web::FileAPI;
|
||||
using namespace Web::Geometry;
|
||||
|
@ -3976,6 +3979,7 @@ void generate_iterator_prototype_implementation(IDL::Interface const& interface,
|
|||
using namespace Web::CSS;
|
||||
using namespace Web::DOM;
|
||||
using namespace Web::DOMParsing;
|
||||
using namespace Web::Encoding;
|
||||
using namespace Web::Fetch;
|
||||
using namespace Web::FileAPI;
|
||||
using namespace Web::Geometry;
|
||||
|
@ -4108,6 +4112,7 @@ using namespace Web::Crypto;
|
|||
using namespace Web::CSS;
|
||||
using namespace Web::DOM;
|
||||
using namespace Web::DOMParsing;
|
||||
using namespace Web::Encoding;
|
||||
using namespace Web::Fetch;
|
||||
using namespace Web::FileAPI;
|
||||
using namespace Web::Geometry;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace Web::Encoding {
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> TextDecoder::construct_impl(JS::Realm& realm, FlyString encoding)
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> TextDecoder::construct_impl(JS::Realm& realm, FlyString encoding, Optional<TextDecoderOptions> const& options)
|
||||
{
|
||||
auto& vm = realm.vm();
|
||||
|
||||
|
@ -20,7 +20,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> TextDecoder::construct_impl(J
|
|||
if (!decoder.has_value())
|
||||
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, TRY_OR_THROW_OOM(vm, String::formatted("Invalid encoding {}", encoding)) };
|
||||
|
||||
return realm.heap().allocate<TextDecoder>(realm, realm, *decoder, move(encoding), false, false);
|
||||
return realm.heap().allocate<TextDecoder>(realm, realm, *decoder, move(encoding), options.value_or({}).fatal, options.value_or({}).ignore_bom);
|
||||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textdecoder
|
||||
|
@ -42,7 +42,7 @@ void TextDecoder::initialize(JS::Realm& realm)
|
|||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
|
||||
WebIDL::ExceptionOr<String> TextDecoder::decode(Optional<JS::Handle<JS::Object>> const& input) const
|
||||
WebIDL::ExceptionOr<String> TextDecoder::decode(Optional<JS::Handle<JS::Object>> const& input, Optional<TextDecodeOptions> const&) const
|
||||
{
|
||||
if (!input.has_value())
|
||||
return TRY_OR_THROW_OOM(vm(), m_decoder.to_utf8({}));
|
||||
|
|
|
@ -16,23 +16,33 @@
|
|||
|
||||
namespace Web::Encoding {
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textdecoderoptions
|
||||
struct TextDecoderOptions {
|
||||
bool fatal = false;
|
||||
bool ignore_bom = false;
|
||||
};
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textdecodeoptions
|
||||
struct TextDecodeOptions {
|
||||
bool stream = false;
|
||||
};
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textdecoder
|
||||
class TextDecoder : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(TextDecoder, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> construct_impl(JS::Realm&, FlyString encoding);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> construct_impl(JS::Realm&, FlyString encoding, Optional<TextDecoderOptions> const& options = {});
|
||||
|
||||
virtual ~TextDecoder() override;
|
||||
|
||||
WebIDL::ExceptionOr<String> decode(Optional<JS::Handle<JS::Object>> const&) const;
|
||||
WebIDL::ExceptionOr<String> decode(Optional<JS::Handle<JS::Object>> const&, Optional<TextDecodeOptions> const& options = {}) const;
|
||||
|
||||
FlyString const& encoding() const { return m_encoding; }
|
||||
bool fatal() const { return m_fatal; }
|
||||
bool ignore_bom() const { return m_ignore_bom; }
|
||||
|
||||
private:
|
||||
// https://encoding.spec.whatwg.org/#dom-textdecoder
|
||||
TextDecoder(JS::Realm&, TextCodec::Decoder&, FlyString encoding, bool fatal, bool ignore_bom);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
|
|
@ -1,13 +1,27 @@
|
|||
[Exposed=(Window,Worker)]
|
||||
interface TextDecoder {
|
||||
// FIXME: 'optional TextDecoderOptions options = {}'
|
||||
constructor(optional DOMString label = "utf-8");
|
||||
|
||||
// FIXME: [AllowShared] on the first parameter.
|
||||
// FIXME: 'optional TextDecodeOptions options = {}'
|
||||
USVString decode(optional BufferSource input);
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textdecodercommon
|
||||
interface mixin TextDecoderCommon {
|
||||
readonly attribute DOMString encoding;
|
||||
readonly attribute boolean fatal;
|
||||
readonly attribute boolean ignoreBOM;
|
||||
};
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textdecoderoptions
|
||||
dictionary TextDecoderOptions {
|
||||
boolean fatal = false;
|
||||
boolean ignoreBOM = false;
|
||||
};
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textdecodeoptions
|
||||
dictionary TextDecodeOptions {
|
||||
boolean stream = false;
|
||||
};
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textdecoder
|
||||
[Exposed=*]
|
||||
interface TextDecoder {
|
||||
constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options = {});
|
||||
|
||||
// FIXME: BufferSource is really a AllowSharedBufferSource
|
||||
USVString decode(optional BufferSource input, optional TextDecodeOptions options = {});
|
||||
};
|
||||
TextDecoder includes TextDecoderCommon;
|
||||
|
|
|
@ -254,6 +254,9 @@ class XMLSerializer;
|
|||
}
|
||||
|
||||
namespace Web::Encoding {
|
||||
struct TextDecodeOptions;
|
||||
class TextDecoder;
|
||||
struct TextDecoderOptions;
|
||||
class TextEncoder;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue