Replace the generated C++ legacy codec implementations with a small Rust wrapper around encoding_rs. This keeps the existing LibTextCodec API while moving label lookup, legacy decode/encode, validation, and streaming decoder state to Rust. The generated index data and generator are no longer needed. It also fixes several TextDecoder EOF cases due to a more correct implementation. encoding_rs finalizes decoders according to the Encoding Standard, so incomplete UTF-8/Big5 tails and malformed UTF-16 surrogate tails produce the required single replacement at end-of-queue instead of being dropped, buffered, or double-counted by our old hand-written decoders.
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2026-present, the Ladybird developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/OwnPtr.h>
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
|
#include <LibWeb/Encoding/TextDecoder.h>
|
|
#include <LibWeb/Encoding/TextDecoderCommon.h>
|
|
#include <LibWeb/Streams/GenericTransformStream.h>
|
|
|
|
namespace Web::Encoding {
|
|
|
|
// https://encoding.spec.whatwg.org/#textdecoderstream
|
|
class TextDecoderStream final
|
|
: public Bindings::PlatformObject
|
|
, public Streams::GenericTransformStreamMixin
|
|
, public TextDecoderCommonMixin {
|
|
WEB_PLATFORM_OBJECT(TextDecoderStream, Bindings::PlatformObject);
|
|
GC_DECLARE_ALLOCATOR(TextDecoderStream);
|
|
|
|
public:
|
|
static WebIDL::ExceptionOr<GC::Ref<TextDecoderStream>> construct_impl(JS::Realm&, FlyString label, Bindings::TextDecoderOptions const&);
|
|
virtual ~TextDecoderStream() override;
|
|
|
|
private:
|
|
TextDecoderStream(JS::Realm&, GC::Ref<Streams::TransformStream>, TextCodec::Decoder&, FlyString encoding, ErrorMode, bool ignore_bom);
|
|
|
|
virtual void initialize(JS::Realm&) override;
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
WebIDL::ExceptionOr<void> decode_and_enqueue_chunk(JS::Value);
|
|
WebIDL::ExceptionOr<void> flush_and_enqueue();
|
|
|
|
WebIDL::ExceptionOr<void> enqueue_decoded_output(String const&);
|
|
|
|
// https://encoding.spec.whatwg.org/#textdecodercommon-i-o-queue
|
|
NonnullOwnPtr<TextCodec::StreamingDecoder> m_streaming_decoder;
|
|
};
|
|
|
|
}
|