Skip to content

Truly independent web browser

LibWeb: Remove the unused operations of UniversalGlobalScopeMixin

Shannon Boothf8f884673b7c
diff --git a/Libraries/LibWeb/HTML/UniversalGlobalScope.cpp b/Libraries/LibWeb/HTML/UniversalGlobalScope.cpp
index f812c9cc02a..43b3495e4e4 100644
--- a/Libraries/LibWeb/HTML/UniversalGlobalScope.cpp
+++ b/Libraries/LibWeb/HTML/UniversalGlobalScope.cpp
@@ -7,28 +7,17 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/Base64.h>
#include <AK/String.h>
-#include <AK/StringBuilder.h>
-#include <AK/Utf8View.h>
#include <AK/Vector.h>
#include <LibGC/Function.h>
#include <LibGC/Heap.h>
-#include <LibJS/Runtime/NativeFunction.h>
-#include <LibTextCodec/Decoder.h>
-#include <LibWeb/Bindings/MessagePort.h>
+#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/HTML/PromiseRejectionEvent.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
-#include <LibWeb/HTML/StructuredSerialize.h>
#include <LibWeb/HTML/UniversalGlobalScope.h>
-#include <LibWeb/HTML/Window.h>
#include <LibWeb/HTML/WorkletGlobalScope.h>
-#include <LibWeb/WebIDL/AbstractOperations.h>
-#include <LibWeb/WebIDL/DOMException.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
-#include <LibWebCommon/Infra/CharacterTypes.h>
-#include <LibWebCommon/WebIDL/Types.h>
namespace Web::HTML {
@@ -47,73 +36,6 @@ void UniversalGlobalScopeMixin::visit_edges(GC::Cell::Visitor& visitor)
visitor.visit(m_about_to_be_notified_rejected_promises_list);
}
-// https://html.spec.whatwg.org/multipage/webappapis.html#dom-btoa
-WebIDL::ExceptionOr<Utf16String> UniversalGlobalScopeMixin::btoa(Utf16View data) const
-{
- auto& vm = this_impl().vm();
-
- // The btoa(data) method must throw an "InvalidCharacterError" DOMException if data contains any character whose code point is greater than U+00FF.
- Vector<u8> byte_string;
- byte_string.ensure_capacity(data.length_in_code_units());
- for (u32 code_point : data) {
- if (code_point > 0xff)
- return WebIDL::InvalidCharacterError::create(*vm.current_realm(), "Data contains characters outside the range U+0000 and U+00FF"_utf16);
- byte_string.append(code_point);
- }
-
- // Otherwise, the user agent must convert data to a byte sequence whose nth byte is the eight-bit representation of the nth code point of data,
- // and then must apply forgiving-base64 encode to that byte sequence and return the result.
- return TRY_OR_THROW_OOM(vm, encode_base64_to_utf16(byte_string.span()));
-}
-
-// https://html.spec.whatwg.org/multipage/webappapis.html#dom-atob
-WebIDL::ExceptionOr<Utf16String> UniversalGlobalScopeMixin::atob(Utf16View data) const
-{
- auto& vm = this_impl().vm();
- auto& realm = *vm.current_realm();
-
- // 1. Let decodedData be the result of running forgiving-base64 decode on data.
- ByteBuffer decoded_data;
- TRY_OR_THROW_OOM(vm, decoded_data.try_resize(size_required_to_decode_base64(data)));
- auto decode_result = decode_base64_into(data, decoded_data);
-
- // 2. If decodedData is failure, then throw an "InvalidCharacterError" DOMException.
- if (decode_result.is_error())
- return WebIDL::InvalidCharacterError::create(realm, "Input string is not valid base64 data"_utf16);
-
- // 3. Return decodedData.
- Utf16StringBuilder builder { decoded_data.size() };
- for (auto byte : decoded_data.bytes())
- builder.append_code_unit(byte);
- return builder.to_string();
-}
-
-// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-queuemicrotask
-void UniversalGlobalScopeMixin::queue_microtask(WebIDL::CallbackType& callback)
-{
- GC::Ptr<DOM::Document> document;
- if (is<Window>(this_impl()))
- document = &static_cast<Window&>(this_impl()).associated_document();
-
- // The queueMicrotask(callback) method must queue a microtask to invoke callback with « » and "report".
- HTML::queue_a_microtask(document, GC::create_function(GC::Heap::the(), [&callback] {
- (void)WebIDL::invoke_callback(callback, {}, WebIDL::ExceptionBehavior::Report, {});
- }));
-}
-
-// https://html.spec.whatwg.org/multipage/structured-data.html#dom-structuredclone
-WebIDL::ExceptionOr<JS::Value> UniversalGlobalScopeMixin::structured_clone(JS::Realm& realm, JS::Value value, Bindings::StructuredSerializeOptions const& options)
-{
- // 1. Let serialized be ? StructuredSerializeWithTransfer(value, options["transfer"]).
- auto serialized = TRY(HTML::structured_serialize_with_transfer(realm, value, options.transfer));
-
- // 2. Let deserializeRecord be ? StructuredDeserializeWithTransfer(serialized, this's relevant realm).
- auto deserialized = TRY(HTML::structured_deserialize_with_transfer(serialized, realm));
-
- // 3. Return deserializeRecord.[[Deserialized]].
- return deserialized.deserialized;
-}
-
void UniversalGlobalScopeMixin::push_onto_outstanding_rejected_promises_weak_set(GC::Ptr<JS::Promise> promise)
{
m_outstanding_rejected_promises_weak_set.append(promise);
diff --git a/Libraries/LibWeb/HTML/UniversalGlobalScope.h b/Libraries/LibWeb/HTML/UniversalGlobalScope.h
index 9c707043b53..db70239158a 100644
--- a/Libraries/LibWeb/HTML/UniversalGlobalScope.h
+++ b/Libraries/LibWeb/HTML/UniversalGlobalScope.h
@@ -9,18 +9,9 @@
#pragma once
#include <AK/Forward.h>
-#include <AK/Utf16String.h>
#include <LibGC/HeapVector.h>
-#include <LibJS/Runtime/Value.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/Scripting/ImportMap.h>
-#include <LibWeb/WebIDL/ExceptionOr.h>
-
-namespace Web::Bindings {
-
-struct StructuredSerializeOptions;
-
-}
namespace Web::HTML {
@@ -32,11 +23,6 @@ public:
virtual DOM::EventTarget& this_impl() = 0;
virtual DOM::EventTarget const& this_impl() const = 0;
- WebIDL::ExceptionOr<Utf16String> btoa(Utf16View data) const;
- WebIDL::ExceptionOr<Utf16String> atob(Utf16View data) const;
- void queue_microtask(WebIDL::CallbackType&);
- WebIDL::ExceptionOr<JS::Value> structured_clone(JS::Realm&, JS::Value, Bindings::StructuredSerializeOptions const&);
-
void push_onto_outstanding_rejected_promises_weak_set(GC::Ptr<JS::Promise>);
bool remove_from_outstanding_rejected_promises_weak_set(GC::Ptr<JS::Promise>);
diff --git a/Meta/Linters/check_libweb_realm_mentions.py b/Meta/Linters/check_libweb_realm_mentions.py
index 1c65847b236..b69af9b6489 100755
--- a/Meta/Linters/check_libweb_realm_mentions.py
+++ b/Meta/Linters/check_libweb_realm_mentions.py
@@ -51,8 +51,8 @@ ALLOWED_REALM_MENTIONS = {
),
"FileAPI": (2, 9, "Blob glue still creates streams and buffers in selected realms"),
"HTML": (
- 65,
- 187,
+ 64,
+ 185,
"HTML algorithms still contain structured serialization, including posted-message preparation, canvas, navigation transfer/reconstruction, worker/worklet, and event realm use, and cross-origin Window/Location property functions are created in the current realm; RemoteWindow mirrors Window's postMessage; "
"the C++ glue of the Rust structured serialization creates platform objects and SharedArrayBuffers in a given realm",
),