2021-12-12 15:03:22 -03: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 12:09:45 -03:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2021-12-12 15:03:22 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2023-11-23 04:07:25 -03:00
|
|
|
#include <LibWeb/WebIDL/Buffers.h>
|
2024-02-26 14:54:36 -03:00
|
|
|
#include <LibWeb/WebIDL/Types.h>
|
2021-12-12 15:03:22 -03:00
|
|
|
|
|
|
|
|
namespace Web::Encoding {
|
|
|
|
|
|
2023-10-06 02:03:44 -03:00
|
|
|
// https://encoding.spec.whatwg.org/#dictdef-textencoderencodeintoresult
|
|
|
|
|
struct TextEncoderEncodeIntoResult {
|
2024-02-26 14:54:36 -03:00
|
|
|
WebIDL::UnsignedLongLong read;
|
|
|
|
|
WebIDL::UnsignedLongLong written;
|
2023-10-06 02:03:44 -03:00
|
|
|
};
|
|
|
|
|
|
2021-12-12 15:03:22 -03:00
|
|
|
// https://encoding.spec.whatwg.org/#textencoder
|
2022-09-04 05:56:37 -03:00
|
|
|
class TextEncoder final : public Bindings::PlatformObject {
|
|
|
|
|
WEB_PLATFORM_OBJECT(TextEncoder, Bindings::PlatformObject);
|
2023-11-19 15:47:52 -03:00
|
|
|
JS_DECLARE_ALLOCATOR(TextEncoder);
|
2021-12-12 15:03:22 -03:00
|
|
|
|
2022-09-04 05:56:37 -03:00
|
|
|
public:
|
2023-02-19 12:53:44 -03:00
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<TextEncoder>> construct_impl(JS::Realm&);
|
2021-12-12 15:03:22 -03:00
|
|
|
|
2022-09-04 05:56:37 -03:00
|
|
|
virtual ~TextEncoder() override;
|
2021-12-12 15:03:22 -03:00
|
|
|
|
2023-10-06 02:03:44 -03:00
|
|
|
JS::NonnullGCPtr<JS::Uint8Array> encode(String const& input) const;
|
2023-11-23 04:07:25 -03:00
|
|
|
TextEncoderEncodeIntoResult encode_into(String const& source, JS::Handle<WebIDL::BufferSource> const& destination) const;
|
2021-12-12 15:05:11 -03:00
|
|
|
|
2023-09-06 01:10:23 -03:00
|
|
|
static FlyString const& encoding();
|
2021-12-12 15:06:07 -03:00
|
|
|
|
2021-12-12 15:03:22 -03: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 21:11:21 -03:00
|
|
|
explicit TextEncoder(JS::Realm&);
|
2023-01-10 08:28:20 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2021-12-12 15:03:22 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|