TextDecoder.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <LibJS/Forward.h>
  10. #include <LibTextCodec/Decoder.h>
  11. #include <LibWeb/Bindings/PlatformObject.h>
  12. #include <LibWeb/DOM/ExceptionOr.h>
  13. #include <LibWeb/Forward.h>
  14. namespace Web::Encoding {
  15. // https://encoding.spec.whatwg.org/#textdecoder
  16. class TextDecoder : public Bindings::PlatformObject {
  17. WEB_PLATFORM_OBJECT(TextDecoder, Bindings::PlatformObject);
  18. public:
  19. static DOM::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> create_with_global_object(HTML::Window&, FlyString encoding);
  20. virtual ~TextDecoder() override;
  21. DOM::ExceptionOr<String> decode(JS::Handle<JS::Object> const&) const;
  22. FlyString const& encoding() const { return m_encoding; }
  23. bool fatal() const { return m_fatal; }
  24. bool ignore_bom() const { return m_ignore_bom; };
  25. private:
  26. // https://encoding.spec.whatwg.org/#dom-textdecoder
  27. TextDecoder(HTML::Window&, TextCodec::Decoder&, FlyString encoding, bool fatal, bool ignore_bom);
  28. TextCodec::Decoder& m_decoder;
  29. FlyString m_encoding;
  30. bool m_fatal { false };
  31. bool m_ignore_bom { false };
  32. };
  33. }
  34. WRAPPER_HACK(TextDecoder, Web::Encoding)