diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index 8cbe5a516c..8f68687ec3 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -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; diff --git a/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp b/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp index 64ef50e016..1df868e2f5 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp +++ b/Userland/Libraries/LibWeb/Encoding/TextDecoder.cpp @@ -12,7 +12,7 @@ namespace Web::Encoding { -WebIDL::ExceptionOr> TextDecoder::construct_impl(JS::Realm& realm, FlyString encoding) +WebIDL::ExceptionOr> TextDecoder::construct_impl(JS::Realm& realm, FlyString encoding, Optional const& options) { auto& vm = realm.vm(); @@ -20,7 +20,7 @@ WebIDL::ExceptionOr> 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(realm, realm, *decoder, move(encoding), false, false); + return realm.heap().allocate(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 TextDecoder::decode(Optional> const& input) const +WebIDL::ExceptionOr TextDecoder::decode(Optional> const& input, Optional const&) const { if (!input.has_value()) return TRY_OR_THROW_OOM(vm(), m_decoder.to_utf8({})); diff --git a/Userland/Libraries/LibWeb/Encoding/TextDecoder.h b/Userland/Libraries/LibWeb/Encoding/TextDecoder.h index 5d12a3c1c0..8bd4e8265a 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextDecoder.h +++ b/Userland/Libraries/LibWeb/Encoding/TextDecoder.h @@ -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> construct_impl(JS::Realm&, FlyString encoding); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString encoding, Optional const& options = {}); virtual ~TextDecoder() override; - WebIDL::ExceptionOr decode(Optional> const&) const; + WebIDL::ExceptionOr decode(Optional> const&, Optional 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; diff --git a/Userland/Libraries/LibWeb/Encoding/TextDecoder.idl b/Userland/Libraries/LibWeb/Encoding/TextDecoder.idl index acded928c7..8b95f2a25c 100644 --- a/Userland/Libraries/LibWeb/Encoding/TextDecoder.idl +++ b/Userland/Libraries/LibWeb/Encoding/TextDecoder.idl @@ -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; diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index fd217c7dc9..84604044d0 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -254,6 +254,9 @@ class XMLSerializer; } namespace Web::Encoding { +struct TextDecodeOptions; +class TextDecoder; +struct TextDecoderOptions; class TextEncoder; }