Skip to content

Truly independent web browser

LibWeb: Implement TextDecoder in Rust

Aliaksandr Kalenik8577e38ab00e
diff --git a/Cargo.lock b/Cargo.lock
index b711c7794d6..715726e6bcf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -974,6 +974,7 @@ name = "libweb_bindings_rust"
version = "0.1.0"
dependencies = [
"ak",
+ "encoding_rs",
"ladybird_allocator",
"libjs_rust",
"libweb_rust",
diff --git a/Libraries/LibWeb/Bindings/Rust/Cargo.toml b/Libraries/LibWeb/Bindings/Rust/Cargo.toml
index 90d9d8ea92a..da3a1d6e5df 100644
--- a/Libraries/LibWeb/Bindings/Rust/Cargo.toml
+++ b/Libraries/LibWeb/Bindings/Rust/Cargo.toml
@@ -19,6 +19,7 @@ thread-sanitizer = ["libjs_rust/thread-sanitizer", "libweb_rust/thread-sanitizer
# python3 Meta/CMake/flatpak/generate-cargo-sources.py
[dependencies]
ak = { path = "../../../../AK/Rust" }
+encoding_rs = "0.8.40"
ladybird_allocator = { path = "../../../RustAllocator", optional = true }
libjs_rust = { path = "../../../LibJS/Rust", default-features = false }
libweb_rust = { path = "../../Rust" }
diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs
index f7843afad00..e5e8b633ad0 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs
@@ -66,6 +66,11 @@ impl UsvString {
pub(crate) fn into_utf16_string(self) -> Utf16String {
self.0
}
+
+ /// The string of the code units, with U+FFFD in place of every surrogate that is not part of a pair.
+ pub(crate) fn from_utf16_replacing_lone_surrogates(code_units: &[u16]) -> Self {
+ Self(Utf16String::well_formed_from_utf16(code_units))
+ }
}
/// A JS value converted to a DOMString, https://webidl.spec.whatwg.org/#es-DOMString
diff --git a/Libraries/LibWeb/Bindings/Rust/src/encoding/decoding.rs b/Libraries/LibWeb/Bindings/Rust/src/encoding/decoding.rs
new file mode 100644
index 00000000000..fbb1293b295
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/encoding/decoding.rs
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! Decoding with the decoders of the Encoding Standard, https://encoding.spec.whatwg.org/#encodings, which the
+//! encoding_rs crate implements.
+
+use ak::Utf16StringUnits;
+use encoding_rs::{CoderResult, Decoder, DecoderResult, Encoding};
+
+/// Getting an encoding from a label, https://encoding.spec.whatwg.org/#concept-encoding-get
+pub(crate) fn encoding_for_label(label: Utf16StringUnits<'_>) -> Option<&'static Encoding> {
+ match label {
+ Utf16StringUnits::Ascii(label) => Encoding::for_label(label),
+ Utf16StringUnits::Utf16(label) => {
+ // NB: Every label is ASCII, so a label with any other code unit is not one.
+ let label: Option<Vec<u8>> = label.iter().map(|&unit| u8::try_from(unit).ok()).collect();
+ Encoding::for_label(&label.filter(|label| label.is_ascii())?)
+ }
+ }
+}
+
+#[derive(Debug, PartialEq, Eq)]
+pub(crate) struct DecodingFailed;
+
+/// The decoder of an encoding together with the error mode and the BOM handling that it decodes with, which keeps
+/// the bytes of a character that a chunk of a stream ended in until the next chunk.
+pub(crate) struct StreamingDecoder {
+ encoding: &'static Encoding,
+ fatal: bool,
+ ignore_bom: bool,
+ decoder: Decoder,
+}
+
+impl StreamingDecoder {
+ pub(crate) fn new(encoding: &'static Encoding, fatal: bool, ignore_bom: bool) -> Self {
+ Self {
+ encoding,
+ fatal,
+ ignore_bom,
+ decoder: Self::new_decoder(encoding, ignore_bom),
+ }
+ }
+
+ fn new_decoder(encoding: &'static Encoding, ignore_bom: bool) -> Decoder {
+ if ignore_bom {
+ encoding.new_decoder_without_bom_handling()
+ } else {
+ encoding.new_decoder_with_bom_removal()
+ }
+ }
+
+ pub(crate) fn encoding(&self) -> &'static Encoding {
+ self.encoding
+ }
+
+ pub(crate) fn fatal(&self) -> bool {
+ self.fatal
+ }
+
+ pub(crate) fn ignore_bom(&self) -> bool {
+ self.ignore_bom
+ }
+
+ /// Decodes the next bytes of the input to UTF-16. Unless more of the input follows, the bytes are its end: the
+ /// decoder then flushes what it kept, and starts over for the next input, whether or not decoding succeeded.
+ pub(crate) fn decode(&mut self, input: &[u8], more_input_follows: bool) -> Result<Vec<u16>, DecodingFailed> {
+ let decoded = self.decode_with_current_decoder(input, !more_input_follows);
+ if !more_input_follows {
+ // NB: encoding_rs finishes a decoder for good once it has seen the end of its input.
+ self.decoder = Self::new_decoder(self.encoding, self.ignore_bom);
+ }
+ decoded
+ }
+
+ fn decode_with_current_decoder(&mut self, input: &[u8], last: bool) -> Result<Vec<u16>, DecodingFailed> {
+ let output_capacity = self
+ .decoder
+ .max_utf16_buffer_length(input.len())
+ .ok_or(DecodingFailed)?;
+ let mut output = vec![0; output_capacity];
+
+ let (input_was_consumed, written) = if self.fatal {
+ let (result, _, written) = self
+ .decoder
+ .decode_to_utf16_without_replacement(input, &mut output, last);
+ (matches!(result, DecoderResult::InputEmpty), written)
+ } else {
+ let (result, _, written, _) = self.decoder.decode_to_utf16(input, &mut output, last);
+ (matches!(result, CoderResult::InputEmpty), written)
+ };
+ if !input_was_consumed {
+ return Err(DecodingFailed);
+ }
+ output.truncate(written);
+ Ok(output)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn utf8_decoder(fatal: bool, ignore_bom: bool) -> StreamingDecoder {
+ StreamingDecoder::new(encoding_rs::UTF_8, fatal, ignore_bom)
+ }
+
+ fn utf16(string: &str) -> Vec<u16> {
+ string.encode_utf16().collect()
+ }
+
+ #[test]
+ fn labels() {
+ let name = |label: Utf16StringUnits<'_>| encoding_for_label(label).map(Encoding::name);
+ assert_eq!(name(Utf16StringUnits::Ascii(b" Latin1\n")), Some("windows-1252"));
+ assert_eq!(name(Utf16StringUnits::Ascii(b"nonsense")), None);
+ assert_eq!(name(Utf16StringUnits::Utf16(&utf16("utf-8"))), Some("UTF-8"));
+ assert_eq!(name(Utf16StringUnits::Utf16(&utf16("\u{FC}tf-8"))), None);
+ assert_eq!(name(Utf16StringUnits::Utf16(&utf16("\u{175}tf-8"))), None);
+ }
+
+ #[test]
+ fn a_character_split_over_chunks() {
+ let mut decoder = utf8_decoder(false, false);
+ assert_eq!(decoder.decode(&[0x61, 0xE2, 0x82], true), Ok(utf16("a")));
+ assert_eq!(decoder.decode(&[0xAC], false), Ok(utf16("\u{20AC}")));
+ }
+
+ #[test]
+ fn the_end_of_the_input_flushes_and_starts_over() {
+ let mut decoder = utf8_decoder(false, false);
+ assert_eq!(decoder.decode(&[0x61, 0xE2, 0x82], false), Ok(utf16("a\u{FFFD}")));
+ assert_eq!(decoder.decode(&[0xAC], false), Ok(utf16("\u{FFFD}")));
+ assert_eq!(decoder.decode(&[], false), Ok(Vec::new()));
+ }
+
+ #[test]
+ fn a_byte_order_mark_is_removed_once_for_every_input() {
+ let mut decoder = utf8_decoder(false, false);
+ assert_eq!(decoder.decode(&[0xEF, 0xBB, 0xBF, 0x61], true), Ok(utf16("a")));
+ assert_eq!(decoder.decode(&[0xEF, 0xBB, 0xBF, 0x62], false), Ok(utf16("\u{FEFF}b")));
+ assert_eq!(decoder.decode(&[0xEF, 0xBB, 0xBF, 0x63], false), Ok(utf16("c")));
+
+ let mut keeping = utf8_decoder(false, true);
+ assert_eq!(keeping.decode(&[0xEF, 0xBB, 0xBF, 0x61], false), Ok(utf16("\u{FEFF}a")));
+ }
+
+ #[test]
+ fn fatal_decoding_fails_on_invalid_bytes() {
+ let mut decoder = utf8_decoder(true, false);
+ assert_eq!(decoder.decode(&[0x61, 0xFF], false), Err(DecodingFailed));
+ assert_eq!(decoder.decode(&[0x62], false), Ok(utf16("b")));
+ assert_eq!(decoder.decode(&[0xE2, 0x82], false), Err(DecodingFailed));
+ }
+
+ #[test]
+ fn a_failure_in_the_middle_of_the_input_keeps_the_decoder() {
+ let mut decoder = utf8_decoder(true, false);
+ assert_eq!(decoder.decode(&[0x61, 0xFF, 0x62], true), Err(DecodingFailed));
+ assert_eq!(decoder.decode(&[0x63], true), Ok(utf16("c")));
+ assert_eq!(decoder.decode(&[0x64], false), Ok(utf16("d")));
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/encoding/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/encoding/mod.rs
index 2dde28b8241..087bc997916 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/encoding/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/encoding/mod.rs
@@ -6,6 +6,9 @@
//! The Encoding Standard, https://encoding.spec.whatwg.org/
+pub(crate) mod decoding;
+#[cfg(not(test))]
+pub(crate) mod text_decoder;
#[cfg(not(test))]
pub(crate) mod text_encoder;
pub(crate) mod utf8;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/encoding/text_decoder.rs b/Libraries/LibWeb/Bindings/Rust/src/encoding/text_decoder.rs
new file mode 100644
index 00000000000..468399c2d20
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/encoding/text_decoder.rs
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! TextDecoder, https://encoding.spec.whatwg.org/#interface-textdecoder
+
+use core::cell::RefCell;
+
+use ak::Utf16String;
+use libjs_rust::api::Trace;
+
+use crate::bindings::conversions::{BufferSource, UsvString};
+use crate::bindings::{CallContext, Exception, WebIdlResult};
+use crate::encoding::decoding::{DecodingFailed, StreamingDecoder, encoding_for_label};
+
+/// The dictionary TextDecoderOptions of Encoding/TextDecoder.idl, whose members the bindings convert.
+pub(crate) struct TextDecoderOptions {
+ pub(crate) fatal: bool,
+ pub(crate) ignore_bom: bool,
+}
+
+/// The dictionary TextDecodeOptions of Encoding/TextDecoder.idl, whose members the bindings convert.
+pub(crate) struct TextDecodeOptions {
+ pub(crate) stream: bool,
+}
+
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct TextDecoder {
+ /// The encoding, the error mode and the ignore BOM flag of the decoder, with the decoder of the encoding, which
+ /// holds the I/O queue of a decode() that asked for more input to follow.
+ #[gc(untraced)]
+ decoder: RefCell<StreamingDecoder>,
+}
+
+#[expect(
+ clippy::unnecessary_wraps,
+ reason = "the bindings call every method of an implementation for its WebIDL result, whether or not it can fail"
+)]
+impl TextDecoder {
+ // https://encoding.spec.whatwg.org/#dom-textdecoder
+ pub(crate) fn construct(
+ _: &mut CallContext,
+ label: Utf16String,
+ options: TextDecoderOptions,
+ ) -> WebIdlResult<Self> {
+ // 1. Let encoding be the result of getting an encoding from label.
+ // 2. If encoding is failure or replacement, then throw a RangeError.
+ let encoding = encoding_for_label(label.as_units())
+ .filter(|&encoding| encoding != encoding_rs::REPLACEMENT)
+ .ok_or_else(|| Exception::RangeError(Utf16String::from_ascii(b"Invalid encoding")))?;
+
+ // 3. Set this's encoding to encoding.
+ // 4. If options["fatal"] is true, then set this's error mode to "fatal".
+ // 5. Set this's ignore BOM to options["ignoreBOM"].
+ Ok(Self {
+ decoder: RefCell::new(StreamingDecoder::new(encoding, options.fatal, options.ignore_bom)),
+ })
+ }
+
+ // https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
+ pub(crate) fn encoding(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {
+ // The encoding getter steps are to return this's encoding's name, ASCII lowercased.
+ let name = self.decoder.borrow().encoding().name().to_ascii_lowercase();
+ Ok(Utf16String::from_ascii(name.as_bytes()))
+ }
+
+ // https://encoding.spec.whatwg.org/#dom-textdecoder-fatal
+ pub(crate) fn fatal(&self, _: &mut CallContext) -> WebIdlResult<bool> {
+ // The fatal getter steps are to return true if this's error mode is "fatal", otherwise false.
+ Ok(self.decoder.borrow().fatal())
+ }
+
+ // https://encoding.spec.whatwg.org/#dom-textdecoder-ignorebom
+ pub(crate) fn ignore_bom(&self, _: &mut CallContext) -> WebIdlResult<bool> {
+ // The ignoreBOM getter steps are to return this's ignore BOM.
+ Ok(self.decoder.borrow().ignore_bom())
+ }
+
+ // https://encoding.spec.whatwg.org/#dom-textdecoder-decode
+ pub(crate) fn decode(
+ &self,
+ _: &mut CallContext,
+ input: Option<BufferSource>,
+ options: TextDecodeOptions,
+ ) -> WebIdlResult<UsvString> {
+ // 1. If this's do not flush is false, then set this's decoder to a new instance of this's encoding's decoder,
+ // this's I/O queue to the I/O queue of bytes « end-of-queue », and this's BOM seen to false.
+ // 2. Set this's do not flush to options["stream"].
+ // 3. If input is given, then push a copy of input to this's I/O queue.
+ // 4. Let output be the I/O queue of scalar values « end-of-queue ».
+ // 5. While true:
+ // 1. Let item be the result of reading from this's I/O queue.
+ // 2. If item is end-of-queue and this's do not flush is true, then return the result of running
+ // serialize I/O queue with this and output.
+ // 3. Otherwise:
+ // 1. Let result be the result of processing an item with item, this's decoder, this's I/O queue,
+ // output, and this's error mode.
+ // 2. If result is finished, then return the result of running serialize I/O queue with this and
+ // output.
+ // 3. Otherwise, if result is error, throw a TypeError.
+ // NB: The decoder of encoding_rs holds the I/O queue and whether the BOM was seen, and is replaced when a
+ // call that does not stream returns, where step 1 replaces it in the next call.
+ let mut decoder = self.decoder.borrow_mut();
+ let decoded = match &input {
+ // SAFETY: Decoding runs no script and allocates no cell, so nothing detaches, resizes or frees the
+ // buffer of the input while its bytes are read.
+ Some(input) => unsafe { input.with_bytes(|bytes| decoder.decode(bytes, options.stream)) },
+ None => decoder.decode(&[], options.stream),
+ };
+ let decoded =
+ decoded.map_err(|DecodingFailed| Exception::TypeError(Utf16String::from_ascii(b"Decoding failed")))?;
+ Ok(UsvString::from_utf16_replacing_lone_surrogates(&decoded))
+ }
+}
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 2b8c8d9b3d3..715c859b4c5 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -353,7 +353,6 @@ set(SOURCES
Editing/StyledMarkupSerializer.cpp
Editing/VisiblePosition.cpp
Editing/ReplaceSelection.cpp
- Encoding/TextDecoder.cpp
Encoding/TextDecoderCommon.cpp
Encoding/TextDecoderStream.cpp
Encoding/TextEncoderCommon.cpp
diff --git a/Libraries/LibWeb/Encoding/TextDecoder.cpp b/Libraries/LibWeb/Encoding/TextDecoder.cpp
deleted file mode 100644
index b825706df7a..00000000000
--- a/Libraries/LibWeb/Encoding/TextDecoder.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2022, Ali Mohammad Pur <[email protected]>
- * Copyright (c) 2024, Simon Wanner <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/ByteBuffer.h>
-#include <AK/FlyString.h>
-#include <LibGC/Heap.h>
-#include <LibJS/Runtime/VM.h>
-#include <LibWeb/Encoding/TextDecoder.h>
-
-namespace Web::Encoding {
-
-GC_DEFINE_ALLOCATOR(TextDecoder);
-
-WebIDL::ExceptionOr<GC::Ref<TextDecoder>> TextDecoder::create(Utf16String const& label, TextDecoderOptions const& options)
-{
- return create(Utf16FlyString::from_utf16(label.utf16_view()), options);
-}
-
-// https://encoding.spec.whatwg.org/#dom-textdecoder
-WebIDL::ExceptionOr<GC::Ref<TextDecoder>> TextDecoder::create(Utf16FlyString label, TextDecoderOptions const& options)
-{
- // 1. Let encoding be the result of getting an encoding from label.
- auto encoding = TextCodec::get_standardized_encoding(label.view());
-
- // 2. If encoding is failure or replacement, then throw a RangeError.
- if (!encoding.has_value() || encoding->equals_ignoring_ascii_case("replacement"sv))
- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Invalid encoding"_utf16 };
-
- // 3. Set this’s encoding to encoding.
- // https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
- // The encoding getter steps are to return this’s encoding’s name, ASCII lowercased.
- auto lowercase_encoding_name = encoding.value().to_ascii_lowercase_string();
-
- // 4. If options["fatal"] is true, then set this’s error mode to "fatal".
- auto error_mode = options.fatal ? TextCodec::ErrorMode::Fatal : TextCodec::ErrorMode::Replacement;
-
- // 5. Set this’s ignore BOM to options["ignoreBOM"].
- auto ignore_bom = options.ignore_bom;
-
- // NOTE: This should happen in decode(), but we don't support streaming yet and share decoders across calls.
- return GC::Heap::the().allocate<TextDecoder>(lowercase_encoding_name, error_mode, ignore_bom);
-}
-
-// https://encoding.spec.whatwg.org/#dom-textdecoder
-TextDecoder::TextDecoder(FlyString encoding, TextCodec::ErrorMode error_mode, bool ignore_bom)
- : TextDecoderCommonMixin(move(encoding), error_mode, ignore_bom)
-{
- set_decoder_to_new_instance_of_encoding_decoder();
-}
-
-TextDecoder::~TextDecoder() = default;
-
-WebIDL::ExceptionOr<Utf16String> TextDecoder::decode(Optional<WebIDL::BufferSourceVariant> const& input, Optional<TextDecodeOptions> const& options) const
-{
- Optional<ByteBuffer> data_buffer;
- if (input.has_value()) {
- auto data_buffer_or_error = WebIDL::get_buffer_source_copy(WebIDL::BufferSource { *input });
- if (data_buffer_or_error.is_error())
- return WebIDL::OperationError::create("Failed to copy bytes from ArrayBuffer"_utf16);
- data_buffer = data_buffer_or_error.release_value();
- }
-
- return decode(data_buffer.map([](auto const& buffer) { return buffer.bytes(); }), options.has_value() && options->stream);
-}
-
-// https://encoding.spec.whatwg.org/#dom-textdecoder-decode
-WebIDL::ExceptionOr<Utf16String> TextDecoder::decode(Optional<ReadonlyBytes> input, bool stream) const
-{
- auto& vm = JS::VM::the();
-
- auto decode_bytes = [&](ErrorOr<Utf16String> decoded) -> WebIDL::ExceptionOr<Utf16String> {
- if (decoded.is_error()) {
- // Decoder errors in fatal mode are reported as a TypeError. Only
- // allocation failures should become an internal out-of-memory
- // exception; do not assert that every codec error is ENOMEM.
- if (decoded.error().code() == ENOMEM)
- return vm.throw_completion<JS::InternalError>(vm.error_message(JS::VM::ErrorMessage::OutOfMemory));
- return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Decoding failed"_utf16 };
- }
- return decoded.release_value();
- };
-
- if (stream)
- return decode_bytes(m_decoder->to_utf16(input.has_value() ? input.value() : ReadonlyBytes {}));
-
- // A non-streaming decode signals end-of-queue to the decoder. This flushes any pending partial sequence.
- // encoding_rs permanently finishes a decoder after that operation, so replace it before returning; the
- // TextDecoder object must be reusable for a subsequent independent decode().
- auto decoded_or_error = m_decoder->to_utf16(input.has_value() ? input.value() : ReadonlyBytes {}, TextCodec::Flush::Yes);
- set_decoder_to_new_instance_of_encoding_decoder();
-
- return decode_bytes(move(decoded_or_error));
-}
-
-}
diff --git a/Libraries/LibWeb/Encoding/TextDecoder.h b/Libraries/LibWeb/Encoding/TextDecoder.h
deleted file mode 100644
index a046821341f..00000000000
--- a/Libraries/LibWeb/Encoding/TextDecoder.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2022, Ali Mohammad Pur <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Forward.h>
-#include <AK/NonnullRefPtr.h>
-#include <LibTextCodec/Decoder.h>
-#include <LibWeb/Bindings/Wrappable.h>
-#include <LibWeb/Encoding/TextDecoderCommon.h>
-#include <LibWeb/Forward.h>
-#include <LibWeb/WebIDL/AbstractOperations.h>
-#include <LibWeb/WebIDL/ExceptionOr.h>
-
-namespace Web::Encoding {
-
-// https://encoding.spec.whatwg.org/#textdecoder
-class TextDecoder
- : public Bindings::GCAllocatedWrappable
- , public TextDecoderCommonMixin {
- WEB_WRAPPABLE(TextDecoder, Bindings::GCAllocatedWrappable);
- GC_DECLARE_ALLOCATOR(TextDecoder);
-
-public:
- static WebIDL::ExceptionOr<GC::Ref<TextDecoder>> create(Utf16String const& label, TextDecoderOptions const& options = {});
- static WebIDL::ExceptionOr<GC::Ref<TextDecoder>> create(Utf16FlyString encoding, TextDecoderOptions const& options = {});
-
- virtual ~TextDecoder() override;
-
- WebIDL::ExceptionOr<Utf16String> decode(Optional<WebIDL::BufferSourceVariant> const& input, Optional<TextDecodeOptions> const&) const;
- WebIDL::ExceptionOr<Utf16String> decode(Optional<ReadonlyBytes>, bool stream) const;
-
-private:
- TextDecoder(FlyString encoding, TextCodec::ErrorMode error_mode, bool ignore_bom);
-};
-
-}
diff --git a/Libraries/LibWeb/Encoding/TextDecoder.idl b/Libraries/LibWeb/Encoding/TextDecoder.idl
index 31f54ddbaae..45fc709f9a2 100644
--- a/Libraries/LibWeb/Encoding/TextDecoder.idl
+++ b/Libraries/LibWeb/Encoding/TextDecoder.idl
@@ -10,7 +10,7 @@ dictionary TextDecodeOptions {
};
// https://encoding.spec.whatwg.org/#textdecoder
-[Exposed=*]
+[Exposed=*, ImplementedIn=Rust]
interface TextDecoder {
constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options = {});
diff --git a/Libraries/LibWeb/Encoding/TextDecoderCommon.h b/Libraries/LibWeb/Encoding/TextDecoderCommon.h
index 1120a1e777c..79d3bcc19c1 100644
--- a/Libraries/LibWeb/Encoding/TextDecoderCommon.h
+++ b/Libraries/LibWeb/Encoding/TextDecoderCommon.h
@@ -18,7 +18,6 @@
namespace Web::Encoding {
using TextDecoderOptions = Bindings::TextDecoderOptions;
-using TextDecodeOptions = Bindings::TextDecodeOptions;
struct EndOfQueue {
};
diff --git a/Libraries/LibWeb/Encoding/TextDecoderStream.h b/Libraries/LibWeb/Encoding/TextDecoderStream.h
index 2748958982b..88dd19f4ba2 100644
--- a/Libraries/LibWeb/Encoding/TextDecoderStream.h
+++ b/Libraries/LibWeb/Encoding/TextDecoderStream.h
@@ -9,7 +9,6 @@
#include <AK/ByteBuffer.h>
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/Wrappable.h>
-#include <LibWeb/Encoding/TextDecoder.h>
#include <LibWeb/Encoding/TextDecoderCommon.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Streams/GenericTransformStream.h>
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 678124b788c..577d21afc01 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -554,7 +554,6 @@ enum class HistoryAction : u8;
namespace Web::Encoding {
-class TextDecoder;
class TextEncoderStream;
}