Serenity Operating System
1/*
2 * Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/Forward.h>
10#include <AK/NonnullRefPtr.h>
11#include <LibJS/Forward.h>
12#include <LibTextCodec/Decoder.h>
13#include <LibWeb/Bindings/PlatformObject.h>
14#include <LibWeb/Forward.h>
15#include <LibWeb/WebIDL/ExceptionOr.h>
16
17namespace Web::Encoding {
18
19// https://encoding.spec.whatwg.org/#textdecoder
20class TextDecoder : public Bindings::PlatformObject {
21 WEB_PLATFORM_OBJECT(TextDecoder, Bindings::PlatformObject);
22
23public:
24 static WebIDL::ExceptionOr<JS::NonnullGCPtr<TextDecoder>> construct_impl(JS::Realm&, DeprecatedFlyString encoding);
25
26 virtual ~TextDecoder() override;
27
28 WebIDL::ExceptionOr<DeprecatedString> decode(JS::Handle<JS::Object> const&) const;
29
30 DeprecatedFlyString const& encoding() const { return m_encoding; }
31 bool fatal() const { return m_fatal; }
32 bool ignore_bom() const { return m_ignore_bom; };
33
34private:
35 // https://encoding.spec.whatwg.org/#dom-textdecoder
36 TextDecoder(JS::Realm&, TextCodec::Decoder&, DeprecatedFlyString encoding, bool fatal, bool ignore_bom);
37
38 virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
39
40 TextCodec::Decoder& m_decoder;
41 DeprecatedFlyString m_encoding;
42 bool m_fatal { false };
43 bool m_ignore_bom { false };
44};
45
46}