1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

LibWeb: Port IDL implementations Blob and File to new String

This commit is contained in:
Kenneth Myhra 2023-02-25 10:27:38 +01:00 committed by Linus Groh
parent 31a9bd2bfd
commit 9a5a8d617d
10 changed files with 63 additions and 52 deletions

View file

@ -1,12 +1,11 @@
/*
* Copyright (c) 2022, Kenneth Myhra <kennethmyhra@serenityos.org>
* Copyright (c) 2022-2023, Kenneth Myhra <kennethmyhra@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Vector.h>
#include <LibWeb/Bindings/BlobPrototype.h>
@ -16,14 +15,14 @@
namespace Web::FileAPI {
using BlobPart = Variant<JS::Handle<JS::Object>, JS::Handle<Blob>, DeprecatedString>;
using BlobPart = Variant<JS::Handle<JS::Object>, JS::Handle<Blob>, String>;
struct BlobPropertyBag {
DeprecatedString type = DeprecatedString::empty();
String type = String {};
Bindings::EndingType endings;
};
[[nodiscard]] ErrorOr<DeprecatedString> convert_line_endings_to_native(DeprecatedString const& string);
[[nodiscard]] ErrorOr<String> convert_line_endings_to_native(StringView string);
[[nodiscard]] ErrorOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts, Optional<BlobPropertyBag> const& options = {});
[[nodiscard]] bool is_basic_latin(StringView view);
@ -33,24 +32,24 @@ class Blob : public Bindings::PlatformObject {
public:
virtual ~Blob() override;
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> create(JS::Realm&, ByteBuffer, DeprecatedString type);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> create(JS::Realm&, ByteBuffer, String type);
static WebIDL::ExceptionOr<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 = {});
// https://w3c.github.io/FileAPI/#dfn-size
u64 size() const { return m_byte_buffer.size(); }
// https://w3c.github.io/FileAPI/#dfn-type
DeprecatedString const& type() const { return m_type; }
String const& type() const { return m_type; }
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<DeprecatedString> const& content_type = {});
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {});
JS::Promise* text();
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> text();
JS::Promise* array_buffer();
ReadonlyBytes bytes() const { return m_byte_buffer.bytes(); }
protected:
Blob(JS::Realm&, ByteBuffer, DeprecatedString type);
Blob(JS::Realm&, ByteBuffer, String type);
Blob(JS::Realm&, ByteBuffer);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
@ -59,7 +58,7 @@ private:
explicit Blob(JS::Realm&);
ByteBuffer m_byte_buffer {};
DeprecatedString m_type {};
String m_type {};
};
}