diff options
author | Linus Groh <mail@linusgroh.de> | 2022-03-05 22:47:56 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-03-06 23:27:39 +0100 |
commit | 245ec9981345b3eb546899188a87922ade2f89f3 (patch) | |
tree | 244c9176dda292071d92fee8648a63f509a48cab | |
parent | c7b977547d194cde0b12a80cc90ebb62c598aa3c (diff) | |
download | serenity-245ec9981345b3eb546899188a87922ade2f89f3.zip |
LibWeb: Implement the CrossOriginGet AO
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp index ec855525e6..1a7de336e1 100644 --- a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.cpp @@ -166,4 +166,33 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<Lo return {}; } +// 7.2.3.5 CrossOriginGet ( O, P, Receiver ), https://html.spec.whatwg.org/multipage/browsers.html#crossoriginget-(-o,-p,-receiver-) +JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::GlobalObject& global_object, JS::Object const& object, JS::PropertyKey const& property_key, JS::Value receiver) +{ + auto& vm = global_object.vm(); + + // 1. Let desc be ? O.[[GetOwnProperty]](P). + auto descriptor = TRY(object.internal_get_own_property(property_key)); + + // 2. Assert: desc is not undefined. + VERIFY(descriptor.has_value()); + + // 3. If IsDataDescriptor(desc) is true, then return desc.[[Value]]. + if (descriptor->is_data_descriptor()) + return descriptor->value; + + // 4. Assert: IsAccessorDescriptor(desc) is true. + VERIFY(descriptor->is_accessor_descriptor()); + + // 5. Let getter be desc.[[Get]]. + auto& getter = descriptor->get; + + // 6. If getter is undefined, then throw a "SecurityError" DOMException. + if (!getter.has_value()) + return vm.throw_completion<DOMExceptionWrapper>(global_object, DOM::SecurityError::create(String::formatted("Can't get property '{}' on cross-origin object", property_key))); + + // 7. Return ? Call(getter, Receiver). + return JS::call(global_object, *getter, receiver); +} + } diff --git a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h index 79a6b2f2bd..c92d114a3d 100644 --- a/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h +++ b/Userland/Libraries/LibWeb/Bindings/CrossOriginAbstractOperations.h @@ -31,6 +31,8 @@ Vector<CrossOriginProperty> cross_origin_properties(Variant<LocationObject const JS::ThrowCompletionOr<JS::PropertyDescriptor> cross_origin_property_fallback(JS::GlobalObject&, JS::PropertyKey const&); bool is_platform_object_same_origin(JS::Object const&); Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<LocationObject*, WindowObject*> const&, JS::PropertyKey const&); +JS::ThrowCompletionOr<JS::Value> cross_origin_get(JS::GlobalObject&, JS::Object const&, JS::PropertyKey const&, JS::Value receiver); +JS::ThrowCompletionOr<bool> cross_origin_set(JS::GlobalObject&, JS::Object&, JS::PropertyKey const&, JS::Value, JS::Value receiver); } |