mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 22:38:51 +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);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
using BlobPart = Variant<JS::Handle<WebIDL::BufferSource>, JS::Handle<Blob>, String>;
|
||||
using BlobPart = Variant<GC::Root<WebIDL::BufferSource>, GC::Root<Blob>, String>;
|
||||
|
||||
struct BlobPropertyBag {
|
||||
String type = String {};
|
||||
|
@ -31,30 +31,30 @@ class Blob
|
|||
: public Bindings::PlatformObject
|
||||
, public Bindings::Serializable {
|
||||
WEB_PLATFORM_OBJECT(Blob, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(Blob);
|
||||
GC_DECLARE_ALLOCATOR(Blob);
|
||||
|
||||
public:
|
||||
virtual ~Blob() override;
|
||||
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Blob> create(JS::Realm&, ByteBuffer, String type);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<Blob> create(JS::Realm&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> construct_impl(JS::Realm&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||
[[nodiscard]] static GC::Ref<Blob> create(JS::Realm&, ByteBuffer, String type);
|
||||
[[nodiscard]] static GC::Ref<Blob> create(JS::Realm&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||
static WebIDL::ExceptionOr<GC::Ref<Blob>> construct_impl(JS::Realm&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dfn-size
|
||||
u64 size() const { return m_byte_buffer.size(); }
|
||||
// https://w3c.github.io/FileAPI/#dfn-type
|
||||
String const& type() const { return m_type; }
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {});
|
||||
WebIDL::ExceptionOr<GC::Ref<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {});
|
||||
|
||||
JS::NonnullGCPtr<Streams::ReadableStream> stream();
|
||||
JS::NonnullGCPtr<WebIDL::Promise> text();
|
||||
JS::NonnullGCPtr<WebIDL::Promise> array_buffer();
|
||||
JS::NonnullGCPtr<WebIDL::Promise> bytes();
|
||||
GC::Ref<Streams::ReadableStream> stream();
|
||||
GC::Ref<WebIDL::Promise> text();
|
||||
GC::Ref<WebIDL::Promise> array_buffer();
|
||||
GC::Ref<WebIDL::Promise> bytes();
|
||||
|
||||
ReadonlyBytes raw_bytes() const { return m_byte_buffer.bytes(); }
|
||||
|
||||
JS::NonnullGCPtr<Streams::ReadableStream> get_stream();
|
||||
GC::Ref<Streams::ReadableStream> get_stream();
|
||||
|
||||
virtual StringView interface_name() const override { return "Blob"sv; }
|
||||
|
||||
|
@ -67,7 +67,7 @@ protected:
|
|||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> slice_blob(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {});
|
||||
WebIDL::ExceptionOr<GC::Ref<Blob>> slice_blob(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {});
|
||||
|
||||
ByteBuffer m_byte_buffer {};
|
||||
String m_type {};
|
||||
|
|
|
@ -60,7 +60,7 @@ ErrorOr<String> generate_new_blob_url()
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#add-an-entry
|
||||
ErrorOr<String> add_entry_to_blob_url_store(JS::NonnullGCPtr<Blob> object)
|
||||
ErrorOr<String> add_entry_to_blob_url_store(GC::Ref<Blob> object)
|
||||
{
|
||||
// 1. Let store be the user agent’s blob URL store.
|
||||
auto& store = blob_url_store();
|
||||
|
@ -93,7 +93,7 @@ ErrorOr<void> remove_entry_from_blob_url_store(StringView url)
|
|||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#lifeTime
|
||||
void run_unloading_cleanup_steps(JS::NonnullGCPtr<DOM::Document> document)
|
||||
void run_unloading_cleanup_steps(GC::Ref<DOM::Document> document)
|
||||
{
|
||||
// 1. Let environment be the Document's relevant settings object.
|
||||
auto& environment = document->relevant_settings_object();
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibJS/Heap/Handle.h>
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibGC/Root.h>
|
||||
#include <LibURL/Forward.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
|
@ -17,8 +17,8 @@ namespace Web::FileAPI {
|
|||
|
||||
// https://w3c.github.io/FileAPI/#blob-url-entry
|
||||
struct BlobURLEntry {
|
||||
JS::Handle<Blob> object; // FIXME: This could also be a MediaSource after we implement MSE.
|
||||
JS::Handle<HTML::EnvironmentSettingsObject> environment;
|
||||
GC::Root<Blob> object; // FIXME: This could also be a MediaSource after we implement MSE.
|
||||
GC::Root<HTML::EnvironmentSettingsObject> environment;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/FileAPI/#BlobURLStore
|
||||
|
@ -26,10 +26,10 @@ using BlobURLStore = HashMap<String, BlobURLEntry>;
|
|||
|
||||
BlobURLStore& blob_url_store();
|
||||
ErrorOr<String> generate_new_blob_url();
|
||||
ErrorOr<String> add_entry_to_blob_url_store(JS::NonnullGCPtr<Blob> object);
|
||||
ErrorOr<String> add_entry_to_blob_url_store(GC::Ref<Blob> object);
|
||||
ErrorOr<void> remove_entry_from_blob_url_store(StringView url);
|
||||
Optional<BlobURLEntry> resolve_a_blob_url(URL::URL const&);
|
||||
|
||||
void run_unloading_cleanup_steps(JS::NonnullGCPtr<DOM::Document>);
|
||||
void run_unloading_cleanup_steps(GC::Ref<DOM::Document>);
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(File);
|
||||
GC_DEFINE_ALLOCATOR(File);
|
||||
|
||||
File::File(JS::Realm& realm, ByteBuffer byte_buffer, String file_name, String type, i64 last_modified)
|
||||
: Blob(realm, move(byte_buffer), move(type))
|
||||
|
@ -36,13 +36,13 @@ void File::initialize(JS::Realm& realm)
|
|||
|
||||
File::~File() = default;
|
||||
|
||||
JS::NonnullGCPtr<File> File::create(JS::Realm& realm)
|
||||
GC::Ref<File> File::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.create<File>(realm);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#ref-for-dom-file-file
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> File::create(JS::Realm& realm, Vector<BlobPart> const& file_bits, String const& file_name, Optional<FilePropertyBag> const& options)
|
||||
WebIDL::ExceptionOr<GC::Ref<File>> File::create(JS::Realm& realm, Vector<BlobPart> const& file_bits, String const& file_name, Optional<FilePropertyBag> const& options)
|
||||
{
|
||||
auto& vm = realm.vm();
|
||||
|
||||
|
@ -82,7 +82,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> File::create(JS::Realm& realm, Vecto
|
|||
return realm.create<File>(realm, move(bytes), move(name), move(type), last_modified);
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> File::construct_impl(JS::Realm& realm, Vector<BlobPart> const& file_bits, String const& file_name, Optional<FilePropertyBag> const& options)
|
||||
WebIDL::ExceptionOr<GC::Ref<File>> File::construct_impl(JS::Realm& realm, Vector<BlobPart> const& file_bits, String const& file_name, Optional<FilePropertyBag> const& options)
|
||||
{
|
||||
return create(realm, file_bits, file_name, options);
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@ struct FilePropertyBag : BlobPropertyBag {
|
|||
|
||||
class File : public Blob {
|
||||
WEB_PLATFORM_OBJECT(File, Blob);
|
||||
JS_DECLARE_ALLOCATOR(File);
|
||||
GC_DECLARE_ALLOCATOR(File);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<File> create(JS::Realm& realm);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> create(JS::Realm&, Vector<BlobPart> const& file_bits, String const& file_name, Optional<FilePropertyBag> const& options = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> construct_impl(JS::Realm&, Vector<BlobPart> const& file_bits, String const& file_name, Optional<FilePropertyBag> const& options = {});
|
||||
static GC::Ref<File> create(JS::Realm& realm);
|
||||
static WebIDL::ExceptionOr<GC::Ref<File>> create(JS::Realm&, Vector<BlobPart> const& file_bits, String const& file_name, Optional<FilePropertyBag> const& options = {});
|
||||
static WebIDL::ExceptionOr<GC::Ref<File>> construct_impl(JS::Realm&, Vector<BlobPart> const& file_bits, String const& file_name, Optional<FilePropertyBag> const& options = {});
|
||||
|
||||
virtual ~File() override;
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(FileList);
|
||||
GC_DEFINE_ALLOCATOR(FileList);
|
||||
|
||||
JS::NonnullGCPtr<FileList> FileList::create(JS::Realm& realm)
|
||||
GC::Ref<FileList> FileList::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.create<FileList>(realm);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/FileAPI/File.h>
|
||||
#include <LibWeb/WebIDL/Types.h>
|
||||
|
@ -19,12 +19,12 @@ class FileList
|
|||
: public Bindings::PlatformObject
|
||||
, public Bindings::Serializable {
|
||||
WEB_PLATFORM_OBJECT(FileList, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(FileList);
|
||||
GC_DECLARE_ALLOCATOR(FileList);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<FileList> create(JS::Realm&);
|
||||
[[nodiscard]] static GC::Ref<FileList> create(JS::Realm&);
|
||||
|
||||
void add_file(JS::NonnullGCPtr<File> file) { m_files.append(file); }
|
||||
void add_file(GC::Ref<File> file) { m_files.append(file); }
|
||||
|
||||
virtual ~FileList() override;
|
||||
|
||||
|
@ -55,7 +55,7 @@ private:
|
|||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Vector<JS::NonnullGCPtr<File>> m_files;
|
||||
Vector<GC::Ref<File>> m_files;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <AK/Base64.h>
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Time.h>
|
||||
#include <LibJS/Heap/Heap.h>
|
||||
#include <LibGC/Heap.h>
|
||||
#include <LibJS/Runtime/Promise.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibJS/Runtime/TypedArray.h>
|
||||
|
@ -32,7 +32,7 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(FileReader);
|
||||
GC_DEFINE_ALLOCATOR(FileReader);
|
||||
|
||||
FileReader::~FileReader() = default;
|
||||
|
||||
|
@ -53,12 +53,12 @@ void FileReader::visit_edges(JS::Cell::Visitor& visitor)
|
|||
visitor.visit(m_error);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<FileReader> FileReader::create(JS::Realm& realm)
|
||||
GC::Ref<FileReader> FileReader::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.create<FileReader>(realm);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<FileReader> FileReader::construct_impl(JS::Realm& realm)
|
||||
GC::Ref<FileReader> FileReader::construct_impl(JS::Realm& realm)
|
||||
{
|
||||
return FileReader::create(realm);
|
||||
}
|
||||
|
@ -146,25 +146,25 @@ WebIDL::ExceptionOr<void> FileReader::read_operation(Blob& blob, Type type, Opti
|
|||
bool is_first_chunk = true;
|
||||
|
||||
// 10. In parallel, while true:
|
||||
Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(heap(), [this, chunk_promise, reader, bytes, is_first_chunk, &realm, type, encoding_name, blobs_type]() mutable {
|
||||
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(heap(), [this, chunk_promise, reader, bytes, is_first_chunk, &realm, type, encoding_name, blobs_type]() mutable {
|
||||
HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
Optional<MonotonicTime> progress_timer;
|
||||
|
||||
while (true) {
|
||||
auto& vm = realm.vm();
|
||||
// FIXME: Try harder to not reach into the [[Promise]] slot of chunkPromise
|
||||
auto promise = JS::NonnullGCPtr { verify_cast<JS::Promise>(*chunk_promise->promise()) };
|
||||
auto promise = GC::Ref { verify_cast<JS::Promise>(*chunk_promise->promise()) };
|
||||
|
||||
// 1. Wait for chunkPromise to be fulfilled or rejected.
|
||||
// FIXME: Create spec issue to use WebIDL react to promise steps here instead of this custom logic
|
||||
Platform::EventLoopPlugin::the().spin_until(JS::create_heap_function(heap(), [promise]() {
|
||||
Platform::EventLoopPlugin::the().spin_until(GC::create_function(heap(), [promise]() {
|
||||
return promise->state() == JS::Promise::State::Fulfilled || promise->state() == JS::Promise::State::Rejected;
|
||||
}));
|
||||
|
||||
// 2. If chunkPromise is fulfilled, and isFirstChunk is true, queue a task to fire a progress event called loadstart at fr.
|
||||
// NOTE: ISSUE 2 We might change loadstart to be dispatched synchronously, to align with XMLHttpRequest behavior. [Issue #119]
|
||||
if (promise->state() == JS::Promise::State::Fulfilled && is_first_chunk) {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), JS::create_heap_function(heap(), [this, &realm]() {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), GC::create_function(heap(), [this, &realm]() {
|
||||
dispatch_event(DOM::Event::create(realm, HTML::EventNames::loadstart));
|
||||
}));
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ WebIDL::ExceptionOr<void> FileReader::read_operation(Blob& blob, Type type, Opti
|
|||
// See http://wpt.live/FileAPI/reading-data-section/filereader_events.any.html
|
||||
bool contained_data = byte_sequence.array_length().length() > 0;
|
||||
if (enough_time_passed && contained_data) {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), JS::create_heap_function(heap(), [this, &realm]() {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), GC::create_function(heap(), [this, &realm]() {
|
||||
dispatch_event(DOM::Event::create(realm, HTML::EventNames::progress));
|
||||
}));
|
||||
progress_timer = now;
|
||||
|
@ -204,7 +204,7 @@ WebIDL::ExceptionOr<void> FileReader::read_operation(Blob& blob, Type type, Opti
|
|||
}
|
||||
// 5. Otherwise, if chunkPromise is fulfilled with an object whose done property is true, queue a task to run the following steps and abort this algorithm:
|
||||
else if (promise->state() == JS::Promise::State::Fulfilled && done.as_bool()) {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), JS::create_heap_function(heap(), [this, bytes, type, &realm, encoding_name, blobs_type]() {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), GC::create_function(heap(), [this, bytes, type, &realm, encoding_name, blobs_type]() {
|
||||
// 1. Set fr’s state to "done".
|
||||
m_state = State::Done;
|
||||
|
||||
|
@ -238,7 +238,7 @@ WebIDL::ExceptionOr<void> FileReader::read_operation(Blob& blob, Type type, Opti
|
|||
}
|
||||
// 6. Otherwise, if chunkPromise is rejected with an error error, queue a task to run the following steps and abort this algorithm:
|
||||
else if (promise->state() == JS::Promise::State::Rejected) {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), JS::create_heap_function(heap(), [this, &realm]() {
|
||||
HTML::queue_global_task(HTML::Task::Source::FileReading, realm.global_object(), GC::create_function(heap(), [this, &realm]() {
|
||||
// 1. Set fr’s state to "done".
|
||||
m_state = State::Done;
|
||||
|
||||
|
|
|
@ -17,15 +17,15 @@ namespace Web::FileAPI {
|
|||
// https://w3c.github.io/FileAPI/#dfn-filereader
|
||||
class FileReader : public DOM::EventTarget {
|
||||
WEB_PLATFORM_OBJECT(FileReader, DOM::EventTarget);
|
||||
JS_DECLARE_ALLOCATOR(FileReader);
|
||||
GC_DECLARE_ALLOCATOR(FileReader);
|
||||
|
||||
public:
|
||||
using Result = Variant<Empty, String, JS::Handle<JS::ArrayBuffer>>;
|
||||
using Result = Variant<Empty, String, GC::Root<JS::ArrayBuffer>>;
|
||||
|
||||
virtual ~FileReader() override;
|
||||
|
||||
[[nodiscard]] static JS::NonnullGCPtr<FileReader> create(JS::Realm&);
|
||||
static JS::NonnullGCPtr<FileReader> construct_impl(JS::Realm&);
|
||||
[[nodiscard]] static GC::Ref<FileReader> create(JS::Realm&);
|
||||
static GC::Ref<FileReader> construct_impl(JS::Realm&);
|
||||
|
||||
// async read methods
|
||||
WebIDL::ExceptionOr<void> read_as_array_buffer(Blob&);
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
Result result() const { return m_result; }
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dom-filereader-error
|
||||
JS::GCPtr<WebIDL::DOMException> error() const { return m_error; }
|
||||
GC::Ptr<WebIDL::DOMException> error() const { return m_error; }
|
||||
|
||||
// event handler attributes
|
||||
void set_onloadstart(WebIDL::CallbackType*);
|
||||
|
@ -111,7 +111,7 @@ private:
|
|||
|
||||
// A FileReader has an associated error (null or a DOMException). It is initially null.
|
||||
// https://w3c.github.io/FileAPI/#filereader-error
|
||||
JS::GCPtr<WebIDL::DOMException> m_error;
|
||||
GC::Ptr<WebIDL::DOMException> m_error;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue