summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-10-03 23:31:52 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-03 23:36:56 +0200
commit573955be7f4b236c2725855aa96b2d24477415ed (patch)
treee58981a5b4096644745ed17a3bcc2d52cbceb6d8
parent37784a85c0e71c4728899240a081440adb49bc00 (diff)
downloadserenity-573955be7f4b236c2725855aa96b2d24477415ed.zip
LibWeb: Basic support for location.replace(url)
This is not entirely to spec, but gets the basic job done.
-rw-r--r--Userland/Libraries/LibWeb/Bindings/LocationObject.cpp12
-rw-r--r--Userland/Libraries/LibWeb/Bindings/LocationObject.h1
-rw-r--r--Userland/Libraries/LibWeb/DOM/Window.cpp9
-rw-r--r--Userland/Libraries/LibWeb/DOM/Window.h1
4 files changed, 23 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
index a5946d2d90..e9160e2296 100644
--- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp
@@ -33,6 +33,7 @@ void LocationObject::initialize(JS::GlobalObject& global_object)
define_native_accessor("port", port_getter, {}, attr);
define_native_function("reload", reload, 0, JS::Attribute::Enumerable);
+ define_native_function("replace", replace, 1, JS::Attribute::Enumerable);
}
LocationObject::~LocationObject()
@@ -125,6 +126,17 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
return JS::js_undefined();
}
+JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace)
+{
+ auto& window = static_cast<WindowObject&>(global_object);
+ auto url = vm.argument(0).to_string(global_object);
+ if (vm.exception())
+ return {};
+ // FIXME: This needs spec compliance work.
+ window.impl().did_call_location_replace({}, move(url));
+ return JS::js_undefined();
+}
+
// https://html.spec.whatwg.org/multipage/history.html#location-setprototypeof
JS::ThrowCompletionOr<bool> LocationObject::internal_set_prototype_of(Object* prototype)
{
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.h b/Userland/Libraries/LibWeb/Bindings/LocationObject.h
index 7062c4ae25..e89d82b22e 100644
--- a/Userland/Libraries/LibWeb/Bindings/LocationObject.h
+++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.h
@@ -30,6 +30,7 @@ public:
private:
JS_DECLARE_NATIVE_FUNCTION(reload);
+ JS_DECLARE_NATIVE_FUNCTION(replace);
JS_DECLARE_NATIVE_FUNCTION(href_getter);
JS_DECLARE_NATIVE_FUNCTION(href_setter);
diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp
index aa02decf67..79960998cf 100644
--- a/Userland/Libraries/LibWeb/DOM/Window.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Window.cpp
@@ -234,6 +234,15 @@ void Window::did_call_location_reload(Badge<Bindings::LocationObject>)
frame->loader().load(associated_document().url(), FrameLoader::Type::Reload);
}
+void Window::did_call_location_replace(Badge<Bindings::LocationObject>, String url)
+{
+ auto* frame = associated_document().browsing_context();
+ if (!frame)
+ return;
+ auto new_url = associated_document().parse_url(url);
+ frame->loader().load(move(new_url), FrameLoader::Type::Navigation);
+}
+
bool Window::dispatch_event(NonnullRefPtr<Event> event)
{
return EventDispatcher::dispatch(*this, event, true);
diff --git a/Userland/Libraries/LibWeb/DOM/Window.h b/Userland/Libraries/LibWeb/DOM/Window.h
index 563afc4ed1..3ee7d723c4 100644
--- a/Userland/Libraries/LibWeb/DOM/Window.h
+++ b/Userland/Libraries/LibWeb/DOM/Window.h
@@ -62,6 +62,7 @@ public:
void did_set_location_href(Badge<Bindings::LocationObject>, AK::URL const& new_href);
void did_call_location_reload(Badge<Bindings::LocationObject>);
+ void did_call_location_replace(Badge<Bindings::LocationObject>, String url);
Bindings::WindowObject* wrapper() { return m_wrapper; }
Bindings::WindowObject const* wrapper() const { return m_wrapper; }