LibWeb: Define window.isSecureContext

This commit is contained in:
Cameron Youell 2023-01-18 20:50:03 +11:00 committed by Linus Groh
parent f7fe9e3355
commit 204257526c
Notes: sideshowbarker 2024-07-17 01:34:17 +09:00
2 changed files with 10 additions and 0 deletions

View File

@ -1137,6 +1137,7 @@ void Window::initialize_web_interfaces(Badge<WindowEnvironmentSettingsObject>)
define_native_accessor(realm, "localStorage", local_storage_getter, {}, attr);
define_native_accessor(realm, "sessionStorage", session_storage_getter, {}, attr);
define_native_accessor(realm, "origin", origin_getter, {}, attr);
define_native_accessor(realm, "isSecureContext", is_secure_context_getter, {}, attr);
// Legacy
define_native_accessor(realm, "event", event_getter, event_setter, JS::Attribute::Enumerable);
@ -1863,6 +1864,14 @@ JS_DEFINE_NATIVE_FUNCTION(Window::origin_getter)
return JS::PrimitiveString::create(vm, impl->associated_document().origin().serialize());
}
// https://html.spec.whatwg.org/multipage/webappapis.html#dom-issecurecontext
JS_DEFINE_NATIVE_FUNCTION(Window::is_secure_context_getter)
{
auto* impl = TRY(impl_from(vm));
// The isSecureContext getter steps are to return true if this's relevant settings object is a secure context, or false otherwise.
return JS::Value(is_secure_context(impl->associated_document().relevant_settings_object()));
}
JS_DEFINE_NATIVE_FUNCTION(Window::local_storage_getter)
{
auto* impl = TRY(impl_from(vm));

View File

@ -247,6 +247,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(local_storage_getter);
JS_DECLARE_NATIVE_FUNCTION(session_storage_getter);
JS_DECLARE_NATIVE_FUNCTION(origin_getter);
JS_DECLARE_NATIVE_FUNCTION(is_secure_context_getter);
JS_DECLARE_NATIVE_FUNCTION(open);
JS_DECLARE_NATIVE_FUNCTION(alert);