1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:27:34 +00:00

LibWeb: Add origin property to window object

This commit is contained in:
Alex M 2022-02-28 09:50:11 -04:00 committed by Linus Groh
parent 39f92fa131
commit f0f2009170
3 changed files with 35 additions and 0 deletions

View file

@ -115,6 +115,7 @@ void WindowObject::initialize_global_object()
define_direct_property("CSS", heap().allocate<CSSNamespace>(*this, *this), 0);
define_native_accessor("localStorage", local_storage_getter, {}, attr);
define_native_accessor("origin", origin_getter, {}, attr);
// Legacy
define_native_accessor("event", event_getter, event_setter, JS::Attribute::Enumerable);
@ -651,6 +652,13 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::post_message)
return JS::js_undefined();
}
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-origin
JS_DEFINE_NATIVE_FUNCTION(WindowObject::origin_getter)
{
auto* impl = TRY(impl_from(vm, global_object));
return JS::js_string(vm, impl->associated_document().origin().serialize());
}
JS_DEFINE_NATIVE_FUNCTION(WindowObject::local_storage_getter)
{
auto* impl = TRY(impl_from(vm, global_object));