Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibWeb: ShadowRealms part 4 - enough for it to not crash #1993

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tests/LibWeb/Text/expected/all-window-properties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ ServiceWorkerContainer
ServiceWorkerRegistration
Set
ShadowRealm
ShadowRealmGlobalScope
ShadowRoot
SharedArrayBuffer
SourceBuffer
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ set(SOURCES
HTML/ServiceWorkerRegistration.cpp
HTML/SessionHistoryEntry.cpp
HTML/SessionHistoryTraversalQueue.cpp
HTML/ShadowRealmGlobalScope.cpp
HTML/SharedResourceRequest.cpp
HTML/SourceSet.cpp
HTML/Storage.cpp
Expand Down
38 changes: 38 additions & 0 deletions Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024, Shannon Booth <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <LibWeb/Bindings/ShadowRealmGlobalScopePrototype.h>
#include <LibWeb/HTML/ShadowRealmGlobalScope.h>

namespace Web::HTML {

JS_DEFINE_ALLOCATOR(ShadowRealmGlobalScope);

ShadowRealmGlobalScope::ShadowRealmGlobalScope(JS::Realm& realm)
: DOM::EventTarget(realm)
{
}

ShadowRealmGlobalScope::~ShadowRealmGlobalScope() = default;

JS::NonnullGCPtr<ShadowRealmGlobalScope> ShadowRealmGlobalScope::create(JS::Realm& realm)
{
return realm.heap().allocate<ShadowRealmGlobalScope>(realm, realm);
}

void ShadowRealmGlobalScope::initialize(JS::Realm&)
{
// FIXME: This does not work as we do not have any intrinsics in the [HostDefined] of a shadow realm. Figure out how this _should_ work.
// Base::initialize(realm);
// WEB_SET_PROTOTYPE_FOR_INTERFACE(ShadowRealmGlobalScope);
ADKaster marked this conversation as resolved.
Show resolved Hide resolved
}

void ShadowRealmGlobalScope::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
}

}
38 changes: 38 additions & 0 deletions Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2024, Shannon Booth <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/DOM/EventTarget.h>

namespace Web::HTML {

// https://whatpr.org/html/9893/webappapis.html#shadowrealmglobalscope
class ShadowRealmGlobalScope : public DOM::EventTarget {
ADKaster marked this conversation as resolved.
Show resolved Hide resolved
WEB_PLATFORM_OBJECT(ShadowRealmGlobalScope, DOM::EventTarget);
JS_DECLARE_ALLOCATOR(ShadowRealmGlobalScope);

public:
virtual ~ShadowRealmGlobalScope() override;

static JS::NonnullGCPtr<ShadowRealmGlobalScope> create(JS::Realm&);

// https://whatpr.org/html/9893/webappapis.html#dom-shadowrealmglobalscope-self
JS::NonnullGCPtr<ShadowRealmGlobalScope> self()
{
// The self getter steps are to return this.
return *this;
}

protected:
explicit ShadowRealmGlobalScope(JS::Realm&);

virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
};

}
6 changes: 6 additions & 0 deletions Userland/Libraries/LibWeb/HTML/ShadowRealmGlobalScope.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// https://whatpr.org/html/9893/webappapis.html#shadowrealmglobalscope
// FIXME: This is not correct! We should not have Exposed=Window here.
[Global, Exposed=Window]
interface ShadowRealmGlobalScope : EventTarget {
readonly attribute ShadowRealmGlobalScope self;
};
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/idl_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ libweb_js_bindings(HTML/RadioNodeList)
libweb_js_bindings(HTML/ServiceWorker)
libweb_js_bindings(HTML/ServiceWorkerContainer)
libweb_js_bindings(HTML/ServiceWorkerRegistration)
libweb_js_bindings(HTML/ShadowRealmGlobalScope)
libweb_js_bindings(HTML/Storage)
libweb_js_bindings(HTML/SubmitEvent)
libweb_js_bindings(HTML/TextMetrics)
Expand Down