1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:57:35 +00:00

LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr

This commit is contained in:
Matthew Olsson 2023-02-26 16:09:02 -07:00 committed by Andreas Kling
parent 1df3652e27
commit 7c0c1c8f49
214 changed files with 825 additions and 827 deletions

View file

@ -35,7 +35,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
// https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group-set
OrderedHashTable<BrowsingContext*> m_browsing_context_set;
OrderedHashTable<JS::GCPtr<BrowsingContext>> m_browsing_context_set;
WeakPtr<Page> m_page;
};

View file

@ -38,17 +38,17 @@ void CanvasPath::bezier_curve_to(double cp1x, double cp1y, double cp2x, double c
WebIDL::ExceptionOr<void> CanvasPath::arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise)
{
if (radius < 0)
return WebIDL::IndexSizeError::create(m_self.realm(), DeprecatedString::formatted("The radius provided ({}) is negative.", radius));
return WebIDL::IndexSizeError::create(m_self->realm(), DeprecatedString::formatted("The radius provided ({}) is negative.", radius));
return ellipse(x, y, radius, radius, 0, start_angle, end_angle, counter_clockwise);
}
WebIDL::ExceptionOr<void> CanvasPath::ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise)
{
if (radius_x < 0)
return WebIDL::IndexSizeError::create(m_self.realm(), DeprecatedString::formatted("The major-axis radius provided ({}) is negative.", radius_x));
return WebIDL::IndexSizeError::create(m_self->realm(), DeprecatedString::formatted("The major-axis radius provided ({}) is negative.", radius_x));
if (radius_y < 0)
return WebIDL::IndexSizeError::create(m_self.realm(), DeprecatedString::formatted("The minor-axis radius provided ({}) is negative.", radius_y));
return WebIDL::IndexSizeError::create(m_self->realm(), DeprecatedString::formatted("The minor-axis radius provided ({}) is negative.", radius_y));
if (constexpr float tau = M_TAU; (!counter_clockwise && (end_angle - start_angle) >= tau)
|| (counter_clockwise && (start_angle - end_angle) >= tau)) {

View file

@ -36,7 +36,7 @@ protected:
}
private:
Bindings::PlatformObject& m_self;
JS::NonnullGCPtr<Bindings::PlatformObject> m_self;
Gfx::Path m_path;
};

View file

@ -137,7 +137,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<HT
// 5. Otherwise:
else {
// 1. Let crossOriginGet be undefined.
Optional<JS::FunctionObject*> cross_origin_get;
Optional<JS::GCPtr<JS::FunctionObject>> cross_origin_get;
// 2. If e.[[NeedsGet]] is true, then set crossOriginGet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the getter of the IDL attribute P on object O.
if (*entry.needs_get) {
@ -149,7 +149,7 @@ Optional<JS::PropertyDescriptor> cross_origin_get_own_property_helper(Variant<HT
}
// 3. Let crossOriginSet be undefined.
Optional<JS::FunctionObject*> cross_origin_set;
Optional<JS::GCPtr<JS::FunctionObject>> cross_origin_set;
// If e.[[NeedsSet]] is true, then set crossOriginSet to an anonymous built-in function, created in the current Realm Record, that performs the same steps as the setter of the IDL attribute P on object O.
if (*entry.needs_set) {

View file

@ -24,7 +24,7 @@ void EventHandler::visit_edges(Cell::Visitor& visitor)
Cell::visit_edges(visitor);
visitor.visit(listener);
if (auto* callback = value.get_pointer<WebIDL::CallbackType*>())
if (auto* callback = value.get_pointer<JS::GCPtr<WebIDL::CallbackType>>())
visitor.visit(*callback);
}

View file

@ -23,10 +23,10 @@ public:
// NOTE: This does not contain Empty as part of the optimization of not allocating all event handler attributes up front.
// FIXME: The string should actually be an "internal raw uncompiled handler" struct. This struct is just the uncompiled source code plus a source location for reporting parse errors.
// https://html.spec.whatwg.org/multipage/webappapis.html#internal-raw-uncompiled-handler
Variant<DeprecatedString, WebIDL::CallbackType*> value;
Variant<DeprecatedString, JS::GCPtr<WebIDL::CallbackType>> value;
// https://html.spec.whatwg.org/multipage/webappapis.html#event-handler-listener
DOM::DOMEventListener* listener { nullptr };
JS::GCPtr<DOM::DOMEventListener> listener;
private:
virtual StringView class_name() const override { return "EventHandler"sv; }

View file

@ -308,7 +308,7 @@ void EventLoop::perform_a_microtask_checkpoint()
// 4. For each environment settings object whose responsible event loop is this event loop, notify about rejected promises on that environment settings object.
for (auto& environment_settings_object : m_related_environment_settings_objects)
environment_settings_object.notify_about_rejected_promises({});
environment_settings_object->notify_about_rejected_promises({});
// FIXME: 5. Cleanup Indexed Database transactions.
@ -362,7 +362,7 @@ void EventLoop::register_environment_settings_object(Badge<EnvironmentSettingsOb
void EventLoop::unregister_environment_settings_object(Badge<EnvironmentSettingsObject>, EnvironmentSettingsObject& environment_settings_object)
{
bool did_remove = m_related_environment_settings_objects.remove_first_matching([&](auto& entry) { return &entry == &environment_settings_object; });
bool did_remove = m_related_environment_settings_objects.remove_first_matching([&](auto& entry) { return entry.ptr() == &environment_settings_object; });
VERIFY(did_remove);
}

View file

@ -101,10 +101,10 @@ private:
Vector<WeakPtr<DOM::Document>> m_documents;
// Used to implement step 4 of "perform a microtask checkpoint".
Vector<EnvironmentSettingsObject&> m_related_environment_settings_objects;
Vector<JS::NonnullGCPtr<EnvironmentSettingsObject>> m_related_environment_settings_objects;
// https://html.spec.whatwg.org/multipage/webappapis.html#backup-incumbent-settings-object-stack
Vector<EnvironmentSettingsObject&> m_backup_incumbent_settings_object_stack;
Vector<JS::NonnullGCPtr<EnvironmentSettingsObject>> m_backup_incumbent_settings_object_stack;
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#termination-nesting-level
size_t m_termination_nesting_level { 0 };

View file

@ -12,6 +12,7 @@
#include <AK/StringView.h>
#include <AK/Types.h>
#include <AK/Utf8View.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/Parser/HTMLToken.h>
@ -176,7 +177,7 @@ private:
void restore_to(Utf8CodePointIterator const& new_iterator);
HTMLToken::Position nth_last_position(size_t n = 0);
HTMLParser* m_parser { nullptr };
JS::GCPtr<HTMLParser> m_parser;
State m_state { State::Data };
State m_return_state { State::Data };

View file

@ -39,7 +39,7 @@ private:
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
JS::Promise* m_promise { nullptr };
JS::GCPtr<JS::Promise> m_promise;
JS::Value m_reason;
};

View file

@ -259,7 +259,7 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge<EventLoop>)
// 4. If p's [[PromiseIsHandled]] internal slot is false, add p to settings object's outstanding rejected promises weak set.
if (!promise->is_handled())
m_outstanding_rejected_promises_weak_set.append(promise);
m_outstanding_rejected_promises_weak_set.append(*promise);
// This algorithm results in promise rejections being marked as handled or not handled. These concepts parallel handled and not handled script errors.
// If a rejection is still not handled after this, then the rejection may be reported to a developer console.

View file

@ -130,7 +130,7 @@ private:
// https://html.spec.whatwg.org/multipage/webappapis.html#outstanding-rejected-promises-weak-set
// The outstanding rejected promises weak set must not create strong references to any of its members, and implementations are free to limit its size, e.g. by removing old entries from it when new ones are added.
Vector<JS::Promise*> m_outstanding_rejected_promises_weak_set;
Vector<JS::GCPtr<JS::Promise>> m_outstanding_rejected_promises_weak_set;
// https://html.spec.whatwg.org/multipage/webappapis.html#about-to-be-notified-rejected-promises-list
Vector<JS::Handle<JS::Promise>> m_about_to_be_notified_rejected_promises_list;

View file

@ -48,7 +48,7 @@ public:
struct Entry {
EntryType type;
JavaScriptModuleScript* module_script;
JS::GCPtr<JavaScriptModuleScript> module_script;
};
bool is_fetching(AK::URL const& url, DeprecatedString const& type) const;

View file

@ -35,7 +35,7 @@ private:
AK::URL m_base_url;
DeprecatedString m_filename;
EnvironmentSettingsObject& m_settings_object;
JS::NonnullGCPtr<EnvironmentSettingsObject> m_settings_object;
};
}

