mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-22 18:22:07 +00:00
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:
parent
ce23efc5f6
commit
f87041bf3a
Notes:
github-actions[bot]
2024-11-15 13:50:17 +00:00
Author: https://github.com/shannonbooth
Commit: f87041bf3a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2345
1722 changed files with 9939 additions and 9906 deletions
|
@ -26,9 +26,9 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(Blob);
|
||||
GC_DEFINE_ALLOCATOR(Blob);
|
||||
|
||||
JS::NonnullGCPtr<Blob> Blob::create(JS::Realm& realm, ByteBuffer byte_buffer, String type)
|
||||
GC::Ref<Blob> Blob::create(JS::Realm& realm, ByteBuffer byte_buffer, String type)
|
||||
{
|
||||
return realm.create<Blob>(realm, move(byte_buffer), move(type));
|
||||
}
|
||||
|
@ -103,12 +103,12 @@ ErrorOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts, Optio
|
|||
return bytes.try_append(s.bytes());
|
||||
},
|
||||
// 2. If element is a BufferSource, get a copy of the bytes held by the buffer source, and append those bytes to bytes.
|
||||
[&](JS::Handle<WebIDL::BufferSource> const& buffer_source) -> ErrorOr<void> {
|
||||
[&](GC::Root<WebIDL::BufferSource> const& buffer_source) -> ErrorOr<void> {
|
||||
auto data_buffer = TRY(WebIDL::get_buffer_source_copy(*buffer_source->raw_object()));
|
||||
return bytes.try_append(data_buffer.bytes());
|
||||
},
|
||||
// 3. If element is a Blob, append the bytes it represents to bytes.
|
||||
[&](JS::Handle<Blob> const& blob) -> ErrorOr<void> {
|
||||
[&](GC::Root<Blob> const& blob) -> ErrorOr<void> {
|
||||
return bytes.try_append(blob->raw_bytes());
|
||||
}));
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ WebIDL::ExceptionOr<void> Blob::deserialization_steps(ReadonlySpan<u32> const& r
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#ref-for-dom-blob-blob
|
||||
JS::NonnullGCPtr<Blob> Blob::create(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
||||
GC::Ref<Blob> Blob::create(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
||||
{
|
||||
// 1. If invoked with zero parameters, return a new Blob object consisting of 0 bytes, with size set to 0, and with type set to the empty string.
|
||||
if (!blob_parts.has_value() && !options.has_value())
|
||||
|
@ -216,13 +216,13 @@ JS::NonnullGCPtr<Blob> Blob::create(JS::Realm& realm, Optional<Vector<BlobPart>>
|
|||
return realm.create<Blob>(realm, move(byte_buffer), move(type));
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::construct_impl(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
||||
WebIDL::ExceptionOr<GC::Ref<Blob>> Blob::construct_impl(JS::Realm& realm, Optional<Vector<BlobPart>> const& blob_parts, Optional<BlobPropertyBag> const& options)
|
||||
{
|
||||
return Blob::create(realm, blob_parts, options);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dfn-slice
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::slice(Optional<i64> start, Optional<i64> end, Optional<String> const& content_type)
|
||||
WebIDL::ExceptionOr<GC::Ref<Blob>> Blob::slice(Optional<i64> start, Optional<i64> end, Optional<String> const& content_type)
|
||||
{
|
||||
// 1. Let sliceStart, sliceEnd, and sliceContentType be null.
|
||||
// 2. If start is given, set sliceStart to start.
|
||||
|
@ -233,7 +233,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::slice(Optional<i64> start, Opt
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#slice-blob
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::slice_blob(Optional<i64> start, Optional<i64> end, Optional<String> const& content_type)
|
||||
WebIDL::ExceptionOr<GC::Ref<Blob>> Blob::slice_blob(Optional<i64> start, Optional<i64> end, Optional<String> const& content_type)
|
||||
{
|
||||
auto& vm = realm().vm();
|
||||
|
||||
|
@ -309,14 +309,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::slice_blob(Optional<i64> start
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dom-blob-stream
|
||||
JS::NonnullGCPtr<Streams::ReadableStream> Blob::stream()
|
||||
GC::Ref<Streams::ReadableStream> Blob::stream()
|
||||
{
|
||||
// The stream() method, when invoked, must return the result of calling get stream on this.
|
||||
return get_stream();
|
||||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#blob-get-stream
|
||||
JS::NonnullGCPtr<Streams::ReadableStream> Blob::get_stream()
|
||||
GC::Ref<Streams::ReadableStream> Blob::get_stream()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
|
@ -335,7 +335,7 @@ JS::NonnullGCPtr<Streams::ReadableStream> Blob::get_stream()
|
|||
auto bytes = m_byte_buffer;
|
||||
|
||||
// 2. Queue a global task on the file reading task source given blob’s relevant global object to perform the following steps:
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), JS::create_heap_function(heap(), [stream, bytes = move(bytes)]() {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), GC::create_function(heap(), [stream, bytes = move(bytes)]() {
|
||||
// NOTE: Using an TemporaryExecutionContext here results in a crash in the method HTML::incumbent_realm()
|
||||
// since we end up in a state where we have no execution context + an event loop with an empty incumbent
|
||||
// realm stack. We still need an execution context therefore we push the realm's execution context
|
||||
|
@ -378,7 +378,7 @@ JS::NonnullGCPtr<Streams::ReadableStream> Blob::get_stream()
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dom-blob-text
|
||||
JS::NonnullGCPtr<WebIDL::Promise> Blob::text()
|
||||
GC::Ref<WebIDL::Promise> Blob::text()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
auto& vm = realm.vm();
|
||||
|
@ -396,7 +396,7 @@ JS::NonnullGCPtr<WebIDL::Promise> Blob::text()
|
|||
auto promise = reader->read_all_bytes_deprecated();
|
||||
|
||||
// 4. Return the result of transforming promise by a fulfillment handler that returns the result of running UTF-8 decode on its first argument.
|
||||
return WebIDL::upon_fulfillment(*promise, JS::create_heap_function(heap(), [&vm](JS::Value first_argument) -> WebIDL::ExceptionOr<JS::Value> {
|
||||
return WebIDL::upon_fulfillment(*promise, GC::create_function(heap(), [&vm](JS::Value first_argument) -> WebIDL::ExceptionOr<JS::Value> {
|
||||
auto const& object = first_argument.as_object();
|
||||
VERIFY(is<JS::ArrayBuffer>(object));
|
||||
auto const& buffer = static_cast<const JS::ArrayBuffer&>(object).buffer();
|
||||
|
@ -408,7 +408,7 @@ JS::NonnullGCPtr<WebIDL::Promise> Blob::text()
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dom-blob-arraybuffer
|
||||
JS::NonnullGCPtr<WebIDL::Promise> Blob::array_buffer()
|
||||
GC::Ref<WebIDL::Promise> Blob::array_buffer()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
|
@ -425,7 +425,7 @@ JS::NonnullGCPtr<WebIDL::Promise> Blob::array_buffer()
|
|||
auto promise = reader->read_all_bytes_deprecated();
|
||||
|
||||
// 4. Return the result of transforming promise by a fulfillment handler that returns a new ArrayBuffer whose contents are its first argument.
|
||||
return WebIDL::upon_fulfillment(*promise, JS::create_heap_function(heap(), [&realm](JS::Value first_argument) -> WebIDL::ExceptionOr<JS::Value> {
|
||||
return WebIDL::upon_fulfillment(*promise, GC::create_function(heap(), [&realm](JS::Value first_argument) -> WebIDL::ExceptionOr<JS::Value> {
|
||||
auto const& object = first_argument.as_object();
|
||||
VERIFY(is<JS::ArrayBuffer>(object));
|
||||
auto const& buffer = static_cast<const JS::ArrayBuffer&>(object).buffer();
|
||||
|
@ -435,7 +435,7 @@ JS::NonnullGCPtr<WebIDL::Promise> Blob::array_buffer()
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dom-blob-bytes
|
||||
JS::NonnullGCPtr<WebIDL::Promise> Blob::bytes()
|
||||
GC::Ref<WebIDL::Promise> Blob::bytes()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
|
@ -452,7 +452,7 @@ JS::NonnullGCPtr<WebIDL::Promise> Blob::bytes()
|
|||
auto promise = reader->read_all_bytes_deprecated();
|
||||
|
||||
// 4. Return the result of transforming promise by a fulfillment handler that returns a new Uint8Array wrapping an ArrayBuffer containing its first argument.
|
||||
return WebIDL::upon_fulfillment(*promise, JS::create_heap_function(heap(), [&realm](JS::Value first_argument) -> WebIDL::ExceptionOr<JS::Value> {
|
||||
return WebIDL::upon_fulfillment(*promise, GC::create_function(heap(), [&realm](JS::Value first_argument) -> WebIDL::ExceptionOr<JS::Value> {
|
||||
auto& object = first_argument.as_object();
|
||||
VERIFY(is<JS::ArrayBuffer>(object));
|
||||
auto& array_buffer = static_cast<JS::ArrayBuffer&>(object);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue