mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Move WindowProxy from Bindings/ to HTML/
This commit is contained in:
parent
86f68eb3c3
commit
56d8c4ff26
Notes:
sideshowbarker
2024-07-17 06:39:52 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/56d8c4ff26 Pull-request: https://github.com/SerenityOS/serenity/pull/15345 Reviewed-by: https://github.com/awesomekling ✅
5 changed files with 18 additions and 18 deletions
|
@ -13,13 +13,13 @@
|
|||
#include <LibJS/Runtime/VM.h>
|
||||
#include <LibWeb/Bindings/LocationObject.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/Bindings/WindowProxy.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/PromiseRejectionEvent.h>
|
||||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/HTML/WindowProxy.h>
|
||||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||
|
||||
|
@ -62,7 +62,7 @@ JS::VM& main_thread_vm()
|
|||
// 8.1.5.1 HostEnsureCanAddPrivateElement(O), https://html.spec.whatwg.org/multipage/webappapis.html#the-hostensurecanaddprivateelement-implementation
|
||||
vm->host_ensure_can_add_private_element = [](JS::Object const& object) -> JS::ThrowCompletionOr<void> {
|
||||
// 1. If O is a WindowProxy object, or implements Location, then return Completion { [[Type]]: throw, [[Value]]: a new TypeError }.
|
||||
if (is<WindowProxy>(object) || is<LocationObject>(object))
|
||||
if (is<HTML::WindowProxy>(object) || is<LocationObject>(object))
|
||||
return vm->throw_completion<JS::TypeError>("Cannot add private elements to window or location object");
|
||||
|
||||
// 2. Return NormalCompletion(unused).
|
||||
|
|
|
@ -13,7 +13,6 @@ set(SOURCES
|
|||
Bindings/OptionConstructor.cpp
|
||||
Bindings/PlatformObject.cpp
|
||||
Bindings/WindowConstructor.cpp
|
||||
Bindings/WindowProxy.cpp
|
||||
Crypto/Crypto.cpp
|
||||
Crypto/SubtleCrypto.cpp
|
||||
CSS/Angle.cpp
|
||||
|
@ -262,6 +261,7 @@ set(SOURCES
|
|||
HTML/Timer.cpp
|
||||
HTML/Window.cpp
|
||||
HTML/WindowEventHandlers.cpp
|
||||
HTML/WindowProxy.cpp
|
||||
HTML/Worker.cpp
|
||||
HTML/WorkerDebugConsoleClient.cpp
|
||||
HTML/WorkerGlobalScope.cpp
|
||||
|
|
|
@ -317,6 +317,7 @@ class TextMetrics;
|
|||
class Timer;
|
||||
class Window;
|
||||
class WindowEnvironmentSettingsObject;
|
||||
class WindowProxy;
|
||||
class Worker;
|
||||
class WorkerEnvironmentSettingsObject;
|
||||
class WorkerGlobalScope;
|
||||
|
@ -467,7 +468,6 @@ namespace Web::Bindings {
|
|||
class LocationObject;
|
||||
class OptionConstructor;
|
||||
class RangePrototype;
|
||||
class WindowProxy;
|
||||
class Wrappable;
|
||||
class Wrapper;
|
||||
class XMLHttpRequestPrototype;
|
||||
|
|
|
@ -10,17 +10,17 @@
|
|||
#include <LibJS/Runtime/GlobalObject.h>
|
||||
#include <LibJS/Runtime/PropertyDescriptor.h>
|
||||
#include <LibJS/Runtime/PropertyKey.h>
|
||||
#include <LibWeb/Bindings/WindowProxy.h>
|
||||
#include <LibWeb/DOM/DOMException.h>
|
||||
#include <LibWeb/HTML/CrossOrigin/AbstractOperations.h>
|
||||
#include <LibWeb/HTML/CrossOrigin/Reporting.h>
|
||||
#include <LibWeb/HTML/Scripting/Environments.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/HTML/WindowProxy.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
namespace Web::HTML {
|
||||
|
||||
// 7.4 The WindowProxy exotic object, https://html.spec.whatwg.org/multipage/window-object.html#the-windowproxy-exotic-object
|
||||
WindowProxy::WindowProxy(JS::Realm& realm, HTML::Window& window)
|
||||
WindowProxy::WindowProxy(JS::Realm& realm, Window& window)
|
||||
: JS::Object(realm, nullptr)
|
||||
, m_window(window)
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_ge
|
|||
return m_window->internal_get_own_property(property_key);
|
||||
|
||||
// 4. Let property be CrossOriginGetOwnPropertyHelper(W, P).
|
||||
auto property = cross_origin_get_own_property_helper(const_cast<HTML::Window*>(m_window.ptr()), property_key);
|
||||
auto property = cross_origin_get_own_property_helper(const_cast<Window*>(m_window.ptr()), property_key);
|
||||
|
||||
// 5. If property is not undefined, then return property.
|
||||
if (property.has_value())
|
||||
|
@ -120,7 +120,7 @@ JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> WindowProxy::internal_ge
|
|||
}
|
||||
|
||||
// 7. Return ? CrossOriginPropertyFallback(P).
|
||||
return TRY(HTML::cross_origin_property_fallback(vm, property_key));
|
||||
return TRY(cross_origin_property_fallback(vm, property_key));
|
||||
}
|
||||
|
||||
// 7.4.6 [[DefineOwnProperty]] ( P, Desc ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-defineownproperty
|
||||
|
@ -151,7 +151,7 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const
|
|||
// 1. Let W be the value of the [[Window]] internal slot of this.
|
||||
|
||||
// 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object.
|
||||
HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<HTML::Window>(HTML::current_global_object()).browsing_context(), *m_window->browsing_context(), property_key, HTML::current_settings_object());
|
||||
check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<Window>(current_global_object()).browsing_context(), *m_window->browsing_context(), property_key, current_settings_object());
|
||||
|
||||
// 3. If IsPlatformObjectSameOrigin(W) is true, then return ? OrdinaryGet(this, P, Receiver).
|
||||
// NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
|
||||
|
@ -160,7 +160,7 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const
|
|||
|
||||
// 4. Return ? CrossOriginGet(this, P, Receiver).
|
||||
// NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
|
||||
return HTML::cross_origin_get(vm, *this, property_key, receiver);
|
||||
return cross_origin_get(vm, *this, property_key, receiver);
|
||||
}
|
||||
|
||||
// 7.4.8 [[Set]] ( P, V, Receiver ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-set
|
||||
|
@ -171,7 +171,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& pro
|
|||
// 1. Let W be the value of the [[Window]] internal slot of this.
|
||||
|
||||
// 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object.
|
||||
HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<HTML::Window>(HTML::current_global_object()).browsing_context(), *m_window->browsing_context(), property_key, HTML::current_settings_object());
|
||||
check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<Window>(current_global_object()).browsing_context(), *m_window->browsing_context(), property_key, current_settings_object());
|
||||
|
||||
// 3. If IsPlatformObjectSameOrigin(W) is true, then:
|
||||
if (is_platform_object_same_origin(*m_window)) {
|
||||
|
@ -185,7 +185,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& pro
|
|||
|
||||
// 4. Return ? CrossOriginSet(this, P, V, Receiver).
|
||||
// NOTE: this is passed rather than W as CrossOriginSet will invoke the [[GetOwnProperty]] internal method.
|
||||
return HTML::cross_origin_set(vm, *this, property_key, value, receiver);
|
||||
return cross_origin_set(vm, *this, property_key, value, receiver);
|
||||
}
|
||||
|
||||
// 7.4.9 [[Delete]] ( P ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-delete
|
||||
|
@ -219,7 +219,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_delete(JS::PropertyKey const&
|
|||
// 7.4.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/window-object.html#windowproxy-ownpropertykeys
|
||||
JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> WindowProxy::internal_own_property_keys() const
|
||||
{
|
||||
auto& event_loop = HTML::main_thread_event_loop();
|
||||
auto& event_loop = main_thread_event_loop();
|
||||
auto& vm = event_loop.vm();
|
||||
|
||||
// 1. Let W be the value of the [[Window]] internal slot of this.
|
|
@ -12,7 +12,7 @@
|
|||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Bindings {
|
||||
namespace Web::HTML {
|
||||
|
||||
class WindowProxy final : public JS::Object {
|
||||
JS_OBJECT(WindowProxy, JS::Object);
|
||||
|
@ -31,19 +31,19 @@ public:
|
|||
virtual JS::ThrowCompletionOr<bool> internal_delete(JS::PropertyKey const&) override;
|
||||
virtual JS::ThrowCompletionOr<JS::MarkedVector<JS::Value>> internal_own_property_keys() const override;
|
||||
|
||||
HTML::Window& window() const { return const_cast<HTML::Window&>(*m_window); }
|
||||
Window& window() const { return const_cast<Window&>(*m_window); }
|
||||
|
||||
// NOTE: Someone will have to replace the wrapped window object as well:
|
||||
// "When the browsing context is navigated, the Window object wrapped by the browsing context's associated WindowProxy object is changed."
|
||||
// I haven't found where that actually happens yet. Make sure to use a Badge<T> guarded setter.
|
||||
|
||||
private:
|
||||
WindowProxy(JS::Realm&, HTML::Window&);
|
||||
WindowProxy(JS::Realm&, Window&);
|
||||
|
||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
||||
|
||||
// [[Window]], https://html.spec.whatwg.org/multipage/window-object.html#concept-windowproxy-window
|
||||
JS::GCPtr<HTML::Window> m_window;
|
||||
JS::GCPtr<Window> m_window;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue