1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 19:07:35 +00:00

LibWeb: Basic support for location.replace(url)

This is not entirely to spec, but gets the basic job done.
This commit is contained in:
Andreas Kling 2021-10-03 23:31:52 +02:00
parent 37784a85c0
commit 573955be7f
4 changed files with 23 additions and 0 deletions

View file

@ -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)
{

View file

@ -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);