mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:47:45 +00:00
LibWeb: Use cached_web_prototype() as much as possible
Unlike ensure_web_prototype<T>(), the cached version doesn't require the prototype type to be fully formed, so we can use it without including the FooPrototype.h header. It's also a bit less verbose. :^)
This commit is contained in:
parent
a85542958c
commit
ffad902c07
165 changed files with 176 additions and 325 deletions
|
@ -24,7 +24,7 @@ void AudioConstructor::initialize(JS::Realm& realm)
|
|||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
NativeFunction::initialize(realm);
|
||||
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLAudioElementPrototype>("HTMLAudioElement"), 0);
|
||||
define_direct_property(vm.names.prototype, &window.cached_web_prototype("HTMLAudioElement"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ void ImageConstructor::initialize(JS::Realm& realm)
|
|||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
NativeFunction::initialize(realm);
|
||||
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLImageElementPrototype>("HTMLImageElement"), 0);
|
||||
define_direct_property(vm.names.prototype, &window.cached_web_prototype("HTMLImageElement"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ void LocationConstructor::initialize(JS::Realm& realm)
|
|||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
|
||||
NativeFunction::initialize(realm);
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<LocationPrototype>("Location"), 0);
|
||||
define_direct_property(vm.names.prototype, &window.cached_web_prototype("Location"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Web::Bindings {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/history.html#the-location-interface
|
||||
LocationObject::LocationObject(JS::Realm& realm)
|
||||
: Object(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<LocationPrototype>("Location"))
|
||||
: Object(verify_cast<HTML::Window>(realm.global_object()).cached_web_prototype("Location"))
|
||||
, m_default_properties(heap())
|
||||
{
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ void NavigatorConstructor::initialize(JS::Realm& realm)
|
|||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
|
||||
NativeFunction::initialize(realm);
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<NavigatorPrototype>("Navigator"), 0);
|
||||
define_direct_property(vm.names.prototype, &window.cached_web_prototype("Navigator"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Web {
|
|||
namespace Bindings {
|
||||
|
||||
NavigatorObject::NavigatorObject(JS::Realm& realm)
|
||||
: Object(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<NavigatorPrototype>("Navigator"))
|
||||
: Object(verify_cast<HTML::Window>(realm.global_object()).cached_web_prototype("Navigator"))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ void OptionConstructor::initialize(JS::Realm& realm)
|
|||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
NativeFunction::initialize(realm);
|
||||
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLOptionElementPrototype>("HTMLOptionElement"), 0);
|
||||
define_direct_property(vm.names.prototype, &window.cached_web_prototype("HTMLOptionElement"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ void WindowConstructor::initialize(JS::Realm& realm)
|
|||
auto& window = verify_cast<HTML::Window>(realm.global_object());
|
||||
|
||||
NativeFunction::initialize(realm);
|
||||
define_direct_property(vm.names.prototype, &window.ensure_web_prototype<WindowPrototype>("Window"), 0);
|
||||
define_direct_property(vm.names.prototype, &window.cached_web_prototype("Window"), 0);
|
||||
define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable);
|
||||
}
|
||||
|
||||
|
|
|
@ -388,10 +388,10 @@
|
|||
|
||||
#define ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(interface_name, constructor_name, prototype_name) \
|
||||
{ \
|
||||
auto& constructor = ensure_web_constructor<Bindings::constructor_name>(#interface_name); \
|
||||
constructor.define_direct_property(vm.names.name, js_string(vm, #interface_name), JS::Attribute::Configurable); \
|
||||
auto& prototype = ensure_web_prototype<Bindings::prototype_name>(#interface_name); \
|
||||
auto& constructor = ensure_web_constructor<Bindings::constructor_name>(#interface_name); \
|
||||
prototype.define_direct_property(vm.names.constructor, &constructor, JS::Attribute::Writable | JS::Attribute::Configurable); \
|
||||
constructor.define_direct_property(vm.names.name, js_string(vm, #interface_name), JS::Attribute::Configurable); \
|
||||
}
|
||||
|
||||
#define ADD_WINDOW_OBJECT_INTERFACE(interface_name) \
|
||||
|
|
|
@ -20,7 +20,7 @@ class WindowPrototype final : public JS::Object {
|
|||
|
||||
public:
|
||||
explicit WindowPrototype(JS::Realm& realm)
|
||||
: JS::Object(verify_cast<HTML::Window>(realm.global_object()).ensure_web_prototype<EventTargetPrototype>("EventTarget"))
|
||||
: JS::Object(verify_cast<HTML::Window>(realm.global_object()).cached_web_prototype("EventTarget"))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue