mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:17:34 +00:00
LibWeb: Make Blob and File GC-allocated
This commit is contained in:
parent
018d236439
commit
647ac1bdba
10 changed files with 77 additions and 61 deletions
|
@ -7,18 +7,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/Bindings/BlobPrototype.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
using BlobPart = Variant<JS::Handle<JS::Object>, NonnullRefPtr<Blob>, String>;
|
||||
using BlobPart = Variant<JS::Handle<JS::Object>, JS::Handle<Blob>, String>;
|
||||
|
||||
struct BlobPropertyBag {
|
||||
String type = String::empty();
|
||||
|
@ -29,26 +27,22 @@ struct BlobPropertyBag {
|
|||
[[nodiscard]] ErrorOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts, Optional<BlobPropertyBag> const& options = {});
|
||||
[[nodiscard]] bool is_basic_latin(StringView view);
|
||||
|
||||
class Blob
|
||||
: public RefCounted<Blob>
|
||||
, public Weakable<Blob>
|
||||
, public Bindings::Wrappable {
|
||||
class Blob : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(Blob, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
using WrapperType = Bindings::BlobWrapper;
|
||||
Blob(ByteBuffer byte_buffer, String type);
|
||||
|
||||
virtual ~Blob() override;
|
||||
|
||||
static DOM::ExceptionOr<NonnullRefPtr<Blob>> create(Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||
static DOM::ExceptionOr<NonnullRefPtr<Blob>> create_with_global_object(HTML::Window&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||
static DOM::ExceptionOr<JS::NonnullGCPtr<Blob>> create(HTML::Window&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
|
||||
static DOM::ExceptionOr<JS::NonnullGCPtr<Blob>> create(HTML::Window&, ByteBuffer, String type);
|
||||
static DOM::ExceptionOr<JS::NonnullGCPtr<Blob>> create_with_global_object(HTML::Window&, 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; }
|
||||
|
||||
DOM::ExceptionOr<NonnullRefPtr<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {});
|
||||
DOM::ExceptionOr<JS::NonnullGCPtr<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {});
|
||||
|
||||
JS::Promise* text();
|
||||
JS::Promise* array_buffer();
|
||||
|
@ -56,13 +50,16 @@ public:
|
|||
ReadonlyBytes bytes() const { return m_byte_buffer.bytes(); }
|
||||
|
||||
protected:
|
||||
Blob(ByteBuffer byte_buffer);
|
||||
Blob(HTML::Window&, ByteBuffer, String type);
|
||||
Blob(HTML::Window&, ByteBuffer);
|
||||
|
||||
private:
|
||||
Blob() = default;
|
||||
explicit Blob(HTML::Window&);
|
||||
|
||||
ByteBuffer m_byte_buffer {};
|
||||
String m_type {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
WRAPPER_HACK(Blob, Web::FileAPI)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue