/work/obj-fuzz/dist/include/mozilla/dom/TextDecoder.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_textdecoder_h_ |
8 | | #define mozilla_dom_textdecoder_h_ |
9 | | |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/TextDecoderBinding.h" |
12 | | #include "mozilla/dom/TypedArray.h" |
13 | | #include "nsAutoPtr.h" |
14 | | #include "mozilla/Encoding.h" |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | class ErrorResult; |
19 | | |
20 | | namespace dom { |
21 | | |
22 | | class ArrayBufferViewOrArrayBuffer; |
23 | | |
24 | | class TextDecoder final |
25 | | : public NonRefcountedDOMObject |
26 | | { |
27 | | public: |
28 | | // The WebIDL constructor. |
29 | | static TextDecoder* |
30 | | Constructor(const GlobalObject& aGlobal, |
31 | | const nsAString& aEncoding, |
32 | | const TextDecoderOptions& aOptions, |
33 | | ErrorResult& aRv) |
34 | 0 | { |
35 | 0 | nsAutoPtr<TextDecoder> txtDecoder(new TextDecoder()); |
36 | 0 | txtDecoder->Init(aEncoding, aOptions, aRv); |
37 | 0 | if (aRv.Failed()) { |
38 | 0 | return nullptr; |
39 | 0 | } |
40 | 0 | return txtDecoder.forget(); |
41 | 0 | } |
42 | | |
43 | | TextDecoder() |
44 | | : mFatal(false) |
45 | | , mIgnoreBOM(false) |
46 | 0 | { |
47 | 0 | MOZ_COUNT_CTOR(TextDecoder); |
48 | 0 | } |
49 | | |
50 | | ~TextDecoder() |
51 | 0 | { |
52 | 0 | MOZ_COUNT_DTOR(TextDecoder); |
53 | 0 | } |
54 | | |
55 | | bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
56 | 0 | { |
57 | 0 | return TextDecoder_Binding::Wrap(aCx, this, aGivenProto, aReflector); |
58 | 0 | } |
59 | | |
60 | | /** |
61 | | * Validates provided label and throws an exception if invalid label. |
62 | | * |
63 | | * @param aLabel The encoding label (case insensitive) provided. |
64 | | * @param aOptions The TextDecoderOptions to use. |
65 | | * @return aRv EncodingError exception else null. |
66 | | */ |
67 | | void Init(const nsAString& aLabel, const TextDecoderOptions& aOptions, |
68 | | ErrorResult& aRv); |
69 | | |
70 | | /** |
71 | | * Performs initialization with a Gecko-canonical encoding name (as opposed |
72 | | * to a label.) |
73 | | * |
74 | | * @param aEncoding An Encoding object |
75 | | * @param aOptions The TextDecoderOptions to use. |
76 | | */ |
77 | | void InitWithEncoding(NotNull<const Encoding*> aEncoding, |
78 | | const TextDecoderOptions& aOptions); |
79 | | |
80 | | /** |
81 | | * Return the encoding name. |
82 | | * |
83 | | * @param aEncoding, current encoding. |
84 | | */ |
85 | | void GetEncoding(nsAString& aEncoding); |
86 | | |
87 | | /** |
88 | | * Decodes incoming byte stream of characters in charset indicated by |
89 | | * encoding. |
90 | | * |
91 | | * The encoding algorithm state is reset if aOptions.mStream is not set. |
92 | | * |
93 | | * If the fatal flag is set then a decoding error will throw EncodingError. |
94 | | * Else the decoder will return a decoded string with replacement |
95 | | * character(s) for unidentified character(s). |
96 | | * |
97 | | * @param aView, incoming byte stream of characters to be decoded to |
98 | | * to UTF-16 code points. |
99 | | * @param aOptions, indicates if streaming or not. |
100 | | * @param aOutDecodedString, decoded string of UTF-16 code points. |
101 | | * @param aRv, error result. |
102 | | */ |
103 | | void Decode(mozilla::Span<const uint8_t> aInput, |
104 | | const bool aStream, |
105 | | nsAString& aOutDecodedString, |
106 | | ErrorResult& aRv); |
107 | | |
108 | | void Decode(const Optional<ArrayBufferViewOrArrayBuffer>& aBuffer, |
109 | | const TextDecodeOptions& aOptions, |
110 | | nsAString& aOutDecodedString, |
111 | | ErrorResult& aRv); |
112 | | |
113 | 0 | bool Fatal() const { |
114 | 0 | return mFatal; |
115 | 0 | } |
116 | | |
117 | 0 | bool IgnoreBOM() const { |
118 | 0 | return mIgnoreBOM; |
119 | 0 | } |
120 | | |
121 | | private: |
122 | | nsCString mEncoding; |
123 | | mozilla::UniquePtr<mozilla::Decoder> mDecoder; |
124 | | bool mFatal; |
125 | | bool mIgnoreBOM; |
126 | | }; |
127 | | |
128 | | } // namespace dom |
129 | | } // namespace mozilla |
130 | | |
131 | | #endif // mozilla_dom_textdecoder_h_ |