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

LibWeb+LibJS: Use JS::GCPtr for pointers to GC-allocated objects

Fixes warnings found by LibJSGCVerifier
This commit is contained in:
Aliaksandr Kalenik 2023-12-11 12:23:04 +01:00 committed by Alexander Kalenik
parent ed97946975
commit 6ac43274b2
14 changed files with 31 additions and 31 deletions

View file

@ -14,7 +14,7 @@
namespace JS::Bytecode { namespace JS::Bytecode {
struct UnwindInfo { struct UnwindInfo {
Executable const* executable; JS::GCPtr<Executable const> executable;
JS::GCPtr<Environment> lexical_environment; JS::GCPtr<Environment> lexical_environment;
bool handler_called { false }; bool handler_called { false };

View file

@ -40,8 +40,8 @@ void GraphLoadingState::visit_edges(Cell::Visitor& visitor)
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(promise_capability); visitor.visit(promise_capability);
visitor.visit(host_defined); visitor.visit(host_defined);
for (auto* module : visited) for (auto module : visited)
visitor.visit(*module); visitor.visit(module);
} }
// 16.2.1.5.1 LoadRequestedModules ( [ hostDefined ] ), https://tc39.es/ecma262/#sec-LoadRequestedModules // 16.2.1.5.1 LoadRequestedModules ( [ hostDefined ] ), https://tc39.es/ecma262/#sec-LoadRequestedModules
@ -54,7 +54,7 @@ PromiseCapability& CyclicModule::load_requested_modules(GCPtr<GraphLoadingState:
auto promise_capability = MUST(new_promise_capability(vm(), vm().current_realm()->intrinsics().promise_constructor())); auto promise_capability = MUST(new_promise_capability(vm(), vm().current_realm()->intrinsics().promise_constructor()));
// 3. Let state be the GraphLoadingState Record { [[IsLoading]]: true, [[PendingModulesCount]]: 1, [[Visited]]: « », [[PromiseCapability]]: pc, [[HostDefined]]: hostDefined }. // 3. Let state be the GraphLoadingState Record { [[IsLoading]]: true, [[PendingModulesCount]]: 1, [[Visited]]: « », [[PromiseCapability]]: pc, [[HostDefined]]: hostDefined }.
auto state = heap().allocate_without_realm<GraphLoadingState>(promise_capability, true, 1, HashTable<CyclicModule*> {}, move(host_defined)); auto state = heap().allocate_without_realm<GraphLoadingState>(promise_capability, true, 1, HashTable<JS::GCPtr<CyclicModule>> {}, move(host_defined));
// 4. Perform InnerModuleLoading(state, module). // 4. Perform InnerModuleLoading(state, module).
inner_module_loading(state); inner_module_loading(state);

View file

@ -71,11 +71,11 @@ public:
GCPtr<PromiseCapability> promise_capability; // [[PromiseCapability]] GCPtr<PromiseCapability> promise_capability; // [[PromiseCapability]]
bool is_loading { false }; // [[IsLoading]] bool is_loading { false }; // [[IsLoading]]
size_t pending_module_count { 0 }; // [[PendingModulesCount]] size_t pending_module_count { 0 }; // [[PendingModulesCount]]
HashTable<CyclicModule*> visited; // [[Visited]] HashTable<JS::GCPtr<CyclicModule>> visited; // [[Visited]]
GCPtr<HostDefined> host_defined; // [[HostDefined]] GCPtr<HostDefined> host_defined; // [[HostDefined]]
private: private:
GraphLoadingState(GCPtr<PromiseCapability> promise_capability, bool is_loading, size_t pending_module_count, HashTable<CyclicModule*> visited, GCPtr<HostDefined> host_defined) GraphLoadingState(GCPtr<PromiseCapability> promise_capability, bool is_loading, size_t pending_module_count, HashTable<JS::GCPtr<CyclicModule>> visited, GCPtr<HostDefined> host_defined)
: promise_capability(move(promise_capability)) : promise_capability(move(promise_capability))
, is_loading(is_loading) , is_loading(is_loading)
, pending_module_count(pending_module_count) , pending_module_count(pending_module_count)

View file

@ -462,7 +462,7 @@ ErrorOr<void> initialize_main_thread_vm()
auto destination = Fetch::Infrastructure::Request::Destination::Script; auto destination = Fetch::Infrastructure::Request::Destination::Script;
// 11. Let fetchClient be settingsObject. // 11. Let fetchClient be settingsObject.
Optional<HTML::EnvironmentSettingsObject&> fetch_client = *settings_object; JS::NonnullGCPtr fetch_client { *settings_object };
// 12. If loadState is not undefined, then: // 12. If loadState is not undefined, then:
if (load_state) { if (load_state) {

View file

@ -3587,7 +3587,7 @@ void Document::update_for_history_step_application(JS::NonnullGCPtr<HTML::Sessio
} }
} }
HashMap<AK::URL, HTML::SharedImageRequest*>& Document::shared_image_requests() HashMap<AK::URL, JS::GCPtr<HTML::SharedImageRequest>>& Document::shared_image_requests()
{ {
return m_shared_image_requests; return m_shared_image_requests;
} }

View file

@ -535,7 +535,7 @@ public:
void update_for_history_step_application(JS::NonnullGCPtr<HTML::SessionHistoryEntry>, bool do_not_reactive, size_t script_history_length, size_t script_history_index); void update_for_history_step_application(JS::NonnullGCPtr<HTML::SessionHistoryEntry>, bool do_not_reactive, size_t script_history_length, size_t script_history_index);
HashMap<AK::URL, HTML::SharedImageRequest*>& shared_image_requests(); HashMap<AK::URL, JS::GCPtr<HTML::SharedImageRequest>>& shared_image_requests();
JS::NonnullGCPtr<Animations::DocumentTimeline> timeline(); JS::NonnullGCPtr<Animations::DocumentTimeline> timeline();
@ -754,7 +754,7 @@ private:
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#latest-entry // https://html.spec.whatwg.org/multipage/browsing-the-web.html#latest-entry
JS::GCPtr<HTML::SessionHistoryEntry> m_latest_entry; JS::GCPtr<HTML::SessionHistoryEntry> m_latest_entry;
HashMap<AK::URL, HTML::SharedImageRequest*> m_shared_image_requests; HashMap<AK::URL, JS::GCPtr<HTML::SharedImageRequest>> m_shared_image_requests;
// https://www.w3.org/TR/web-animations-1/#timeline-associated-with-a-document // https://www.w3.org/TR/web-animations-1/#timeline-associated-with-a-document
HashTable<JS::NonnullGCPtr<Animations::AnimationTimeline>> m_associated_animation_timelines; HashTable<JS::NonnullGCPtr<Animations::AnimationTimeline>> m_associated_animation_timelines;

View file

@ -58,10 +58,10 @@ class FetchContext : public JS::GraphLoadingState::HostDefined {
JS_CELL(FetchContext, JS::GraphLoadingState::HostDefined); JS_CELL(FetchContext, JS::GraphLoadingState::HostDefined);
public: public:
JS::Value parse_error; // [[ParseError]] JS::Value parse_error; // [[ParseError]]
Fetch::Infrastructure::Request::Destination destination; // [[Destination]] Fetch::Infrastructure::Request::Destination destination; // [[Destination]]
JS::GCPtr<JS::Promise> perform_fetch; // [[PerformFetch]] JS::GCPtr<JS::Promise> perform_fetch; // [[PerformFetch]]
EnvironmentSettingsObject& fetch_client; // [[FetchClient]] JS::NonnullGCPtr<EnvironmentSettingsObject> fetch_client; // [[FetchClient]]
private: private:
FetchContext(JS::Value parse_error, Fetch::Infrastructure::Request::Destination destination, JS::GCPtr<JS::Promise> perform_fetch, EnvironmentSettingsObject& fetch_client) FetchContext(JS::Value parse_error, Fetch::Infrastructure::Request::Destination destination, JS::GCPtr<JS::Promise> perform_fetch, EnvironmentSettingsObject& fetch_client)

View file

@ -43,7 +43,7 @@ public:
void start_timer() { m_load_timer.start(); } void start_timer() { m_load_timer.start(); }
Duration load_time() const { return m_load_timer.elapsed_time(); } Duration load_time() const { return m_load_timer.elapsed_time(); }
Optional<Page&>& page() { return m_page; } JS::GCPtr<Page> page() { return m_page; }
void set_page(Page& page) { m_page = page; } void set_page(Page& page) { m_page = page; }
unsigned hash() const unsigned hash() const
@ -79,7 +79,7 @@ private:
HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> m_headers; HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> m_headers;
ByteBuffer m_body; ByteBuffer m_body;
Core::ElapsedTimer m_load_timer; Core::ElapsedTimer m_load_timer;
Optional<Page&> m_page; JS::GCPtr<Page> m_page;
bool m_main_resource { false }; bool m_main_resource { false };
}; };

View file

@ -231,8 +231,8 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback
} }
if (url.scheme() == "file") { if (url.scheme() == "file") {
if (request.page().has_value()) if (request.page())
m_page = request.page().value(); m_page = request.page();
if (!m_page.has_value()) { if (!m_page.has_value()) {
log_failure(request, "INTERNAL ERROR: No Page for request"); log_failure(request, "INTERNAL ERROR: No Page for request");
@ -302,7 +302,7 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback
success_callback(data, response_headers, {}); success_callback(data, response_headers, {});
}); });
m_page->client().request_file(move(file_request)); (*m_page)->client().request_file(move(file_request));
++m_pending_loads; ++m_pending_loads;
if (on_load_counter_change) if (on_load_counter_change)
@ -348,9 +348,9 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback
if (on_load_counter_change) if (on_load_counter_change)
on_load_counter_change(); on_load_counter_change();
if (request.page().has_value()) { if (request.page()) {
if (auto set_cookie = response_headers.get("Set-Cookie"); set_cookie.has_value()) if (auto set_cookie = response_headers.get("Set-Cookie"); set_cookie.has_value())
store_response_cookies(request.page().value(), request.url(), *set_cookie); store_response_cookies(*request.page(), request.url(), *set_cookie);
if (auto cache_control = response_headers.get("cache-control"); cache_control.has_value()) { if (auto cache_control = response_headers.get("cache-control"); cache_control.has_value()) {
if (cache_control.value().contains("no-store"sv)) { if (cache_control.value().contains("no-store"sv)) {
s_resource_cache.remove(request); s_resource_cache.remove(request);

View file

@ -144,7 +144,7 @@ private:
NonnullRefPtr<ResourceLoaderConnector> m_connector; NonnullRefPtr<ResourceLoaderConnector> m_connector;
String m_user_agent; String m_user_agent;
String m_platform; String m_platform;
Optional<Page&> m_page {}; Optional<JS::GCPtr<Page>> m_page {};
}; };
} }

View file

@ -74,14 +74,14 @@ public:
virtual void on_chunk(JS::Value chunk) override virtual void on_chunk(JS::Value chunk) override
{ {
// 1. Resolve promise with «[ "value" → chunk, "done" → false ]». // 1. Resolve promise with «[ "value" → chunk, "done" → false ]».
WebIDL::resolve_promise(m_realm, m_promise, JS::create_iterator_result_object(m_realm.vm(), chunk, false)); WebIDL::resolve_promise(m_realm, m_promise, JS::create_iterator_result_object(m_realm->vm(), chunk, false));
} }
// close steps, given chunk // close steps, given chunk
virtual void on_close(JS::Value chunk) override virtual void on_close(JS::Value chunk) override
{ {
// 1. Resolve promise with «[ "value" → chunk, "done" → true ]». // 1. Resolve promise with «[ "value" → chunk, "done" → true ]».
WebIDL::resolve_promise(m_realm, m_promise, JS::create_iterator_result_object(m_realm.vm(), chunk, true)); WebIDL::resolve_promise(m_realm, m_promise, JS::create_iterator_result_object(m_realm->vm(), chunk, true));
} }
// error steps, given e // error steps, given e
@ -99,7 +99,7 @@ private:
visitor.visit(m_promise); visitor.visit(m_promise);
} }
JS::Realm& m_realm; JS::NonnullGCPtr<JS::Realm> m_realm;
WebIDL::Promise& m_promise; WebIDL::Promise& m_promise;
}; };

View file

@ -126,12 +126,12 @@ public:
virtual void on_chunk(JS::Value chunk) override virtual void on_chunk(JS::Value chunk) override
{ {
WebIDL::resolve_promise(m_realm, m_promise, JS::create_iterator_result_object(m_realm.vm(), chunk, false)); WebIDL::resolve_promise(m_realm, m_promise, JS::create_iterator_result_object(m_realm->vm(), chunk, false));
} }
virtual void on_close() override virtual void on_close() override
{ {
WebIDL::resolve_promise(m_realm, m_promise, JS::create_iterator_result_object(m_realm.vm(), JS::js_undefined(), true)); WebIDL::resolve_promise(m_realm, m_promise, JS::create_iterator_result_object(m_realm->vm(), JS::js_undefined(), true));
} }
virtual void on_error(JS::Value error) override virtual void on_error(JS::Value error) override
@ -147,7 +147,7 @@ private:
visitor.visit(m_promise); visitor.visit(m_promise);
} }
JS::Realm& m_realm; JS::NonnullGCPtr<JS::Realm> m_realm;
WebIDL::Promise& m_promise; WebIDL::Promise& m_promise;
}; };

View file

@ -53,8 +53,8 @@ private:
virtual void visit_edges(Visitor&) override; virtual void visit_edges(Visitor&) override;
JS::VM& m_vm; JS::VM& m_vm;
JS::Realm& m_realm; JS::NonnullGCPtr<JS::Realm> m_realm;
ReadableStreamDefaultReader& m_reader; JS::NonnullGCPtr<ReadableStreamDefaultReader> m_reader;
ByteBuffer m_bytes; ByteBuffer m_bytes;
SuccessSteps m_success_steps; SuccessSteps m_success_steps;
FailureSteps m_failure_steps; FailureSteps m_failure_steps;

View file

@ -42,7 +42,7 @@ protected:
// A ReadableStream instance that owns this reader // A ReadableStream instance that owns this reader
JS::GCPtr<ReadableStream> m_stream; JS::GCPtr<ReadableStream> m_stream;
JS::Realm& m_realm; JS::NonnullGCPtr<JS::Realm> m_realm;
}; };
} }