mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibWeb: Extract the TextEncoderCommon mixin to its own IDL file
Co-Authored-By: Tim Flynn <trflynn89@pm.me>
This commit is contained in:
parent
c14d5f27f9
commit
24d5f24749
Notes:
github-actions[bot]
2025-02-07 16:05:58 +00:00
Author: https://github.com/Lubrsi Commit: https://github.com/LadybirdBrowser/ladybird/commit/24d5f24749f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3481 Reviewed-by: https://github.com/trflynn89 ✅
7 changed files with 57 additions and 14 deletions
|
@ -243,6 +243,7 @@ set(SOURCES
|
|||
Editing/Internal/Algorithms.cpp
|
||||
Encoding/TextDecoder.cpp
|
||||
Encoding/TextEncoder.cpp
|
||||
Encoding/TextEncoderCommon.cpp
|
||||
EntriesAPI/FileSystemEntry.cpp
|
||||
EventTiming/PerformanceEventTiming.cpp
|
||||
Fetch/Body.cpp
|
||||
|
|
|
@ -106,11 +106,4 @@ TextEncoderEncodeIntoResult TextEncoder::encode_into(String const& source, GC::R
|
|||
return { read, written };
|
||||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
|
||||
FlyString const& TextEncoder::encoding()
|
||||
{
|
||||
static FlyString const encoding = "utf-8"_fly_string;
|
||||
return encoding;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <AK/RefCounted.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Encoding/TextEncoderCommon.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/WebIDL/Buffers.h>
|
||||
#include <LibWeb/WebIDL/Types.h>
|
||||
|
@ -24,7 +25,9 @@ struct TextEncoderEncodeIntoResult {
|
|||
};
|
||||
|
||||
// https://encoding.spec.whatwg.org/#textencoder
|
||||
class TextEncoder final : public Bindings::PlatformObject {
|
||||
class TextEncoder final
|
||||
: public Bindings::PlatformObject
|
||||
, public TextEncoderCommonMixin {
|
||||
WEB_PLATFORM_OBJECT(TextEncoder, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(TextEncoder);
|
||||
|
||||
|
@ -36,8 +39,6 @@ public:
|
|||
GC::Ref<JS::Uint8Array> encode(String const& input) const;
|
||||
TextEncoderEncodeIntoResult encode_into(String const& source, GC::Root<WebIDL::BufferSource> const& destination) const;
|
||||
|
||||
static FlyString const& encoding();
|
||||
|
||||
protected:
|
||||
// https://encoding.spec.whatwg.org/#dom-textencoder
|
||||
explicit TextEncoder(JS::Realm&);
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
// https://encoding.spec.whatwg.org/#textencodercommon
|
||||
interface mixin TextEncoderCommon {
|
||||
readonly attribute DOMString encoding;
|
||||
};
|
||||
#import <Encoding/TextEncoderCommon.idl>
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dictdef-textencoderencodeintoresult
|
||||
dictionary TextEncoderEncodeIntoResult {
|
||||
|
@ -17,4 +14,5 @@ interface TextEncoder {
|
|||
[NewObject] Uint8Array encode(optional USVString input = "");
|
||||
TextEncoderEncodeIntoResult encodeInto(USVString source, [AllowShared] Uint8Array destination);
|
||||
};
|
||||
|
||||
TextEncoder includes TextEncoderCommon;
|
||||
|
|
22
Libraries/LibWeb/Encoding/TextEncoderCommon.cpp
Normal file
22
Libraries/LibWeb/Encoding/TextEncoderCommon.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Encoding/TextEncoderCommon.h>
|
||||
|
||||
namespace Web::Encoding {
|
||||
|
||||
TextEncoderCommonMixin::TextEncoderCommonMixin() = default;
|
||||
TextEncoderCommonMixin::~TextEncoderCommonMixin() = default;
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
|
||||
FlyString const& TextEncoderCommonMixin::encoding() const
|
||||
{
|
||||
// The encoding getter steps are to return "utf-8".
|
||||
static FlyString const encoding = "utf-8"_fly_string;
|
||||
return encoding;
|
||||
}
|
||||
|
||||
}
|
24
Libraries/LibWeb/Encoding/TextEncoderCommon.h
Normal file
24
Libraries/LibWeb/Encoding/TextEncoderCommon.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
|
||||
namespace Web::Encoding {
|
||||
|
||||
class TextEncoderCommonMixin {
|
||||
public:
|
||||
virtual ~TextEncoderCommonMixin();
|
||||
|
||||
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
|
||||
FlyString const& encoding() const;
|
||||
|
||||
protected:
|
||||
TextEncoderCommonMixin();
|
||||
};
|
||||
|
||||
}
|
4
Libraries/LibWeb/Encoding/TextEncoderCommon.idl
Normal file
4
Libraries/LibWeb/Encoding/TextEncoderCommon.idl
Normal file
|
@ -0,0 +1,4 @@
|
|||
// https://encoding.spec.whatwg.org/#textencodercommon
|
||||
interface mixin TextEncoderCommon {
|
||||
readonly attribute DOMString encoding;
|
||||
};
|
Loading…
Add table
Reference in a new issue