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();