LibWeb/HTML: Port Window.navigator to IDL

This commit is contained in:
Linus Groh 2023-03-05 17:55:03 +00:00
parent c219e6d9c1
commit eb2425040b
Notes: sideshowbarker 2024-07-16 23:16:15 +09:00
3 changed files with 14 additions and 11 deletions

View file

@ -1160,9 +1160,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
// Legacy
define_native_accessor(realm, "event", event_getter, event_setter, JS::Attribute::Enumerable);
define_native_accessor(realm, "navigator", navigator_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_accessor(realm, "clientInformation", navigator_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
// NOTE: location is marked as [LegacyUnforgeable], meaning it isn't configurable.
define_native_accessor(realm, "location", location_getter, location_setter, JS::Attribute::Enumerable);
@ -1207,6 +1204,13 @@ static JS::ThrowCompletionOr<HTML::Window*> impl_from(JS::VM& vm)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Window");
}
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
JS::NonnullGCPtr<Navigator> Window::navigator() const
{
// The navigator and clientInformation getter steps are to return this's associated Navigator.
return *m_navigator;
}
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-alert
void Window::alert(String const& message)
{
@ -1912,10 +1916,4 @@ JS_DEFINE_NATIVE_FUNCTION(Window::name_setter)
return JS::js_undefined();
}
JS_DEFINE_NATIVE_FUNCTION(Window::navigator_getter)
{
auto* impl = TRY(impl_from(vm));
return impl->m_navigator;
}
}

View file

@ -140,6 +140,8 @@ public:
Vector<JS::NonnullGCPtr<MimeType>> pdf_viewer_mime_type_objects();
// JS API functions
JS::NonnullGCPtr<Navigator> navigator() const;
void alert(String const& message = {});
bool confirm(Optional<String> const& message);
Optional<String> prompt(Optional<String> const& message, Optional<String> const& default_);
@ -288,8 +290,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(crypto_getter);
JS_DECLARE_NATIVE_FUNCTION(navigator_getter);
HTML::Location* m_location { nullptr };
// [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap

View file

@ -1,9 +1,14 @@
#import <DOM/EventHandler.idl>
#import <DOM/EventTarget.idl>
#import <HTML/Navigator.idl>
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#window
[Global=Window, Exposed=Window, LegacyUnenumerableNamedProperties, UseNewAKString]
interface Window : EventTarget {
// the user agent
readonly attribute Navigator navigator;
[ImplementedAs=navigator] readonly attribute Navigator clientInformation; // legacy alias of .navigator
// user prompts
undefined alert();
undefined alert(DOMString message);