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

@ -5,10 +5,10 @@
*/
#include <LibCore/Promise.h>
#include <LibGC/Heap.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/Font/WOFF/Loader.h>
#include <LibGfx/Font/WOFF2/Loader.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/FontFacePrototype.h>
@ -31,7 +31,7 @@ static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> load_vector_fo
// FIXME: 'Asynchronously' shouldn't mean 'later on the main thread'.
// Can we defer this to a background thread?
Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&data, promise] {
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(realm.heap(), [&data, promise] {
// FIXME: This should be de-duplicated with StyleComputer::FontLoader::try_load_font
// We don't have the luxury of knowing the MIME type, so we have to try all formats.
auto ttf = Gfx::Typeface::try_load_from_externally_owned_memory(data);
@ -55,7 +55,7 @@ static NonnullRefPtr<Core::Promise<NonnullRefPtr<Gfx::Typeface>>> load_vector_fo
return promise;
}
JS_DEFINE_ALLOCATOR(FontFace);
GC_DEFINE_ALLOCATOR(FontFace);
template<CSS::PropertyID PropertyID>
RefPtr<CSSStyleValue const> parse_property_string(JS::Realm& realm, StringView value)
@ -65,7 +65,7 @@ RefPtr<CSSStyleValue const> parse_property_string(JS::Realm& realm, StringView v
}
// https://drafts.csswg.org/css-font-loading/#font-face-constructor
JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String family, FontFaceSource source, FontFaceDescriptors const& descriptors)
GC::Ref<FontFace> FontFace::construct_impl(JS::Realm& realm, String family, FontFaceSource source, FontFaceDescriptors const& descriptors)
{
auto& vm = realm.vm();
auto base_url = HTML::relevant_settings_object(realm.global_object()).api_base_url();
@ -93,7 +93,7 @@ JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String fam
if (sources.is_empty())
WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid source string"_string));
} else {
auto buffer_source = source.get<JS::Handle<WebIDL::BufferSource>>();
auto buffer_source = source.get<GC::Root<WebIDL::BufferSource>>();
auto maybe_buffer = WebIDL::get_buffer_source_copy(buffer_source->raw_object());
if (maybe_buffer.is_error()) {
VERIFY(maybe_buffer.error().code() == ENOMEM);
@ -118,7 +118,7 @@ JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String fam
if (font->m_binary_data.is_empty())
return font;
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(vm.heap(), [&realm, font] {
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), GC::create_function(vm.heap(), [&realm, font] {
// 1. Set font faces status attribute to "loading".
font->m_status = Bindings::FontFaceLoadStatus::Loading;
@ -128,8 +128,8 @@ JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String fam
// When this is completed, successfully or not, queue a task to run the following steps synchronously:
font->m_font_load_promise = load_vector_font(realm, font->m_binary_data);
font->m_font_load_promise->when_resolved([font = JS::make_handle(font)](auto const& vector_font) -> ErrorOr<void> {
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(font->heap(), [font = JS::NonnullGCPtr(*font), vector_font] {
font->m_font_load_promise->when_resolved([font = GC::make_root(font)](auto const& vector_font) -> ErrorOr<void> {
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), GC::create_function(font->heap(), [font = GC::Ref(*font), vector_font] {
HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
// 1. If the load was successful, font face now represents the parsed font;
// fulfill font faces [[FontStatusPromise]] with font face, and set its status attribute to "loaded".
@ -145,8 +145,8 @@ JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String fam
}));
return {};
});
font->m_font_load_promise->when_rejected([font = JS::make_handle(font)](auto const& error) {
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(font->heap(), [font = JS::NonnullGCPtr(*font), error = Error::copy(error)] {
font->m_font_load_promise->when_rejected([font = GC::make_root(font)](auto const& error) {
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), GC::create_function(font->heap(), [font = GC::Ref(*font), error = Error::copy(error)] {
HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
// 2. Otherwise, reject font faces [[FontStatusPromise]] with a DOMException named "SyntaxError"
// and set font faces status attribute to "error".
@ -163,7 +163,7 @@ JS::NonnullGCPtr<FontFace> FontFace::construct_impl(JS::Realm& realm, String fam
return font;
}
FontFace::FontFace(JS::Realm& realm, JS::NonnullGCPtr<WebIDL::Promise> font_status_promise, Vector<ParsedFontFace::Source> urls, ByteBuffer data, String font_family, FontFaceDescriptors const& descriptors)
FontFace::FontFace(JS::Realm& realm, GC::Ref<WebIDL::Promise> font_status_promise, Vector<ParsedFontFace::Source> urls, ByteBuffer data, String font_family, FontFaceDescriptors const& descriptors)
: Bindings::PlatformObject(realm)
, m_font_status_promise(font_status_promise)
, m_urls(move(urls))
@ -205,7 +205,7 @@ void FontFace::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(m_font_status_promise);
}
JS::NonnullGCPtr<WebIDL::Promise> FontFace::loaded() const
GC::Ref<WebIDL::Promise> FontFace::loaded() const
{
return m_font_status_promise;
}
@ -320,7 +320,7 @@ WebIDL::ExceptionOr<void> FontFace::set_line_gap_override(String const&)
}
// https://drafts.csswg.org/css-font-loading/#dom-fontface-load
JS::NonnullGCPtr<WebIDL::Promise> FontFace::load()
GC::Ref<WebIDL::Promise> FontFace::load()
{
// 1. Let font face be the FontFace object on which this method was called.
auto& font_face = *this;
@ -349,13 +349,13 @@ void FontFace::load_font_source()
// and continue executing the rest of this algorithm asynchronously.
m_status = Bindings::FontFaceLoadStatus::Loading;
Web::Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(heap(), [font = JS::make_handle(this)] {
Web::Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(heap(), [font = GC::make_root(this)] {
// 4. Using the value of font faces [[Urls]] slot, attempt to load a font as defined in [CSS-FONTS-3],
// as if it was the value of a @font-face rules src descriptor.
// 5. When the load operation completes, successfully or not, queue a task to run the following steps synchronously:
auto on_error = [font] {
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(font->heap(), [font = JS::NonnullGCPtr(*font)] {
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), GC::create_function(font->heap(), [font = GC::Ref(*font)] {
HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
// 1. If the attempt to load fails, reject font faces [[FontStatusPromise]] with a DOMException whose name
@ -369,7 +369,7 @@ void FontFace::load_font_source()
auto on_load = [font](FontLoader const& loader) {
// FIXME: We are assuming that the font loader will live as long as the document! This is an unsafe capture
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(font->heap(), [font = JS::NonnullGCPtr(*font), &loader] {
HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), GC::create_function(font->heap(), [font = GC::Ref(*font), &loader] {
HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
// 2. Otherwise, font face now represents the loaded font; fulfill font faces [[FontStatusPromise]] with font face