2021-12-12 18:03:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
|
|
#include <AK/RefCounted.h>
|
|
|
|
#include <LibJS/Forward.h>
|
2022-09-04 17:09:45 +02:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2025-02-07 12:40:26 +00:00
|
|
|
#include <LibWeb/Encoding/TextEncoderCommon.h>
|
2021-12-12 18:03:22 +00:00
|
|
|
#include <LibWeb/Forward.h>
|
2023-11-23 20:07:25 +13:00
|
|
|
#include <LibWeb/WebIDL/Buffers.h>
|
2024-02-26 18:54:36 +01:00
|
|
|
#include <LibWeb/WebIDL/Types.h>
|
2021-12-12 18:03:22 +00:00
|
|
|
|
|
|
|
namespace Web::Encoding {
|
|
|
|
|
2023-10-06 07:03:44 +02:00
|
|
|
// https://encoding.spec.whatwg.org/#dictdef-textencoderencodeintoresult
|
|
|
|
struct TextEncoderEncodeIntoResult {
|
2024-02-26 18:54:36 +01:00
|
|
|
WebIDL::UnsignedLongLong read;
|
|
|
|
WebIDL::UnsignedLongLong written;
|
2023-10-06 07:03:44 +02:00
|
|
|
};
|
|
|
|
|
2021-12-12 18:03:22 +00:00
|
|
|
// https://encoding.spec.whatwg.org/#textencoder
|
2025-02-07 12:40:26 +00:00
|
|
|
class TextEncoder final
|
|
|
|
: public Bindings::PlatformObject
|
|
|
|
, public TextEncoderCommonMixin {
|
2022-09-04 10:56:37 +02:00
|
|
|
WEB_PLATFORM_OBJECT(TextEncoder, Bindings::PlatformObject);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(TextEncoder);
|
2021-12-12 18:03:22 +00:00
|
|
|
|
2022-09-04 10:56:37 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
static WebIDL::ExceptionOr<GC::Ref<TextEncoder>> construct_impl(JS::Realm&);
|
2021-12-12 18:03:22 +00:00
|
|
|
|
2022-09-04 10:56:37 +02:00
|
|
|
virtual ~TextEncoder() override;
|
2021-12-12 18:03:22 +00:00
|
|
|
|
2024-11-15 04:01:23 +13:00
|
|
|
GC::Ref<JS::Uint8Array> encode(String const& input) const;
|
|
|
|
TextEncoderEncodeIntoResult encode_into(String const& source, GC::Root<WebIDL::BufferSource> const& destination) const;
|
2021-12-12 18:05:11 +00:00
|
|
|
|
2021-12-12 18:03:22 +00:00
|
|
|
protected:
|
|
|
|
// https://encoding.spec.whatwg.org/#dom-textencoder
|
LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
2022-09-25 18:11:21 -06:00
|
|
|
explicit TextEncoder(JS::Realm&);
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2021-12-12 18:03:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|