mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 14:45:07 +00:00

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.
16 lines
1.1 KiB
C
16 lines
1.1 KiB
C
/*
|
|
* 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();
|