From a05c998e69b2b7e524c70b34c9b5c44c48ef64ea Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 12 Sep 2021 11:32:14 +0100 Subject: LibWeb: Add A JS setter macro for [Replaceable] IDL properties The [Replaceable] attribute "indicates that setting the corresponding property on the platform object will result in an own property with the same name being created on the object which has the value being assigned. This property will shadow the accessor property corresponding to the attribute, which exists on the interface prototype object." (https://heycam.github.io/webidl/#Replaceable) The spec doesn't tell how exactly this is supposed to be done, but other engines just have a setter as well that just redefines the property as a data descriptor when called, and returns undefined. It's bound to the property name and requires an object of the correct type, so I mirrored these constraints here. Storing the setter and calling it multiple times will therefore just work. Implementing this in the wrapper generator is left as an exercise for the reader, this is going to be used in WindowObject, which isn't generated from IDL yet. --- Userland/Libraries/LibWeb/Bindings/Replaceable.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Userland/Libraries/LibWeb/Bindings/Replaceable.h (limited to 'Userland') diff --git a/Userland/Libraries/LibWeb/Bindings/Replaceable.h b/Userland/Libraries/LibWeb/Bindings/Replaceable.h new file mode 100644 index 0000000000..6617922fe9 --- /dev/null +++ b/Userland/Libraries/LibWeb/Bindings/Replaceable.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2021, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#define REPLACEABLE_PROPERTY_SETTER(ObjectType, property) \ + auto this_value = vm.this_value(global_object); \ + if (!this_value.is_object() || !is(this_value.as_object())) { \ + vm.throw_exception(global_object, JS::ErrorType::NotAnObjectOfType, #ObjectType); \ + return {}; \ + } \ + this_value.as_object().internal_define_own_property(#property, JS::PropertyDescriptor { .value = vm.argument(0), .writable = true }); \ + return JS::js_undefined(); -- cgit v1.2.3