mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
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.
This commit is contained in:
parent
c5bd382524
commit
a05c998e69
1 changed files with 16 additions and 0 deletions
16
Userland/Libraries/LibWeb/Bindings/Replaceable.h
Normal file
16
Userland/Libraries/LibWeb/Bindings/Replaceable.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* 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<ObjectType>(this_value.as_object())) { \
|
||||
vm.throw_exception<JS::TypeError>(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();
|
Loading…
Add table
Add a link
Reference in a new issue