1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:48:12 +00:00

LibWeb: Remove no-op impl() methods from the WEB_PLATFORM_OBJECT macro

These are leftovers from when wrapper objects still had an internal
implementation, which is no longer the case.
This commit is contained in:
Linus Groh 2022-09-21 17:45:18 +01:00
parent 2cab2a8e8f
commit 6055b0e850
14 changed files with 28 additions and 39 deletions

View file

@ -337,7 +337,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!@js_name@@js_suffix@.is_object() || !is<@parameter.type.name@>(@js_name@@js_suffix@.as_object())) if (!@js_name@@js_suffix@.is_object() || !is<@parameter.type.name@>(@js_name@@js_suffix@.as_object()))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
auto& @cpp_name@ = static_cast<@parameter.type.name@&>(@js_name@@js_suffix@.as_object()).impl(); auto& @cpp_name@ = static_cast<@parameter.type.name@&>(@js_name@@js_suffix@.as_object());
)~~~"); )~~~");
} else { } else {
scoped_generator.append(R"~~~( scoped_generator.append(R"~~~(
@ -346,7 +346,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!@js_name@@js_suffix@.is_object() || !is<@parameter.type.name@>(@js_name@@js_suffix@.as_object())) if (!@js_name@@js_suffix@.is_object() || !is<@parameter.type.name@>(@js_name@@js_suffix@.as_object()))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
@cpp_name@ = static_cast<@parameter.type.name@&>(@js_name@@js_suffix@.as_object()).impl(); @cpp_name@ = static_cast<@parameter.type.name@&>(@js_name@@js_suffix@.as_object());
} }
)~~~"); )~~~");
} }
@ -357,7 +357,7 @@ static void generate_to_cpp(SourceGenerator& generator, ParameterType& parameter
if (!@js_name@@js_suffix@.is_object() || !is<@parameter.type.name@>(@js_name@@js_suffix@.as_object())) if (!@js_name@@js_suffix@.is_object() || !is<@parameter.type.name@>(@js_name@@js_suffix@.as_object()))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@parameter.type.name@");
@cpp_name@ = &static_cast<@parameter.type.name@&>(@js_name@@js_suffix@.as_object()).impl(); @cpp_name@ = &static_cast<@parameter.type.name@&>(@js_name@@js_suffix@.as_object());
} }
)~~~"); )~~~");
} }
@ -2567,7 +2567,7 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm)
if (interface.name == "EventTarget") { if (interface.name == "EventTarget") {
generator.append(R"~~~( generator.append(R"~~~(
if (is<HTML::Window>(this_object)) { if (is<HTML::Window>(this_object)) {
return &static_cast<HTML::Window*>(this_object)->impl(); return static_cast<HTML::Window*>(this_object);
} }
)~~~"); )~~~");
} }
@ -2576,7 +2576,7 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm)
if (!is<@fully_qualified_name@>(this_object)) if (!is<@fully_qualified_name@>(this_object))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@fully_qualified_name@"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@fully_qualified_name@");
return &static_cast<@fully_qualified_name@*>(this_object)->impl(); return static_cast<@fully_qualified_name@*>(this_object);
} }
)~~~"); )~~~");
} }
@ -2869,7 +2869,7 @@ static JS::ThrowCompletionOr<@fully_qualified_name@*> impl_from(JS::VM& vm)
auto* this_object = TRY(vm.this_value().to_object(vm)); auto* this_object = TRY(vm.this_value().to_object(vm));
if (!is<@fully_qualified_name@>(this_object)) if (!is<@fully_qualified_name@>(this_object))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@fully_qualified_name@"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "@fully_qualified_name@");
return &static_cast<@fully_qualified_name@*>(this_object)->impl(); return static_cast<@fully_qualified_name@*>(this_object);
} }
JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::next) JS_DEFINE_NATIVE_FUNCTION(@prototype_class@::next)

View file

