mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibWeb: Add support for interfaces being exposed for shadow realm
This commit is contained in:
parent
fc2104f099
commit
2ea31fad32
Notes:
github-actions[bot]
2024-11-09 19:37:16 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/2ea31fad32c Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2220 Reviewed-by: https://github.com/ADKaster ✅
7 changed files with 31 additions and 8 deletions
|
@ -195,6 +195,7 @@ function (generate_js_bindings target)
|
|||
IntrinsicDefinitions.cpp
|
||||
DedicatedWorkerExposedInterfaces.cpp DedicatedWorkerExposedInterfaces.h
|
||||
SharedWorkerExposedInterfaces.cpp SharedWorkerExposedInterfaces.h
|
||||
ShadowRealmExposedInterfaces.cpp ShadowRealmExposedInterfaces.h
|
||||
WindowExposedInterfaces.cpp WindowExposedInterfaces.h)
|
||||
list(TRANSFORM exposed_interface_sources PREPEND "Bindings/")
|
||||
add_custom_command(
|
||||
|
@ -206,6 +207,8 @@ function (generate_js_bindings target)
|
|||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/DedicatedWorkerExposedInterfaces.cpp "Bindings/DedicatedWorkerExposedInterfaces.cpp"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/SharedWorkerExposedInterfaces.h "Bindings/SharedWorkerExposedInterfaces.h"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/SharedWorkerExposedInterfaces.cpp "Bindings/SharedWorkerExposedInterfaces.cpp"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/ShadowRealmExposedInterfaces.h "Bindings/ShadowRealmExposedInterfaces.h"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/ShadowRealmExposedInterfaces.cpp "Bindings/ShadowRealmExposedInterfaces.cpp"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/WindowExposedInterfaces.h "Bindings/WindowExposedInterfaces.h"
|
||||
COMMAND "${CMAKE_COMMAND}" -E copy_if_different tmp/WindowExposedInterfaces.cpp "Bindings/WindowExposedInterfaces.cpp"
|
||||
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/tmp"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <LibIDL/Types.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
static ErrorOr<void> add_to_interface_sets(IDL::Interface&, Vector<IDL::Interface&>& intrinsics, Vector<IDL::Interface&>& window_exposed, Vector<IDL::Interface&>& dedicated_worker_exposed, Vector<IDL::Interface&>& shared_worker_exposed);
|
||||
static ErrorOr<void> add_to_interface_sets(IDL::Interface&, Vector<IDL::Interface&>& intrinsics, Vector<IDL::Interface&>& window_exposed, Vector<IDL::Interface&>& dedicated_worker_exposed, Vector<IDL::Interface&>& shared_worker_exposed, Vector<IDL::Interface&>& shadow_realm_exposed);
|
||||
static ByteString s_error_string;
|
||||
|
||||
struct LegacyConstructor {
|
||||
|
@ -367,6 +367,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
Vector<IDL::Interface&> window_exposed;
|
||||
Vector<IDL::Interface&> dedicated_worker_exposed;
|
||||
Vector<IDL::Interface&> shared_worker_exposed;
|
||||
Vector<IDL::Interface&> shadow_realm_exposed;
|
||||
// TODO: service_worker_exposed
|
||||
|
||||
for (size_t i = 0; i < paths.size(); ++i) {
|
||||
|
@ -378,7 +379,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return Error::from_string_view(s_error_string.view());
|
||||
}
|
||||
|
||||
TRY(add_to_interface_sets(interface, intrinsics, window_exposed, dedicated_worker_exposed, shared_worker_exposed));
|
||||
TRY(add_to_interface_sets(interface, intrinsics, window_exposed, dedicated_worker_exposed, shared_worker_exposed, shadow_realm_exposed));
|
||||
parsers.append(move(parser));
|
||||
}
|
||||
|
||||
|
@ -387,11 +388,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
TRY(generate_exposed_interface_header("Window"sv, output_path));
|
||||
TRY(generate_exposed_interface_header("DedicatedWorker"sv, output_path));
|
||||
TRY(generate_exposed_interface_header("SharedWorker"sv, output_path));
|
||||
TRY(generate_exposed_interface_header("ShadowRealm"sv, output_path));
|
||||
// TODO: ServiceWorkerExposed.h
|
||||
|
||||
TRY(generate_exposed_interface_implementation("Window"sv, output_path, window_exposed));
|
||||
TRY(generate_exposed_interface_implementation("DedicatedWorker"sv, output_path, dedicated_worker_exposed));
|
||||
TRY(generate_exposed_interface_implementation("SharedWorker"sv, output_path, shared_worker_exposed));
|
||||
TRY(generate_exposed_interface_implementation("ShadowRealm"sv, output_path, shadow_realm_exposed));
|
||||
// TODO: ServiceWorkerExposed.cpp
|
||||
|
||||
return 0;
|
||||
|
@ -404,8 +407,9 @@ enum ExposedTo {
|
|||
ServiceWorker = 0x4,
|
||||
AudioWorklet = 0x8,
|
||||
Window = 0x10,
|
||||
AllWorkers = 0xF, // FIXME: Is "AudioWorklet" a Worker? We'll assume it is for now
|
||||
All = 0x1F,
|
||||
ShadowRealm = 0x20,
|
||||
AllWorkers = DedicatedWorker | SharedWorker | ServiceWorker | AudioWorklet, // FIXME: Is "AudioWorklet" a Worker? We'll assume it is for now (here, and line below)
|
||||
All = AllWorkers | Window | ShadowRealm
|
||||
};
|
||||
AK_ENUM_BITWISE_OPERATORS(ExposedTo);
|
||||
|
||||
|
@ -436,6 +440,8 @@ static ErrorOr<ExposedTo> parse_exposure_set(IDL::Interface& interface)
|
|||
return ExposedTo::ServiceWorker;
|
||||
if (exposed == "AudioWorklet"sv)
|
||||
return ExposedTo::AudioWorklet;
|
||||
if (exposed == "ShadowRealm"sv)
|
||||
return ExposedTo::ShadowRealm;
|
||||
|
||||
if (exposed[0] == '(') {
|
||||
ExposedTo whom = Nobody;
|
||||
|
@ -453,6 +459,8 @@ static ErrorOr<ExposedTo> parse_exposure_set(IDL::Interface& interface)
|
|||
whom |= ExposedTo::ServiceWorker;
|
||||
} else if (candidate == "AudioWorklet"sv) {
|
||||
whom |= ExposedTo::AudioWorklet;
|
||||
} else if (candidate == "ShadowRealm"sv) {
|
||||
whom |= ExposedTo::ShadowRealm;
|
||||
} else {
|
||||
s_error_string = ByteString::formatted("Unknown Exposed attribute candidate {} in {} in {}", candidate, exposed, interface.name);
|
||||
return Error::from_string_view(s_error_string.view());
|
||||
|
@ -469,7 +477,7 @@ static ErrorOr<ExposedTo> parse_exposure_set(IDL::Interface& interface)
|
|||
return Error::from_string_view(s_error_string.view());
|
||||
}
|
||||
|
||||
ErrorOr<void> add_to_interface_sets(IDL::Interface& interface, Vector<IDL::Interface&>& intrinsics, Vector<IDL::Interface&>& window_exposed, Vector<IDL::Interface&>& dedicated_worker_exposed, Vector<IDL::Interface&>& shared_worker_exposed)
|
||||
ErrorOr<void> add_to_interface_sets(IDL::Interface& interface, Vector<IDL::Interface&>& intrinsics, Vector<IDL::Interface&>& window_exposed, Vector<IDL::Interface&>& dedicated_worker_exposed, Vector<IDL::Interface&>& shared_worker_exposed, Vector<IDL::Interface&>& shadow_realm_exposed)
|
||||
{
|
||||
// TODO: Add service worker exposed and audio worklet exposed
|
||||
auto whom = TRY(parse_exposure_set(interface));
|
||||
|
@ -485,5 +493,8 @@ ErrorOr<void> add_to_interface_sets(IDL::Interface& interface, Vector<IDL::Inter
|
|||
if (whom & ExposedTo::SharedWorker)
|
||||
shared_worker_exposed.append(interface);
|
||||
|
||||
if (whom & ExposedTo::ShadowRealm)
|
||||
shadow_realm_exposed.append(interface);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -340,7 +340,6 @@ ServiceWorkerContainer
|
|||
ServiceWorkerRegistration
|
||||
Set
|
||||
ShadowRealm
|
||||
ShadowRealmGlobalScope
|
||||
ShadowRoot
|
||||
SharedArrayBuffer
|
||||
SourceBuffer
|
||||
|
|
|
@ -600,6 +600,9 @@ ErrorOr<void> initialize_main_thread_vm(HTML::EventLoop::Type type)
|
|||
// 11. Perform ? SetDefaultGlobalBindings(realm).
|
||||
set_default_global_bindings(realm);
|
||||
|
||||
// NOTE: This needs to be done after initialization so that the realm has an intrinsics in its [[HostDefined]]
|
||||
global_object->initialize_web_interfaces();
|
||||
|
||||
// 12. Return NormalCompletion(unused).
|
||||
return {};
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/ShadowRealmExposedInterfaces.h>
|
||||
#include <LibWeb/Bindings/ShadowRealmGlobalScopePrototype.h>
|
||||
#include <LibWeb/HTML/ShadowRealmGlobalScope.h>
|
||||
|
||||
|
@ -30,6 +31,11 @@ void ShadowRealmGlobalScope::initialize(JS::Realm&)
|
|||
// WEB_SET_PROTOTYPE_FOR_INTERFACE(ShadowRealmGlobalScope);
|
||||
}
|
||||
|
||||
void ShadowRealmGlobalScope::initialize_web_interfaces()
|
||||
{
|
||||
add_shadow_realm_exposed_interfaces(*this);
|
||||
}
|
||||
|
||||
void ShadowRealmGlobalScope::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
|
|
|
@ -28,6 +28,8 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
void initialize_web_interfaces();
|
||||
|
||||
protected:
|
||||
explicit ShadowRealmGlobalScope(JS::Realm&);
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// https://whatpr.org/html/9893/webappapis.html#shadowrealmglobalscope
|
||||
// FIXME: This is not correct! We should not have Exposed=Window here.
|
||||
[Global, Exposed=Window]
|
||||
[Global, Exposed=ShadowRealm]
|
||||
interface ShadowRealmGlobalScope : EventTarget {
|
||||
readonly attribute ShadowRealmGlobalScope self;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue