1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:57:45 +00:00

LibWeb/HTML: Port Window.location to IDL

This commit is contained in:
Linus Groh 2023-03-05 20:13:00 +00:00
parent 0e40841990
commit eccc0d90de
3 changed files with 15 additions and 13 deletions

View file

@ -11,10 +11,12 @@
#include <AK/GenericLexer.h>
#include <AK/Utf8View.h>
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibJS/Runtime/Accessor.h>
#include <LibJS/Runtime/Completion.h>
#include <LibJS/Runtime/Error.h>
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalEnvironment.h>
#include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/Shape.h>
#include <LibTextCodec/Decoder.h>
#include <LibWeb/Bindings/CSSNamespace.h>
@ -1135,8 +1137,9 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
// Legacy
define_native_accessor(realm, "event", event_getter, event_setter, JS::Attribute::Enumerable);
// NOTE: location is marked as [LegacyUnforgeable], meaning it isn't configurable.
define_native_accessor(realm, "location", location_getter, location_setter, JS::Attribute::Enumerable);
// FIXME: Implement codegen for readonly properties with [PutForwards]
auto& location_accessor = storage_get("location")->value.as_accessor();
location_accessor.set_setter(JS::NativeFunction::create(realm, location_setter, 1, "location", &realm, {}, "set"sv));
// WebAssembly "namespace"
define_direct_property("WebAssembly", MUST_OR_THROW_OOM(heap().allocate<Bindings::WebAssemblyObject>(realm, realm)), JS::Attribute::Enumerable | JS::Attribute::Configurable);
@ -1222,6 +1225,13 @@ void Window::set_name(String const& name)
browsing_context()->set_name(name.to_deprecated_string());
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location
JS::NonnullGCPtr<Location> Window::location() const
{
// The Window object's location getter steps are to return this's Location object.
return *m_location;
}
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
JS::NonnullGCPtr<WindowProxy> Window::frames() const
{
@ -1632,12 +1642,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::event_setter)
REPLACEABLE_PROPERTY_SETTER(Window, event);
}
JS_DEFINE_NATIVE_FUNCTION(Window::location_getter)
{
auto* impl = TRY(impl_from(vm));
return impl->m_location;
}
JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
{
auto* impl = TRY(impl_from(vm));

View file

@ -14,6 +14,7 @@
#include <AK/URL.h>
#include <LibJS/Heap/Heap.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/WindowGlobalMixin.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/AnimationFrameCallbackDriver.h>
@ -23,7 +24,6 @@
#include <LibWeb/HTML/Plugin.h>
#include <LibWeb/HTML/Scripting/ImportMap.h>
#include <LibWeb/HTML/WindowEventHandlers.h>
#include <LibWeb/Bindings/WindowGlobalMixin.h>
namespace Web::HTML {
@ -142,6 +142,7 @@ public:
JS::NonnullGCPtr<DOM::Document const> document() const;
String name() const;
void set_name(String const&);
JS::NonnullGCPtr<Location> location() const;
JS::NonnullGCPtr<WindowProxy> frames() const;
@ -209,9 +210,6 @@ private:
public:
HTML::Origin origin() const;
HTML::Location* location() { return m_location; }
HTML::Location const* location() const { return m_location; }
virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(JS::Object* prototype) override;
CrossOriginPropertyDescriptorMap const& cross_origin_property_descriptor_map() const { return m_cross_origin_property_descriptor_map; }
@ -223,7 +221,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(frame_element_getter);
JS_DECLARE_NATIVE_FUNCTION(location_getter);
JS_DECLARE_NATIVE_FUNCTION(location_setter);
JS_DECLARE_NATIVE_FUNCTION(performance_getter);

View file

@ -11,6 +11,7 @@ interface Window : EventTarget {
[Replaceable] readonly attribute WindowProxy self;
[LegacyUnforgeable] readonly attribute Document document;
attribute DOMString name;
[PutForwards=href, LegacyUnforgeable] readonly attribute Location location;
// other browsing contexts
[Replaceable] readonly attribute WindowProxy frames;