@ -40,7 +40,7 @@ JS::ThrowCompletionOr<JS::Object*> AudioConstructor::construct(FunctionObject&)
// 1. Let document be the current global object's associated Document. // 1. Let document be the current global object's associated Document.
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
auto& document = window.impl().associated_document(); auto& document = window.associated_document();
// 2. Let audio be the result of creating an element given document, audio, and the HTML namespace. // 2. Let audio be the result of creating an element given document, audio, and the HTML namespace.
auto audio = DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML); auto audio = DOM::create_element(document, HTML::TagNames::audio, Namespace::HTML);

View file

@ -108,12 +108,12 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter)
// 2. Parse the given value relative to the entry settings object. If that failed, throw a TypeError exception. // 2. Parse the given value relative to the entry settings object. If that failed, throw a TypeError exception.
auto new_href = TRY(vm.argument(0).to_string(vm)); auto new_href = TRY(vm.argument(0).to_string(vm));
auto href_url = window.impl().associated_document().parse_url(new_href); auto href_url = window.associated_document().parse_url(new_href);
if (!href_url.is_valid()) if (!href_url.is_valid())
return vm.throw_completion<JS::URIError>(String::formatted("Invalid URL '{}'", new_href)); return vm.throw_completion<JS::URIError>(String::formatted("Invalid URL '{}'", new_href));
// 3. Location-object navigate given the resulting URL record. // 3. Location-object navigate given the resulting URL record.
window.impl().did_set_location_href({}, href_url); window.did_set_location_href({}, href_url);
return JS::js_undefined(); return JS::js_undefined();
} }
@ -226,7 +226,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::port_getter)
JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload) JS_DEFINE_NATIVE_FUNCTION(LocationObject::reload)
{ {
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
window.impl().did_call_location_reload({}); window.did_call_location_reload({});
return JS::js_undefined(); return JS::js_undefined();
} }
@ -236,7 +236,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::replace)
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
auto url = TRY(vm.argument(0).to_string(vm)); auto url = TRY(vm.argument(0).to_string(vm));
// FIXME: This needs spec compliance work. // FIXME: This needs spec compliance work.
window.impl().did_call_location_replace({}, move(url)); window.did_call_location_replace({}, move(url));
return JS::js_undefined(); return JS::js_undefined();
} }

View file

