LibWeb/HTML: Port Window.name to IDL

This commit is contained in:
Linus Groh 2023-03-05 19:02:16 +00:00
parent 0e587420a8
commit 0e40841990
Notes: sideshowbarker 2024-07-17 01:46:43 +09:00
3 changed files with 25 additions and 40 deletions

View file

@ -895,26 +895,6 @@ WebIDL::ExceptionOr<JS::Value> Window::structured_clone_impl(JS::VM& vm, JS::Val
return MUST(structured_deserialize(vm, serialized, *vm.current_realm(), {}));
}
// https://html.spec.whatwg.org/multipage/window-object.html#dom-name
DeprecatedString Window::name() const
{
// 1. If this's browsing context is null, then return the empty string.
if (!browsing_context())
return DeprecatedString::empty();
// 2. Return this's browsing context's name.
return browsing_context()->name();
}
// https://html.spec.whatwg.org/multipage/window-object.html#dom-name
void Window::set_name(DeprecatedString const& name)
{
// 1. If this's browsing context is null, then return.
if (!browsing_context())
return;
// 2. Set this's browsing context's name to the given value.
browsing_context()->set_name(name);
}
// https://html.spec.whatwg.org/multipage/interaction.html#transient-activation
bool Window::has_transient_activation() const
{
@ -1094,7 +1074,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
define_native_accessor(realm, "top", top_getter, nullptr, JS::Attribute::Enumerable);
define_native_accessor(realm, "parent", parent_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "name", name_getter, name_setter, JS::Attribute::Enumerable);
define_native_accessor(realm, "history", history_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "performance", performance_getter, performance_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_accessor(realm, "crypto", crypto_getter, {}, JS::Attribute::Enumerable);
@ -1221,6 +1200,28 @@ JS::NonnullGCPtr<DOM::Document const> Window::document() const
return associated_document();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-name
String Window::name() const
{
// 1. If this's navigable is null, then return the empty string.
if (!browsing_context())
return String {};
// 2. Return this's navigable's target name.
return String::from_deprecated_string(browsing_context()->name()).release_value_but_fixme_should_propagate_errors();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#apis-for-creating-and-navigating-browsing-contexts-by-name:dom-name
void Window::set_name(String const& name)
{
// 1. If this's navigable is null, then return.
if (!browsing_context())
return;
// 2. Set this's navigable's active session history entry's document state's navigable target name to the given value.
browsing_context()->set_name(name.to_deprecated_string());
}
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
JS::NonnullGCPtr<WindowProxy> Window::frames() const
{
@ -1897,17 +1898,4 @@ JS_DEFINE_NATIVE_FUNCTION(Window::session_storage_getter)
return impl->session_storage();
}
JS_DEFINE_NATIVE_FUNCTION(Window::name_getter)
{
auto* impl = TRY(impl_from(vm));
return JS::PrimitiveString::create(vm, impl->name());
}
JS_DEFINE_NATIVE_FUNCTION(Window::name_setter)
{
auto* impl = TRY(impl_from(vm));
impl->set_name(TRY(vm.argument(0).to_deprecated_string(vm)));
return JS::js_undefined();
}
}

View file

@ -121,9 +121,6 @@ public:
WebIDL::ExceptionOr<JS::Value> structured_clone_impl(JS::VM& vm, JS::Value);
DeprecatedString name() const;
void set_name(DeprecatedString const&);
void start_an_idle_period();
u32 request_idle_callback_impl(WebIDL::CallbackType& callback);
@ -143,6 +140,8 @@ public:
JS::NonnullGCPtr<WindowProxy> window() const;
JS::NonnullGCPtr<WindowProxy> self() const;
JS::NonnullGCPtr<DOM::Document const> document() const;
String name() const;
void set_name(String const&);
JS::NonnullGCPtr<WindowProxy> frames() const;
@ -227,9 +226,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(location_getter);
JS_DECLARE_NATIVE_FUNCTION(location_setter);
JS_DECLARE_NATIVE_FUNCTION(name_getter);
JS_DECLARE_NATIVE_FUNCTION(name_setter);
JS_DECLARE_NATIVE_FUNCTION(performance_getter);
JS_DECLARE_NATIVE_FUNCTION(performance_setter);

View file

@ -10,6 +10,7 @@ interface Window : EventTarget {
[LegacyUnforgeable] readonly attribute WindowProxy window;
[Replaceable] readonly attribute WindowProxy self;
[LegacyUnforgeable] readonly attribute Document document;
attribute DOMString name;
// other browsing contexts
[Replaceable] readonly attribute WindowProxy frames;