LibGC+Everywhere: Factor out a LibGC from LibJS

Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
This commit is contained in:
Shannon Booth 2024-11-15 04:01:23 +13:00 committed by Andreas Kling
parent ce23efc5f6
commit f87041bf3a
Notes: github-actions[bot] 2024-11-15 13:50:17 +00:00
1722 changed files with 9939 additions and 9906 deletions

View file

@ -16,11 +16,11 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(ClassicScript);
GC_DEFINE_ALLOCATOR(ClassicScript);
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-classic-script
// https://whatpr.org/html/9893/webappapis.html#creating-a-classic-script
JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, StringView source, JS::Realm& realm, URL::URL base_url, size_t source_line_number, MutedErrors muted_errors)
GC::Ref<ClassicScript> ClassicScript::create(ByteString filename, StringView source, JS::Realm& realm, URL::URL base_url, size_t source_line_number, MutedErrors muted_errors)
{
auto& vm = realm.vm();
@ -75,7 +75,7 @@ JS::NonnullGCPtr<ClassicScript> ClassicScript::create(ByteString filename, Strin
// https://html.spec.whatwg.org/multipage/webappapis.html#run-a-classic-script
// https://whatpr.org/html/9893/webappapis.html#run-a-classic-script
JS::Completion ClassicScript::run(RethrowErrors rethrow_errors, JS::GCPtr<JS::Environment> lexical_environment_override)
JS::Completion ClassicScript::run(RethrowErrors rethrow_errors, GC::Ptr<JS::Environment> lexical_environment_override)
{
// 1. Let realm be the realm of script.
auto& realm = this->realm();

View file

@ -14,8 +14,8 @@ namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/webappapis.html#classic-script
class ClassicScript final : public Script {
JS_CELL(ClassicScript, Script);
JS_DECLARE_ALLOCATOR(ClassicScript);
GC_CELL(ClassicScript, Script);
GC_DECLARE_ALLOCATOR(ClassicScript);
public:
virtual ~ClassicScript() override;
@ -24,7 +24,7 @@ public:
No,
Yes,
};
static JS::NonnullGCPtr<ClassicScript> create(ByteString filename, StringView source, JS::Realm&, URL::URL base_url, size_t source_line_number = 1, MutedErrors = MutedErrors::No);
static GC::Ref<ClassicScript> create(ByteString filename, StringView source, JS::Realm&, URL::URL base_url, size_t source_line_number = 1, MutedErrors = MutedErrors::No);
JS::Script* script_record() { return m_script_record; }
JS::Script const* script_record() const { return m_script_record; }
@ -33,7 +33,7 @@ public:
No,
Yes,
};
JS::Completion run(RethrowErrors = RethrowErrors::No, JS::GCPtr<JS::Environment> lexical_environment_override = {});
JS::Completion run(RethrowErrors = RethrowErrors::No, GC::Ptr<JS::Environment> lexical_environment_override = {});
MutedErrors muted_errors() const { return m_muted_errors; }
@ -42,7 +42,7 @@ private:
virtual void visit_edges(Cell::Visitor&) override;
JS::GCPtr<JS::Script> m_script_record;
GC::Ptr<JS::Script> m_script_record;
MutedErrors m_muted_errors { MutedErrors::No };
};

View file

@ -8,7 +8,7 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(EnvironmentSettingsSnapshot);
GC_DEFINE_ALLOCATOR(EnvironmentSettingsSnapshot);
EnvironmentSettingsSnapshot::EnvironmentSettingsSnapshot(NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& serialized_settings)
: EnvironmentSettingsObject(move(execution_context))

View file

@ -14,15 +14,15 @@ namespace Web::HTML {
class EnvironmentSettingsSnapshot final
: public EnvironmentSettingsObject {
JS_CELL(EnvironmentSettingsSnapshot, EnvironmentSettingsObject);
JS_DECLARE_ALLOCATOR(EnvironmentSettingsSnapshot);
GC_CELL(EnvironmentSettingsSnapshot, EnvironmentSettingsObject);
GC_DECLARE_ALLOCATOR(EnvironmentSettingsSnapshot);
public:
EnvironmentSettingsSnapshot(NonnullOwnPtr<JS::ExecutionContext>, SerializedEnvironmentSettingsObject const&);
virtual ~EnvironmentSettingsSnapshot() override;
JS::GCPtr<DOM::Document> responsible_document() override { return nullptr; }
GC::Ptr<DOM::Document> responsible_document() override { return nullptr; }
String api_url_character_encoding() override { return m_api_url_character_encoding; }
URL::URL api_base_url() override { return m_url; }
URL::Origin origin() override { return m_origin; }

View file

@ -517,7 +517,7 @@ SerializedEnvironmentSettingsObject EnvironmentSettingsObject::serialize()
return object;
}
JS::NonnullGCPtr<StorageAPI::StorageManager> EnvironmentSettingsObject::storage_manager()
GC::Ref<StorageAPI::StorageManager> EnvironmentSettingsObject::storage_manager()
{
if (!m_storage_manager)
m_storage_manager = realm().create<StorageAPI::StorageManager>(realm());

View file

@ -20,7 +20,7 @@ namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/webappapis.html#environment
struct Environment : public JS::Cell {
JS_CELL(Environment, JS::Cell);
GC_CELL(Environment, JS::Cell);
public:
virtual ~Environment() override;
@ -38,7 +38,7 @@ public:
URL::Origin top_level_origin;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-target-browsing-context
JS::GCPtr<BrowsingContext> target_browsing_context;
GC::Ptr<BrowsingContext> target_browsing_context;
// FIXME: An active service worker https://html.spec.whatwg.org/multipage/webappapis.html#concept-environment-active-service-worker
@ -56,7 +56,7 @@ enum class RunScriptDecision {
// https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
struct EnvironmentSettingsObject : public Environment {
JS_CELL(EnvironmentSettingsObject, Environment);
GC_CELL(EnvironmentSettingsObject, Environment);
public:
virtual ~EnvironmentSettingsObject() override;
@ -70,7 +70,7 @@ public:
ModuleMap& module_map();
// https://html.spec.whatwg.org/multipage/webappapis.html#responsible-document
virtual JS::GCPtr<DOM::Document> responsible_document() = 0;
virtual GC::Ptr<DOM::Document> responsible_document() = 0;
// https://html.spec.whatwg.org/multipage/webappapis.html#api-url-character-encoding
virtual String api_url_character_encoding() = 0;
@ -94,11 +94,11 @@ public:
EventLoop& responsible_event_loop();
// https://fetch.spec.whatwg.org/#concept-fetch-group
Vector<JS::NonnullGCPtr<Fetch::Infrastructure::FetchRecord>>& fetch_group() { return m_fetch_group; }
Vector<GC::Ref<Fetch::Infrastructure::FetchRecord>>& fetch_group() { return m_fetch_group; }
SerializedEnvironmentSettingsObject serialize();
JS::NonnullGCPtr<StorageAPI::StorageManager> storage_manager();
GC::Ref<StorageAPI::StorageManager> storage_manager();
[[nodiscard]] bool discarded() const { return m_discarded; }
void set_discarded(bool b) { m_discarded = b; }
@ -110,17 +110,17 @@ protected:
private:
NonnullOwnPtr<JS::ExecutionContext> m_realm_execution_context;
JS::GCPtr<ModuleMap> m_module_map;
GC::Ptr<ModuleMap> m_module_map;
JS::GCPtr<EventLoop> m_responsible_event_loop;
GC::Ptr<EventLoop> m_responsible_event_loop;
// https://fetch.spec.whatwg.org/#concept-fetch-record
// A fetch group holds an ordered list of fetch records
Vector<JS::NonnullGCPtr<Fetch::Infrastructure::FetchRecord>> m_fetch_group;
Vector<GC::Ref<Fetch::Infrastructure::FetchRecord>> m_fetch_group;
// https://storage.spec.whatwg.org/#api
// Each environment settings object has an associated StorageManager object.
JS::GCPtr<StorageAPI::StorageManager> m_storage_manager;
GC::Ptr<StorageAPI::StorageManager> m_storage_manager;
// https://w3c.github.io/ServiceWorker/#service-worker-client-discarded-flag
// A service worker client has an associated discarded flag. It is initially unset.

View file

@ -6,7 +6,7 @@
*/
#include <LibCore/EventLoop.h>
#include <LibJS/Heap/HeapFunction.h>
#include <LibGC/Function.h>
#include <LibJS/Runtime/ModuleRequest.h>
#include <LibTextCodec/Decoder.h>
#include <LibWeb/DOM/Document.h>
@ -30,16 +30,16 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(FetchContext);
GC_DEFINE_ALLOCATOR(FetchContext);
OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<void(JS::GCPtr<Script>)> function)
OnFetchScriptComplete create_on_fetch_script_complete(GC::Heap& heap, Function<void(GC::Ptr<Script>)> function)
{
return JS::create_heap_function(heap, move(function));
return GC::create_function(heap, move(function));
}
PerformTheFetchHook create_perform_the_fetch_hook(JS::Heap& heap, Function<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function)
PerformTheFetchHook create_perform_the_fetch_hook(GC::Heap& heap, Function<WebIDL::ExceptionOr<void>(GC::Ref<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function)
{
return JS::create_heap_function(heap, move(function));
return GC::create_function(heap, move(function));
}
ScriptFetchOptions default_script_fetch_options()
@ -319,7 +319,7 @@ WebIDL::ExceptionOr<String> resolve_a_module_integrity_metadata(const URL::URL&
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-script
WebIDL::ExceptionOr<void> fetch_classic_script(JS::NonnullGCPtr<HTMLScriptElement> element, URL::URL const& url, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, String character_encoding, OnFetchScriptComplete on_complete)
WebIDL::ExceptionOr<void> fetch_classic_script(GC::Ref<HTMLScriptElement> element, URL::URL const& url, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, String character_encoding, OnFetchScriptComplete on_complete)
{
auto& realm = element->realm();
auto& vm = realm.vm();
@ -464,13 +464,13 @@ WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const& url, Envir
}
// https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-worker-imported-script
WebIDL::ExceptionOr<JS::NonnullGCPtr<ClassicScript>> fetch_a_classic_worker_imported_script(URL::URL const& url, HTML::EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch)
WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_script(URL::URL const& url, HTML::EnvironmentSettingsObject& settings_object, PerformTheFetchHook perform_fetch)
{
auto& realm = settings_object.realm();
auto& vm = realm.vm();
// 1. Let response be null.
JS::GCPtr<Fetch::Infrastructure::Response> response = nullptr;
GC::Ptr<Fetch::Infrastructure::Response> response = nullptr;
// 2. Let bodyBytes be null.
Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes;
@ -485,7 +485,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ClassicScript>> fetch_a_classic_worker_impo
request->set_parser_metadata(Fetch::Infrastructure::Request::ParserMetadata::NotParserInserted);
request->set_use_url_credentials(true);
auto process_response_consume_body = [&response, &body_bytes](JS::NonnullGCPtr<Fetch::Infrastructure::Response> res, Fetch::Infrastructure::FetchAlgorithms::BodyBytes bb) {
auto process_response_consume_body = [&response, &body_bytes](GC::Ref<Fetch::Infrastructure::Response> res, Fetch::Infrastructure::FetchAlgorithms::BodyBytes bb) {
// 1. Set bodyBytes to bb.
body_bytes = move(bb);
@ -506,7 +506,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ClassicScript>> fetch_a_classic_worker_impo
// 5. Pause until response is not null.
auto& event_loop = settings_object.responsible_event_loop();
event_loop.spin_until(JS::create_heap_function(vm.heap(), [&]() -> bool {
event_loop.spin_until(GC::create_function(vm.heap(), [&]() -> bool {
return response;
}));
@ -759,7 +759,7 @@ void fetch_single_module_script(JS::Realm& realm,
// then queue a task on the networking task source to proceed with running the following steps.
if (module_map.is_fetching(url, module_type)) {
module_map.wait_for_change(realm.heap(), url, module_type, [on_complete, &realm](auto entry) -> void {
HTML::queue_global_task(HTML::Task::Source::Networking, realm.global_object(), JS::create_heap_function(realm.heap(), [on_complete, entry] {
HTML::queue_global_task(HTML::Task::Source::Networking, realm.global_object(), GC::create_function(realm.heap(), [on_complete, entry] {
// FIXME: This should run other steps, for now we just assume the script loaded.
VERIFY(entry.type == ModuleMap::EntryType::ModuleScript || entry.type == ModuleMap::EntryType::Failed);
@ -803,7 +803,7 @@ void fetch_single_module_script(JS::Realm& realm,
// 13. If performFetch was given, run performFetch with request, isTopLevel, and with processResponseConsumeBody as defined below.
// Otherwise, fetch request with processResponseConsumeBody set to processResponseConsumeBody as defined below.
// In both cases, let processResponseConsumeBody given response response and null, failure, or a byte sequence bodyBytes be the following algorithm:
auto process_response_consume_body = [&module_map, url, module_type, &module_map_realm, on_complete](JS::NonnullGCPtr<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {
auto process_response_consume_body = [&module_map, url, module_type, &module_map_realm, on_complete](GC::Ref<Fetch::Infrastructure::Response> response, Fetch::Infrastructure::FetchAlgorithms::BodyBytes body_bytes) {
// 1. If either of the following conditions are met:
// - bodyBytes is null or failure; or
// - response's status is not an ok status,
@ -823,7 +823,7 @@ void fetch_single_module_script(JS::Realm& realm,
auto mime_type = response->header_list()->extract_mime_type();
// 4. Let moduleScript be null.
JS::GCPtr<JavaScriptModuleScript> module_script;
GC::Ptr<JavaScriptModuleScript> module_script;
// FIXME: 5. Let referrerPolicy be the result of parsing the `Referrer-Policy` header given response. [REFERRERPOLICY]
// FIXME: 6. If referrerPolicy is not the empty string, set options's referrer policy to referrerPolicy.
@ -968,7 +968,7 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm,
auto& loading_promise = record->load_requested_modules(state);
// 6. Upon fulfillment of loadingPromise, run the following steps:
WebIDL::upon_fulfillment(loading_promise, JS::create_heap_function(realm.heap(), [&realm, record, &module_script, on_complete](JS::Value) -> WebIDL::ExceptionOr<JS::Value> {
WebIDL::upon_fulfillment(loading_promise, GC::create_function(realm.heap(), [&realm, record, &module_script, on_complete](JS::Value) -> WebIDL::ExceptionOr<JS::Value> {
// 1. Perform record.Link().
auto linking_result = record->link(realm.vm());
@ -983,7 +983,7 @@ void fetch_descendants_of_and_link_a_module_script(JS::Realm& realm,
}));
// 7. Upon rejection of loadingPromise, run the following steps:
WebIDL::upon_rejection(loading_promise, JS::create_heap_function(realm.heap(), [state, &module_script, on_complete](JS::Value) -> WebIDL::ExceptionOr<JS::Value> {
WebIDL::upon_rejection(loading_promise, GC::create_function(realm.heap(), [state, &module_script, on_complete](JS::Value) -> WebIDL::ExceptionOr<JS::Value> {
// 1. If state.[[ParseError]] is not null, set moduleScript's error to rethrow to state.[[ParseError]] and run
// onComplete given moduleScript.
if (!state->parse_error.is_null()) {

View file

@ -21,11 +21,11 @@ enum class TopLevelModule {
No
};
using OnFetchScriptComplete = JS::NonnullGCPtr<JS::HeapFunction<void(JS::GCPtr<Script>)>>;
using PerformTheFetchHook = JS::GCPtr<JS::HeapFunction<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)>>;
using OnFetchScriptComplete = GC::Ref<GC::Function<void(GC::Ptr<Script>)>>;
using PerformTheFetchHook = GC::Ptr<GC::Function<WebIDL::ExceptionOr<void>(GC::Ref<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)>>;
OnFetchScriptComplete create_on_fetch_script_complete(JS::Heap& heap, Function<void(JS::GCPtr<Script>)> function);
PerformTheFetchHook create_perform_the_fetch_hook(JS::Heap& heap, Function<WebIDL::ExceptionOr<void>(JS::NonnullGCPtr<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function);
OnFetchScriptComplete create_on_fetch_script_complete(GC::Heap& heap, Function<void(GC::Ptr<Script>)> function);
PerformTheFetchHook create_perform_the_fetch_hook(GC::Heap& heap, Function<WebIDL::ExceptionOr<void>(GC::Ref<Fetch::Infrastructure::Request>, TopLevelModule, Fetch::Infrastructure::FetchAlgorithms::ProcessResponseConsumeBodyFunction)> function);
// https://html.spec.whatwg.org/multipage/webappapis.html#script-fetch-options
struct ScriptFetchOptions {
@ -55,14 +55,14 @@ struct ScriptFetchOptions {
ScriptFetchOptions default_script_fetch_options();
class FetchContext : public JS::GraphLoadingState::HostDefined {
JS_CELL(FetchContext, JS::GraphLoadingState::HostDefined);
JS_DECLARE_ALLOCATOR(FetchContext);
GC_CELL(FetchContext, JS::GraphLoadingState::HostDefined);
GC_DECLARE_ALLOCATOR(FetchContext);
public:
JS::Value parse_error; // [[ParseError]]
Fetch::Infrastructure::Request::Destination destination; // [[Destination]]
PerformTheFetchHook perform_fetch; // [[PerformFetch]]
JS::NonnullGCPtr<EnvironmentSettingsObject> fetch_client; // [[FetchClient]]
JS::Value parse_error; // [[ParseError]]
Fetch::Infrastructure::Request::Destination destination; // [[Destination]]
PerformTheFetchHook perform_fetch; // [[PerformFetch]]
GC::Ref<EnvironmentSettingsObject> fetch_client; // [[FetchClient]]
private:
FetchContext(JS::Value parse_error, Fetch::Infrastructure::Request::Destination destination, PerformTheFetchHook perform_fetch, EnvironmentSettingsObject& fetch_client)
@ -88,9 +88,9 @@ WebIDL::ExceptionOr<Optional<URL::URL>> resolve_imports_match(ByteString const&
Optional<URL::URL> resolve_url_like_module_specifier(ByteString const& specifier, URL::URL const& base_url);
WebIDL::ExceptionOr<ScriptFetchOptions> get_descendant_script_fetch_options(ScriptFetchOptions const& original_options, URL::URL const& url, EnvironmentSettingsObject& settings_object);
WebIDL::ExceptionOr<String> resolve_a_module_integrity_metadata(URL::URL const& url, EnvironmentSettingsObject& settings_object);
WebIDL::ExceptionOr<void> fetch_classic_script(JS::NonnullGCPtr<HTMLScriptElement>, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, String character_encoding, OnFetchScriptComplete on_complete);
WebIDL::ExceptionOr<void> fetch_classic_script(GC::Ref<HTMLScriptElement>, URL::URL const&, EnvironmentSettingsObject& settings_object, ScriptFetchOptions options, CORSSettingAttribute cors_setting, String character_encoding, OnFetchScriptComplete on_complete);
WebIDL::ExceptionOr<void> fetch_classic_worker_script(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);
WebIDL::ExceptionOr<JS::NonnullGCPtr<ClassicScript>> fetch_a_classic_worker_imported_script(URL::URL const&, HTML::EnvironmentSettingsObject&, PerformTheFetchHook = nullptr);
WebIDL::ExceptionOr<GC::Ref<ClassicScript>> fetch_a_classic_worker_imported_script(URL::URL const&, HTML::EnvironmentSettingsObject&, PerformTheFetchHook = nullptr);
WebIDL::ExceptionOr<void> fetch_module_worker_script_graph(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);
WebIDL::ExceptionOr<void> fetch_worklet_module_worker_script_graph(URL::URL const&, EnvironmentSettingsObject& fetch_client, Fetch::Infrastructure::Request::Destination, EnvironmentSettingsObject& settings_object, PerformTheFetchHook, OnFetchScriptComplete);
void fetch_internal_module_script_graph(JS::Realm&, JS::ModuleRequest const& module_request, EnvironmentSettingsObject& fetch_client_settings_object, Fetch::Infrastructure::Request::Destination, ScriptFetchOptions const&, Script& referring_script, HashTable<ModuleLocationTuple> const& visited_set, PerformTheFetchHook, OnFetchScriptComplete on_complete);

View file

@ -13,14 +13,14 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(ImportMapParseResult);
GC_DEFINE_ALLOCATOR(ImportMapParseResult);
ImportMapParseResult::ImportMapParseResult() = default;
ImportMapParseResult::~ImportMapParseResult() = default;
// https://html.spec.whatwg.org/multipage/webappapis.html#create-an-import-map-parse-result
JS::NonnullGCPtr<ImportMapParseResult> ImportMapParseResult::create(JS::Realm& realm, ByteString const& input, URL::URL base_url)
GC::Ref<ImportMapParseResult> ImportMapParseResult::create(JS::Realm& realm, ByteString const& input, URL::URL base_url)
{
// 1. Let result be an import map parse result whose import map is null and whose error to rethrow is null.
auto result = realm.create<ImportMapParseResult>();
@ -53,7 +53,7 @@ void ImportMapParseResult::visit_edges(Visitor& visitor)
[&](WebIDL::SimpleException const&) {
// ignore
},
[&](JS::NonnullGCPtr<WebIDL::DOMException> exception) {
[&](GC::Ref<WebIDL::DOMException> exception) {
visitor.visit(exception);
},
[&](JS::Completion const& completion) {

View file

@ -19,13 +19,13 @@ namespace Web::HTML {
class ImportMapParseResult
: public JS::Cell
, public JS::Script::HostDefined {
JS_CELL(ImportMapParseResult, JS::Cell);
JS_DECLARE_ALLOCATOR(ImportMapParseResult);
GC_CELL(ImportMapParseResult, JS::Cell);
GC_DECLARE_ALLOCATOR(ImportMapParseResult);
public:
virtual ~ImportMapParseResult() override;
static JS::NonnullGCPtr<ImportMapParseResult> create(JS::Realm& realm, ByteString const& input, URL::URL base_url);
static GC::Ref<ImportMapParseResult> create(JS::Realm& realm, ByteString const& input, URL::URL base_url);
[[nodiscard]] Optional<ImportMap> const& import_map() const { return m_import_map; }
void set_import_map(ImportMap const& value) { m_import_map = value; }

View file

@ -8,7 +8,7 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(ModuleMap);
GC_DEFINE_ALLOCATOR(ModuleMap);
void ModuleMap::visit_edges(Visitor& visitor)
{
@ -62,9 +62,9 @@ AK::HashSetResult ModuleMap::set(URL::URL const& url, ByteString const& type, En
return value;
}
void ModuleMap::wait_for_change(JS::Heap& heap, URL::URL const& url, ByteString const& type, Function<void(Entry)> callback)
void ModuleMap::wait_for_change(GC::Heap& heap, URL::URL const& url, ByteString const& type, Function<void(Entry)> callback)
{
m_callbacks.ensure({ url, type }).append(JS::create_heap_function(heap, move(callback)));
m_callbacks.ensure({ url, type }).append(GC::create_function(heap, move(callback)));
}
}

View file

@ -6,8 +6,8 @@
#pragma once
#include <LibGC/Function.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Heap/HeapFunction.h>
#include <LibURL/URL.h>
#include <LibWeb/HTML/Scripting/ModuleScript.h>
@ -36,8 +36,8 @@ private:
// https://html.spec.whatwg.org/multipage/webappapis.html#module-map
class ModuleMap final : public JS::Cell {
JS_CELL(ModuleMap, JS::Cell);
JS_DECLARE_ALLOCATOR(ModuleMap);
GC_CELL(ModuleMap, JS::Cell);
GC_DECLARE_ALLOCATOR(ModuleMap);
public:
ModuleMap() = default;
@ -51,10 +51,10 @@ public:
struct Entry {
EntryType type;
JS::GCPtr<JavaScriptModuleScript> module_script;
GC::Ptr<JavaScriptModuleScript> module_script;
};
using CallbackFunction = JS::NonnullGCPtr<JS::HeapFunction<void(Entry)>>;
using CallbackFunction = GC::Ref<GC::Function<void(Entry)>>;
bool is_fetching(URL::URL const& url, ByteString const& type) const;
bool is_failed(URL::URL const& url, ByteString const& type) const;
@ -65,7 +65,7 @@ public:
AK::HashSetResult set(URL::URL const& url, ByteString const& type, Entry);
void wait_for_change(JS::Heap&, URL::URL const& url, ByteString const& type, Function<void(Entry)> callback);
void wait_for_change(GC::Heap&, URL::URL const& url, ByteString const& type, Function<void(Entry)> callback);
private:
virtual void visit_edges(JS::Cell::Visitor&) override;

View file

@ -13,7 +13,7 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(JavaScriptModuleScript);
GC_DEFINE_ALLOCATOR(JavaScriptModuleScript);
ModuleScript::~ModuleScript() = default;
@ -31,7 +31,7 @@ JavaScriptModuleScript::JavaScriptModuleScript(URL::URL base_url, ByteString fil
// https://html.spec.whatwg.org/multipage/webappapis.html#creating-a-javascript-module-script
// https://whatpr.org/html/9893/webappapis.html#creating-a-javascript-module-script
WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> JavaScriptModuleScript::create(ByteString const& filename, StringView source, JS::Realm& realm, URL::URL base_url)
WebIDL::ExceptionOr<GC::Ptr<JavaScriptModuleScript>> JavaScriptModuleScript::create(ByteString const& filename, StringView source, JS::Realm& realm, URL::URL base_url)
{
// 1. If scripting is disabled for realm, then set source to the empty string.
if (HTML::is_scripting_disabled(realm))
@ -146,7 +146,7 @@ JS::Promise* JavaScriptModuleScript::run(PreventErrorReporting)
// NON-STANDARD: To ensure that LibJS can find the module on the stack, we push a new execution context.
auto module_execution_context = JS::ExecutionContext::create();
module_execution_context->realm = &realm;
module_execution_context->script_or_module = JS::NonnullGCPtr<JS::Module> { *record };
module_execution_context->script_or_module = GC::Ref<JS::Module> { *record };
vm().push_execution_context(*module_execution_context);
// 2. Set evaluationPromise to record.Evaluate().

View file

@ -13,7 +13,7 @@ namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/webappapis.html#module-script
class ModuleScript : public Script {
JS_CELL(ModuleScript, Script);
GC_CELL(ModuleScript, Script);
public:
virtual ~ModuleScript() override;
@ -23,13 +23,13 @@ protected:
};
class JavaScriptModuleScript final : public ModuleScript {
JS_CELL(JavaScriptModuleScript, ModuleScript);
JS_DECLARE_ALLOCATOR(JavaScriptModuleScript);
GC_CELL(JavaScriptModuleScript, ModuleScript);
GC_DECLARE_ALLOCATOR(JavaScriptModuleScript);
public:
virtual ~JavaScriptModuleScript() override;
static WebIDL::ExceptionOr<JS::GCPtr<JavaScriptModuleScript>> create(ByteString const& filename, StringView source, JS::Realm&, URL::URL base_url);
static WebIDL::ExceptionOr<GC::Ptr<JavaScriptModuleScript>> create(ByteString const& filename, StringView source, JS::Realm&, URL::URL base_url);
enum class PreventErrorReporting {
Yes,
@ -47,7 +47,7 @@ protected:
private:
virtual void visit_edges(JS::Cell::Visitor&) override;
JS::GCPtr<JS::SourceTextModule> m_record;
GC::Ptr<JS::SourceTextModule> m_record;
size_t m_fetch_internal_request_count { 0 };
size_t m_completed_fetch_internal_request_count { 0 };

View file

@ -9,7 +9,7 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(Script);
GC_DEFINE_ALLOCATOR(Script);
Script::Script(URL::URL base_url, ByteString filename, JS::Realm& realm)
: m_base_url(move(base_url))

View file

@ -18,8 +18,8 @@ namespace Web::HTML {
class Script
: public JS::Cell
, public JS::Script::HostDefined {
JS_CELL(Script, JS::Cell);
JS_DECLARE_ALLOCATOR(Script);
GC_CELL(Script, JS::Cell);
GC_DECLARE_ALLOCATOR(Script);
public:
virtual ~Script() override;
@ -46,7 +46,7 @@ private:
URL::URL m_base_url;
ByteString m_filename;
JS::NonnullGCPtr<JS::Realm> m_realm;
GC::Ref<JS::Realm> m_realm;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-script-parse-error
JS::Value m_parse_error;

View file

@ -6,8 +6,8 @@
#pragma once
#include <LibGC/Ptr.h>
#include <LibJS/Forward.h>
#include <LibJS/Heap/GCPtr.h>
#include <LibWeb/Forward.h>
namespace Web::HTML {
@ -21,15 +21,15 @@ struct SyntheticRealmSettings {
// A principal realm
// The principal realm which this synthetic realm exists within.
JS::NonnullGCPtr<JS::Realm> principal_realm;
GC::Ref<JS::Realm> principal_realm;
// An underlying realm
// The synthetic realm which this settings object represents.
JS::NonnullGCPtr<JS::Realm> underlying_realm;
GC::Ref<JS::Realm> underlying_realm;
// A module map
// A module map that is used when importing JavaScript modules.
JS::NonnullGCPtr<ModuleMap> module_map;
GC::Ref<ModuleMap> module_map;
void visit_edges(JS::Cell::Visitor&);
};

View file

@ -6,7 +6,7 @@
#pragma once
#include <LibJS/Heap/GCPtr.h>
#include <LibGC/Ptr.h>
#include <LibWeb/Forward.h>
namespace Web::HTML {
@ -25,7 +25,7 @@ public:
~TemporaryExecutionContext();
private:
JS::NonnullGCPtr<JS::Realm> m_realm;
GC::Ref<JS::Realm> m_realm;
CallbacksEnabled m_callbacks_enabled { CallbacksEnabled::No };
};

View file

@ -12,7 +12,7 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(WindowEnvironmentSettingsObject);
GC_DEFINE_ALLOCATOR(WindowEnvironmentSettingsObject);
WindowEnvironmentSettingsObject::WindowEnvironmentSettingsObject(Window& window, NonnullOwnPtr<JS::ExecutionContext> execution_context)
: EnvironmentSettingsObject(move(execution_context))
@ -29,7 +29,7 @@ void WindowEnvironmentSettingsObject::visit_edges(JS::Cell::Visitor& visitor)
}
// https://html.spec.whatwg.org/multipage/window-object.html#set-up-a-window-environment-settings-object
void WindowEnvironmentSettingsObject::setup(Page& page, URL::URL const& creation_url, NonnullOwnPtr<JS::ExecutionContext> execution_context, JS::GCPtr<Environment> reserved_environment, URL::URL top_level_creation_url, URL::Origin top_level_origin)
void WindowEnvironmentSettingsObject::setup(Page& page, URL::URL const& creation_url, NonnullOwnPtr<JS::ExecutionContext> execution_context, GC::Ptr<Environment> reserved_environment, URL::URL top_level_creation_url, URL::Origin top_level_origin)
{
// 1. Let realm be the value of execution context's Realm component.
auto realm = execution_context->realm;
@ -83,7 +83,7 @@ void WindowEnvironmentSettingsObject::setup(Page& page, URL::URL const& creation
}
// https://html.spec.whatwg.org/multipage/window-object.html#script-settings-for-window-objects:responsible-document
JS::GCPtr<DOM::Document> WindowEnvironmentSettingsObject::responsible_document()
GC::Ptr<DOM::Document> WindowEnvironmentSettingsObject::responsible_document()
{
// Return window's associated Document.
return m_window->associated_document();

View file

@ -12,15 +12,15 @@
namespace Web::HTML {
class WindowEnvironmentSettingsObject final : public EnvironmentSettingsObject {
JS_CELL(WindowEnvironmentSettingsObject, EnvironmentSettingsObject);
JS_DECLARE_ALLOCATOR(WindowEnvironmentSettingsObject);
GC_CELL(WindowEnvironmentSettingsObject, EnvironmentSettingsObject);
GC_DECLARE_ALLOCATOR(WindowEnvironmentSettingsObject);
public:
static void setup(Page&, URL::URL const& creation_url, NonnullOwnPtr<JS::ExecutionContext>, JS::GCPtr<Environment>, URL::URL top_level_creation_url, URL::Origin top_level_origin);
static void setup(Page&, URL::URL const& creation_url, NonnullOwnPtr<JS::ExecutionContext>, GC::Ptr<Environment>, URL::URL top_level_creation_url, URL::Origin top_level_origin);
virtual ~WindowEnvironmentSettingsObject() override;
virtual JS::GCPtr<DOM::Document> responsible_document() override;
virtual GC::Ptr<DOM::Document> responsible_document() override;
virtual String api_url_character_encoding() override;
virtual URL::URL api_base_url() override;
virtual URL::Origin origin() override;
@ -32,7 +32,7 @@ private:
virtual void visit_edges(JS::Cell::Visitor&) override;
JS::GCPtr<Window> m_window;
GC::Ptr<Window> m_window;
};
}

View file

@ -13,10 +13,10 @@
namespace Web::HTML {
JS_DEFINE_ALLOCATOR(WorkerEnvironmentSettingsObject);
GC_DEFINE_ALLOCATOR(WorkerEnvironmentSettingsObject);
// https://html.spec.whatwg.org/multipage/workers.html#set-up-a-worker-environment-settings-object
JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> WorkerEnvironmentSettingsObject::setup(JS::NonnullGCPtr<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& outside_settings, HighResolutionTime::DOMHighResTimeStamp unsafe_worker_creation_time)
GC::Ref<WorkerEnvironmentSettingsObject> WorkerEnvironmentSettingsObject::setup(GC::Ref<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& outside_settings, HighResolutionTime::DOMHighResTimeStamp unsafe_worker_creation_time)
{
(void)unsafe_worker_creation_time;

View file

@ -14,21 +14,21 @@ namespace Web::HTML {
class WorkerEnvironmentSettingsObject final
: public EnvironmentSettingsObject {
JS_CELL(WorkerEnvironmentSettingsObject, EnvironmentSettingsObject);
JS_DECLARE_ALLOCATOR(WorkerEnvironmentSettingsObject);
GC_CELL(WorkerEnvironmentSettingsObject, EnvironmentSettingsObject);
GC_DECLARE_ALLOCATOR(WorkerEnvironmentSettingsObject);
public:
WorkerEnvironmentSettingsObject(NonnullOwnPtr<JS::ExecutionContext> execution_context, JS::NonnullGCPtr<WorkerGlobalScope> global_scope)
WorkerEnvironmentSettingsObject(NonnullOwnPtr<JS::ExecutionContext> execution_context, GC::Ref<WorkerGlobalScope> global_scope)
: EnvironmentSettingsObject(move(execution_context))
, m_global_scope(global_scope)
{
}
static JS::NonnullGCPtr<WorkerEnvironmentSettingsObject> setup(JS::NonnullGCPtr<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& outside_settings, HighResolutionTime::DOMHighResTimeStamp unsafe_worker_creation_time);
static GC::Ref<WorkerEnvironmentSettingsObject> setup(GC::Ref<Page> page, NonnullOwnPtr<JS::ExecutionContext> execution_context, SerializedEnvironmentSettingsObject const& outside_settings, HighResolutionTime::DOMHighResTimeStamp unsafe_worker_creation_time);
virtual ~WorkerEnvironmentSettingsObject() override = default;
JS::GCPtr<DOM::Document> responsible_document() override { return nullptr; }
GC::Ptr<DOM::Document> responsible_document() override { return nullptr; }
String api_url_character_encoding() override { return m_api_url_character_encoding; }
URL::URL api_base_url() override;
URL::Origin origin() override;
@ -41,7 +41,7 @@ private:
String m_api_url_character_encoding;
URL::Origin m_origin;
JS::NonnullGCPtr<WorkerGlobalScope> m_global_scope;
GC::Ref<WorkerGlobalScope> m_global_scope;
};
}