@ -14,15 +14,7 @@
namespace Web::Bindings { namespace Web::Bindings {
#define WEB_PLATFORM_OBJECT(class_, base_class) \ #define WEB_PLATFORM_OBJECT(class_, base_class) \
JS_OBJECT(class_, base_class) \ JS_OBJECT(class_, base_class)
auto& impl() \
{ \
return *this; \
} \
auto const& impl() const \
{ \
return *this; \
}
#define WRAPPER_HACK(class_, namespace_) \ #define WRAPPER_HACK(class_, namespace_) \
namespace Web::Bindings { \ namespace Web::Bindings { \

View file

@ -151,7 +151,7 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const
// 1. Let W be the value of the [[Window]] internal slot of this. // 1. Let W be the value of the [[Window]] internal slot of this.
// 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object. // 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object.
HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<HTML::Window>(HTML::current_global_object()).impl().browsing_context(), *m_window->browsing_context(), property_key, HTML::current_settings_object()); HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<HTML::Window>(HTML::current_global_object()).browsing_context(), *m_window->browsing_context(), property_key, HTML::current_settings_object());
// 3. If IsPlatformObjectSameOrigin(W) is true, then return ? OrdinaryGet(this, P, Receiver). // 3. If IsPlatformObjectSameOrigin(W) is true, then return ? OrdinaryGet(this, P, Receiver).
// NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method. // NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
@ -171,7 +171,7 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& pro
// 1. Let W be the value of the [[Window]] internal slot of this. // 1. Let W be the value of the [[Window]] internal slot of this.
// 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object. // 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current settings object.
HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<HTML::Window>(HTML::current_global_object()).browsing_context(), *m_window->impl().browsing_context(), property_key, HTML::current_settings_object()); HTML::check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<HTML::Window>(HTML::current_global_object()).browsing_context(), *m_window->browsing_context(), property_key, HTML::current_settings_object());
// 3. If IsPlatformObjectSameOrigin(W) is true, then: // 3. If IsPlatformObjectSameOrigin(W) is true, then:
if (is_platform_object_same_origin(*m_window)) { if (is_platform_object_same_origin(*m_window)) {

View file

@ -353,7 +353,7 @@ JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_set(JS::PropertyKey co
auto css_text = TRY(value.to_string(vm())); auto css_text = TRY(value.to_string(vm()));
impl().set_property(property_id, css_text); set_property(property_id, css_text);
return true; return true;
} }

View file

@ -91,15 +91,14 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<JS::Handle<DOM::DOMEvent
// 8. If global is a Window object, then: // 8. If global is a Window object, then:
if (is<HTML::Window>(global)) { if (is<HTML::Window>(global)) {
auto& bindings_window_global = verify_cast<HTML::Window>(global); auto& window = verify_cast<HTML::Window>(global);
auto& window_impl = bindings_window_global.impl();
// 1. Set currentEvent to globals current event. // 1. Set currentEvent to globals current event.
current_event = window_impl.current_event(); current_event = window.current_event();
// 2. If invocationTargetInShadowTree is false, then set globals current event to event. // 2. If invocationTargetInShadowTree is false, then set globals current event to event.
if (!invocation_target_in_shadow_tree) if (!invocation_target_in_shadow_tree)
window_impl.set_current_event(&event); window.set_current_event(&event);
} }
// 9. If listeners passive is true, then set events in passive listener flag. // 9. If listeners passive is true, then set events in passive listener flag.
@ -125,9 +124,8 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<JS::Handle<DOM::DOMEvent
// 12. If global is a Window object, then set globals current event to currentEvent. // 12. If global is a Window object, then set globals current event to currentEvent.
if (is<HTML::Window>(global)) { if (is<HTML::Window>(global)) {
auto& bindings_window_global = verify_cast<HTML::Window>(global); auto& window = verify_cast<HTML::Window>(global);
auto& window_impl = bindings_window_global.impl(); window.set_current_event(current_event);
window_impl.set_current_event(current_event);
} }
// 13. If events stop immediate propagation flag is set, then return found. // 13. If events stop immediate propagation flag is set, then return found.

View file

@ -548,8 +548,7 @@ void EventTarget::activate_event_handler(FlyString const& name, HTML::EventHandl
// The argument must be an object and it must be an Event. // The argument must be an object and it must be an Event.
auto event_wrapper_argument = vm.argument(0); auto event_wrapper_argument = vm.argument(0);
VERIFY(event_wrapper_argument.is_object()); VERIFY(event_wrapper_argument.is_object());
auto& event_wrapper = verify_cast<DOM::Event>(event_wrapper_argument.as_object()); auto& event = verify_cast<DOM::Event>(event_wrapper_argument.as_object());
auto& event = event_wrapper.impl();
TRY(event_target->process_event_handler_for_event(name, event)); TRY(event_target->process_event_handler_for_event(name, event));
return JS::js_undefined(); return JS::js_undefined();

View file

@ -43,7 +43,7 @@ JS::NonnullGCPtr<Range> Range::create(Node& start_container, u32 start_offset, N
JS::NonnullGCPtr<Range> Range::create_with_global_object(HTML::Window& window) JS::NonnullGCPtr<Range> Range::create_with_global_object(HTML::Window& window)
{ {
return Range::create(window.impl()); return Range::create(window);
} }
Range::Range(Document& document) Range::Range(Document& document)

View file

@ -247,7 +247,7 @@ void queue_global_task(HTML::Task::Source source, JS::Object& global_object, Fun
DOM::Document* document { nullptr }; DOM::Document* document { nullptr };
if (is<HTML::Window>(global_object)) { if (is<HTML::Window>(global_object)) {
auto& window_object = verify_cast<HTML::Window>(global_object); auto& window_object = verify_cast<HTML::Window>(global_object);
document = &window_object.impl().associated_document(); document = &window_object.associated_document();
} }
// 3. Queue a task given source, event loop, document, and steps. // 3. Queue a task given source, event loop, document, and steps.

View file

@ -844,7 +844,7 @@ void Window::initialize(JS::Realm& realm)
HTML::Origin Window::origin() const HTML::Origin Window::origin() const
{ {
return impl().associated_document().origin(); return associated_document().origin();
} }
// https://webidl.spec.whatwg.org/#platform-object-setprototypeof // https://webidl.spec.whatwg.org/#platform-object-setprototypeof
@ -870,7 +870,7 @@ static JS::ThrowCompletionOr<HTML::Window*> impl_from(JS::VM& vm)
if (!is<Window>(*this_object)) if (!is<Window>(*this_object))
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Window"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "Window");
return &static_cast<Window*>(this_object)->impl(); return static_cast<Window*>(this_object);
} }
JS_DEFINE_NATIVE_FUNCTION(Window::alert) JS_DEFINE_NATIVE_FUNCTION(Window::alert)

View file

@ -39,7 +39,7 @@ public:
static DOM::ExceptionOr<JS::NonnullGCPtr<Worker>> create(FlyString const& script_url, WorkerOptions const options, DOM::Document& document); static DOM::ExceptionOr<JS::NonnullGCPtr<Worker>> create(FlyString const& script_url, WorkerOptions const options, DOM::Document& document);
static DOM::ExceptionOr<JS::NonnullGCPtr<Worker>> create_with_global_object(HTML::Window& window, FlyString const& script_url, WorkerOptions const options) static DOM::ExceptionOr<JS::NonnullGCPtr<Worker>> create_with_global_object(HTML::Window& window, FlyString const& script_url, WorkerOptions const options)
{ {
return Worker::create(script_url, options, window.impl().associated_document()); return Worker::create(script_url, options, window.associated_document());
} }
DOM::ExceptionOr<void> terminate(); DOM::ExceptionOr<void> terminate();

View file

@ -58,7 +58,7 @@ DOM::ExceptionOr<JS::NonnullGCPtr<WebSocket>> WebSocket::create_with_global_obje
return DOM::SyntaxError::create(window, "Presence of URL fragment is invalid"); return DOM::SyntaxError::create(window, "Presence of URL fragment is invalid");
// 5. If `protocols` is a string, set `protocols` to a sequence consisting of just that string // 5. If `protocols` is a string, set `protocols` to a sequence consisting of just that string
// 6. If any of the values in `protocols` occur more than once or otherwise fail to match the requirements, throw SyntaxError // 6. If any of the values in `protocols` occur more than once or otherwise fail to match the requirements, throw SyntaxError
return JS::NonnullGCPtr(*window.heap().allocate<WebSocket>(window.realm(), window.impl(), url_record)); return JS::NonnullGCPtr(*window.heap().allocate<WebSocket>(window.realm(), window, url_record));
} }
WebSocket::WebSocket(HTML::Window& window, AK::URL& url) WebSocket::WebSocket(HTML::Window& window, AK::URL& url)

View file

@ -100,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalObject::inspected_node_getter)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "ConsoleGlobalObject"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "ConsoleGlobalObject");
auto console_global_object = static_cast<ConsoleGlobalObject*>(this_object); auto console_global_object = static_cast<ConsoleGlobalObject*>(this_object);
auto& window = console_global_object->m_window_object->impl(); auto& window = *console_global_object->m_window_object;
auto* inspected_node = window.associated_document().inspected_node(); auto* inspected_node = window.associated_document().inspected_node();
if (!inspected_node) if (!inspected_node)
return JS::js_undefined(); return JS::js_undefined();