View file

@ -30,7 +30,7 @@ void WindowEnvironmentSettingsObject::visit_edges(JS::Cell::Visitor& visitor)
WebIDL::ExceptionOr<void> WindowEnvironmentSettingsObject::setup(AK::URL const& creation_url, NonnullOwnPtr<JS::ExecutionContext> execution_context, Optional<Environment> reserved_environment, AK::URL top_level_creation_url, Origin top_level_origin)
{
// 1. Let realm be the value of execution context's Realm component.
auto* realm = execution_context->realm;
auto realm = execution_context->realm;
VERIFY(realm);
// 2. Let window be realm's global object.

View file

@ -25,7 +25,7 @@ public:
static JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> setup(NonnullOwnPtr<JS::ExecutionContext> execution_context /* FIXME: null or an environment reservedEnvironment, a URL topLevelCreationURL, and an origin topLevelOrigin */)
{
auto* realm = execution_context->realm;
auto realm = execution_context->realm;
VERIFY(realm);
auto settings_object = realm->heap().allocate<WorkerEnvironmentSettingsObject>(*realm, move(execution_context)).release_allocated_value_but_fixme_should_propagate_errors();
settings_object->target_browsing_context = nullptr;

View file

@ -15,7 +15,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::href() const
{
auto& vm = realm().vm();
// The href getter steps are to return this's WorkerGlobalScope object's url, serialized.
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope.url().serialize()));
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope->url().serialize()));
}
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-origin
@ -23,7 +23,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::origin() const
{
auto& vm = realm().vm();
// The origin getter steps are to return the serialization of this's WorkerGlobalScope object's url's origin.
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope.url().serialize_origin()));
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope->url().serialize_origin()));
}
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-protocol
@ -31,7 +31,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::protocol() const
{
auto& vm = realm().vm();
// The protocol getter steps are to return this's WorkerGlobalScope object's url's scheme, followed by ":".
return TRY_OR_THROW_OOM(vm, String::formatted("{}:", m_global_scope.url().scheme().view()));
return TRY_OR_THROW_OOM(vm, String::formatted("{}:", m_global_scope->url().scheme().view()));
}
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-host
@ -41,7 +41,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::host() const
// The host getter steps are:
// 1. Let url be this's WorkerGlobalScope object's url.
auto const& url = m_global_scope.url();
auto const& url = m_global_scope->url();
// 2. If url's host is null, return the empty string.
if (url.host().is_empty())
@ -62,7 +62,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::hostname() const
// The hostname getter steps are:
// 1. Let host be this's WorkerGlobalScope object's url's host.
auto const& host = m_global_scope.url().host();
auto const& host = m_global_scope->url().host();
// 2. If host is null, return the empty string.
if (host.is_empty())
@ -79,7 +79,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::port() const
// The port getter steps are:
// 1. Let port be this's WorkerGlobalScope object's url's port.
auto const& port = m_global_scope.url().port();
auto const& port = m_global_scope->url().port();
// 2. If port is null, return the empty string.
if (!port.has_value())
@ -93,7 +93,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::pathname() const
{
auto& vm = realm().vm();
// The pathname getter steps are to return the result of URL path serializing this's WorkerGlobalScope object's url.
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope.url().path()));
return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_global_scope->url().path()));
}
// https://html.spec.whatwg.org/multipage/workers.html#dom-workerlocation-search
@ -103,7 +103,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::search() const
// The search getter steps are:
// 1. Let query be this's WorkerGlobalScope object's url's query.
auto const& query = m_global_scope.url().query();
auto const& query = m_global_scope->url().query();
// 2. If query is either null or the empty string, return the empty string.
if (query.is_empty())
@ -120,7 +120,7 @@ WebIDL::ExceptionOr<String> WorkerLocation::hash() const
// The hash getter steps are:
// 1. Let fragment be this's WorkerGlobalScope object's url's fragment.
auto const& fragment = m_global_scope.url().fragment();
auto const& fragment = m_global_scope->url().fragment();
// 2. If fragment is either null or the empty string, return the empty string.
if (fragment.is_empty())

View file

@ -32,7 +32,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
WorkerGlobalScope& m_global_scope;
JS::NonnullGCPtr<WorkerGlobalScope> m_global_scope;
};
}