|
@@ -8,35 +8,22 @@
|
|
|
|
|
|
#include <AK/Forward.h>
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
-#include <AK/RefCounted.h>
|
|
|
#include <LibJS/Forward.h>
|
|
|
#include <LibTextCodec/Decoder.h>
|
|
|
-#include <LibWeb/Bindings/Wrappable.h>
|
|
|
+#include <LibWeb/Bindings/PlatformObject.h>
|
|
|
#include <LibWeb/DOM/ExceptionOr.h>
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
namespace Web::Encoding {
|
|
|
|
|
|
// https://encoding.spec.whatwg.org/#textdecoder
|
|
|
-class TextDecoder
|
|
|
- : public RefCounted<TextDecoder>
|
|
|
- , public Bindings::Wrappable {
|
|
|
-public:
|
|
|
- using WrapperType = Bindings::TextDecoderWrapper;
|
|
|
-
|
|
|
- static DOM::ExceptionOr<NonnullRefPtr<TextDecoder>> create(FlyString encoding)
|
|
|
- {
|
|
|
- auto decoder = TextCodec::decoder_for(encoding);
|
|
|
- if (!decoder)
|
|
|
- return DOM::SimpleException { DOM::SimpleExceptionType::TypeError, String::formatted("Invalid encoding {}", encoding) };
|
|
|
+class TextDecoder : public Bindings::PlatformObject {
|
|
|
+ WEB_PLATFORM_OBJECT(TextDecoder, Bindings::PlatformObject);
|
|
|
|
|
|
- return adopt_ref(*new TextDecoder(*decoder, move(encoding), false, false));
|
|
|
- }
|
|
|
+public:
|
|
|
+ static DOM::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> create_with_global_object(HTML::Window&, FlyString encoding);
|
|
|
|
|
|
- static DOM::ExceptionOr<NonnullRefPtr<TextDecoder>> create_with_global_object(HTML::Window&, FlyString label)
|
|
|
- {
|
|
|
- return TextDecoder::create(move(label));
|
|
|
- }
|
|
|
+ virtual ~TextDecoder() override;
|
|
|
|
|
|
DOM::ExceptionOr<String> decode(JS::Handle<JS::Object> const&) const;
|
|
|
|
|
@@ -44,15 +31,9 @@ public:
|
|
|
bool fatal() const { return m_fatal; }
|
|
|
bool ignore_bom() const { return m_ignore_bom; };
|
|
|
|
|
|
-protected:
|
|
|
+private:
|
|
|
// https://encoding.spec.whatwg.org/#dom-textdecoder
|
|
|
- TextDecoder(TextCodec::Decoder& decoder, FlyString encoding, bool fatal, bool ignore_bom)
|
|
|
- : m_decoder(decoder)
|
|
|
- , m_encoding(move(encoding))
|
|
|
- , m_fatal(fatal)
|
|
|
- , m_ignore_bom(ignore_bom)
|
|
|
- {
|
|
|
- }
|
|
|
+ TextDecoder(HTML::Window&, TextCodec::Decoder&, FlyString encoding, bool fatal, bool ignore_bom);
|
|
|
|
|
|
TextCodec::Decoder& m_decoder;
|
|
|
FlyString m_encoding;
|
|
@@ -61,3 +42,5 @@ protected:
|
|
|
};
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+WRAPPER_HACK(TextDecoder, Web::Encoding)
|