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/Forward.h>
  13. #include <LibWeb/WebIDL/ExceptionOr.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 WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> construct_impl(JS::Realm&, DeprecatedFlyString encoding);
  20. virtual ~TextDecoder() override;
  21. WebIDL::ExceptionOr<DeprecatedString> decode(JS::Handle<JS::Object> const&) const;
  22. DeprecatedFlyString 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(JS::Realm&, TextCodec::Decoder&, DeprecatedFlyString encoding, bool fatal, bool ignore_bom);
  28. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  29. TextCodec::Decoder& m_decoder;
  30. DeprecatedFlyString m_encoding;
  31. bool m_fatal { false };
  32. bool m_ignore_bom { false };
  33. };
  34. }