LibWeb: Set Constructor.name and Prototype.constructor of generated interfaces

Object introspection in the Browser's JS console is still not great, but
this makes it a lot easier to find out the exact type of an object by
checking its 'constructor' property.
It also fixes all the things that rely on these properties being set, of
course :^)
This commit is contained in:
Linus Groh 2021-04-03 15:06:16 +02:00 committed by Andreas Kling
commit 975b209b9b
Notes: sideshowbarker 2024-07-18 20:52:04 +09:00

View file

@ -234,12 +234,19 @@
#include <LibWeb/Bindings/XMLHttpRequestEventTargetPrototype.h>
#include <LibWeb/Bindings/XMLHttpRequestPrototype.h>
#define ADD_WINDOW_OBJECT_INTERFACE(name) \
#define ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(interface_name, constructor_name, prototype_name) \
{ \
ensure_web_constructor<name##Constructor>(#name); \
auto& constructor = ensure_web_constructor<constructor_name>(#interface_name); \
constructor.define_property(vm.names.name, js_string(vm, #interface_name), JS::Attribute::Configurable); \
auto& prototype = ensure_web_prototype<prototype_name>(#interface_name); \
prototype.define_property(vm.names.constructor, &constructor, JS::Attribute::Writable | JS::Attribute::Configurable); \
}
#define ADD_WINDOW_OBJECT_INTERFACE(interface_name) \
ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(interface_name, interface_name##Constructor, interface_name##Prototype)
#define ADD_WINDOW_OBJECT_INTERFACES \
auto& vm = this->vm(); \
ADD_WINDOW_OBJECT_INTERFACE(CanvasRenderingContext2D) \
ADD_WINDOW_OBJECT_INTERFACE(CharacterData) \
ADD_WINDOW_OBJECT_INTERFACE(Comment) \
@ -323,7 +330,6 @@
ADD_WINDOW_OBJECT_INTERFACE(HTMLUListElement) \
ADD_WINDOW_OBJECT_INTERFACE(HTMLUnknownElement) \
ADD_WINDOW_OBJECT_INTERFACE(HTMLVideoElement) \
ADD_WINDOW_OBJECT_INTERFACE(Image) \
ADD_WINDOW_OBJECT_INTERFACE(ImageData) \
ADD_WINDOW_OBJECT_INTERFACE(MouseEvent) \
ADD_WINDOW_OBJECT_INTERFACE(Node) \
@ -342,4 +348,5 @@
ADD_WINDOW_OBJECT_INTERFACE(Text) \
ADD_WINDOW_OBJECT_INTERFACE(UIEvent) \
ADD_WINDOW_OBJECT_INTERFACE(XMLHttpRequest) \
ADD_WINDOW_OBJECT_INTERFACE(XMLHttpRequestEventTarget)
ADD_WINDOW_OBJECT_INTERFACE(XMLHttpRequestEventTarget) \
ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(Image, ImageConstructor, HTMLImageElementPrototype)