TextEncoder.h 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2021, Linus Groh <linusg@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 <AK/RefCounted.h>
  10. #include <LibJS/Forward.h>
  11. #include <LibWeb/Bindings/Wrappable.h>
  12. #include <LibWeb/Forward.h>
  13. namespace Web::Encoding {
  14. // https://encoding.spec.whatwg.org/#textencoder
  15. class TextEncoder
  16. : public RefCounted<TextEncoder>
  17. , public Bindings::Wrappable {
  18. public:
  19. using WrapperType = Bindings::TextEncoderWrapper;
  20. static NonnullRefPtr<TextEncoder> create()
  21. {
  22. return adopt_ref(*new TextEncoder());
  23. }
  24. static NonnullRefPtr<TextEncoder> create_with_global_object(Bindings::WindowObject&)
  25. {
  26. return TextEncoder::create();
  27. }
  28. JS::Uint8Array* encode(String const& input) const;
  29. static FlyString const& encoding();
  30. protected:
  31. // https://encoding.spec.whatwg.org/#dom-textencoder
  32. TextEncoder() = default;
  33. };
  34. }