LibWeb/HTML: Port Window.open() to IDL
This commit is contained in:
parent
efa48142d2
commit
b2409517bd
Notes:
sideshowbarker
2024-07-17 07:31:31 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/b2409517bd Pull-request: https://github.com/SerenityOS/serenity/pull/17752 Reviewed-by: https://github.com/awesomekling
3 changed files with 9 additions and 24 deletions
|
@ -1057,7 +1057,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
|
|||
define_native_accessor(realm, "innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
|
||||
define_native_accessor(realm, "devicePixelRatio", device_pixel_ratio_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
|
||||
define_native_function(realm, "open", open, 0, attr);
|
||||
define_native_function(realm, "setInterval", set_interval, 1, attr);
|
||||
define_native_function(realm, "setTimeout", set_timeout, 1, attr);
|
||||
define_native_function(realm, "clearInterval", clear_interval, 1, attr);
|
||||
|
@ -1280,6 +1279,13 @@ JS::GCPtr<DOM::Element const> Window::frame_element() const
|
|||
return container;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-open
|
||||
WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> Window::open(Optional<String> const& url, Optional<String> const& target, Optional<String> const& features)
|
||||
{
|
||||
// The open(url, target, features) method steps are to run the window open steps with url, target, and features.
|
||||
return open_impl(*url, *target, *features);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator
|
||||
JS::NonnullGCPtr<Navigator> Window::navigator() const
|
||||
{
|
||||
|
@ -1335,28 +1341,6 @@ void Window::post_message(JS::Value message, String const&)
|
|||
});
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::open)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
|
||||
// optional USVString url = ""
|
||||
DeprecatedString url = "";
|
||||
if (!vm.argument(0).is_undefined())
|
||||
url = TRY(vm.argument(0).to_deprecated_string(vm));
|
||||
|
||||
// optional DOMString target = "_blank"
|
||||
DeprecatedString target = "_blank";
|
||||
if (!vm.argument(1).is_undefined())
|
||||
target = TRY(vm.argument(1).to_deprecated_string(vm));
|
||||
|
||||
// optional [LegacyNullToEmptyString] DOMString features = "")
|
||||
DeprecatedString features = "";
|
||||
if (!vm.argument(2).is_nullish())
|
||||
features = TRY(vm.argument(2).to_deprecated_string(vm));
|
||||
|
||||
return TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { return impl->open_impl(url, target, features); }));
|
||||
}
|
||||
|
||||
static JS::ThrowCompletionOr<TimerHandler> make_timer_handler(JS::VM& vm, JS::Value handler)
|
||||
{
|
||||
if (handler.is_function())
|
||||
|
|
|
@ -147,6 +147,7 @@ public:
|
|||
JS::GCPtr<WindowProxy const> top() const;
|
||||
JS::GCPtr<WindowProxy const> parent() const;
|
||||
JS::GCPtr<DOM::Element const> frame_element() const;
|
||||
WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> open(Optional<String> const& url, Optional<String> const& target, Optional<String> const& features);
|
||||
|
||||
JS::NonnullGCPtr<Navigator> navigator() const;
|
||||
|
||||
|
@ -254,7 +255,6 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(origin_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(is_secure_context_getter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(open);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_interval);
|
||||
JS_DECLARE_NATIVE_FUNCTION(set_timeout);
|
||||
JS_DECLARE_NATIVE_FUNCTION(clear_interval);
|
||||
|
|
|
@ -20,6 +20,7 @@ interface Window : EventTarget {
|
|||
[LegacyUnforgeable] readonly attribute WindowProxy? top;
|
||||
[Replaceable] readonly attribute WindowProxy? parent;
|
||||
readonly attribute Element? frameElement;
|
||||
WindowProxy? open(optional USVString url = "", optional DOMString target = "_blank", optional [LegacyNullToEmptyString] DOMString features = "");
|
||||
|
||||
// the user agent
|
||||
readonly attribute Navigator navigator;
|
||||
|
|
Loading…
Add table
Reference in a new issue