diff options
author | Linus Groh <mail@linusgroh.de> | 2022-03-05 21:31:31 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-03-06 23:27:39 +0100 |
commit | 8b4e5220aa7bf3d527ffef34c79c4c6b335d5733 (patch) | |
tree | f56e028405990423e380aa62675769d25480d2ae /Userland | |
parent | 11d0e37d8ee30cea11a8579ecf26de8df80bd41d (diff) | |
download | serenity-8b4e5220aa7bf3d527ffef34c79c4c6b335d5733.zip |
LibWeb: Implement the [[CrossOriginPropertyDescriptorMap]] internal slot
Diffstat (limited to 'Userland')
3 files changed, 59 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h new file mode 100644 index 0000000000..945296ae9b --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022, Linus Groh <linusg@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Forward.h> +#include <AK/Traits.h> +#include <LibJS/Forward.h> + +namespace Web::Bindings { + +struct CrossOriginKey { + FlatPtr current_settings_object; + FlatPtr relevant_settings_object; + JS::PropertyKey property_key; +}; + +using CrossOriginPropertyDescriptorMap = HashMap<CrossOriginKey, JS::PropertyDescriptor>; + +} + +namespace AK { + +template<> +struct Traits<Web::Bindings::CrossOriginKey> : public GenericTraits<Web::Bindings::CrossOriginKey> { + static unsigned hash(Web::Bindings::CrossOriginKey const& key) + { + return pair_int_hash( + Traits<JS::PropertyKey>::hash(key.property_key), + pair_int_hash(ptr_hash(key.current_settings_object), ptr_hash(key.relevant_settings_object))); + } + + static bool equals(Web::Bindings::CrossOriginKey const& a, Web::Bindings::CrossOriginKey const& b) + { + return a.current_settings_object == b.current_settings_object + && a.relevant_settings_object == b.relevant_settings_object + && Traits<JS::PropertyKey>::equals(a.property_key, b.property_key); + } +}; + +} diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.h b/Userland/Libraries/LibWeb/Bindings/LocationObject.h index 18a16e1a8d..6a03eada20 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.h +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.h @@ -10,6 +10,7 @@ #include <AK/URL.h> #include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Object.h> +#include <LibWeb/Bindings/CrossOriginAbstractOperations.h> #include <LibWeb/Forward.h> namespace Web { @@ -30,6 +31,9 @@ public: // FIXME: There should also be a custom [[GetPrototypeOf]], [[GetOwnProperty]], [[DefineOwnProperty]], [[Get]], [[Set]], [[Delete]] and [[OwnPropertyKeys]], // but we don't have the infrastructure in place to implement them yet. + CrossOriginPropertyDescriptorMap const& cross_origin_property_descriptor_map() const { return m_cross_origin_property_descriptor_map; } + CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; } + private: DOM::Document const* relevant_document() const; AK::URL url() const; @@ -47,6 +51,9 @@ private: JS_DECLARE_NATIVE_FUNCTION(search_getter); JS_DECLARE_NATIVE_FUNCTION(protocol_getter); JS_DECLARE_NATIVE_FUNCTION(port_getter); + + // [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap + CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map; }; } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.h b/Userland/Libraries/LibWeb/Bindings/WindowObject.h index 3488803e04..8efc18177e 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -13,6 +14,7 @@ #include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/GlobalObject.h> #include <LibWeb/Bindings/CallbackType.h> +#include <LibWeb/Bindings/CrossOriginAbstractOperations.h> #include <LibWeb/Forward.h> #include <LibWeb/HTML/GlobalEventHandlers.h> @@ -68,6 +70,9 @@ public: virtual JS::ThrowCompletionOr<bool> internal_set_prototype_of(JS::Object* prototype) override; + CrossOriginPropertyDescriptorMap const& cross_origin_property_descriptor_map() const { return m_cross_origin_property_descriptor_map; } + CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; } + private: virtual void visit_edges(Visitor&) override; @@ -136,6 +141,9 @@ private: HashMap<String, JS::Object*> m_prototypes; HashMap<String, JS::NativeFunction*> m_constructors; + + // [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap + CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map; }; } |