mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 02:38:13 +00:00
AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
This commit is contained in:
parent
f74251606d
commit
6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions
|
@ -14,13 +14,13 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
JS::NonnullGCPtr<Blob> Blob::create(JS::Realm& realm, ByteBuffer byte_buffer, String type)
|
||||
JS::NonnullGCPtr<Blob> Blob::create(JS::Realm& realm, ByteBuffer byte_buffer, DeprecatedString type)
|
||||
{
|
||||
return JS::NonnullGCPtr(*realm.heap().allocate<Blob>(realm, realm, move(byte_buffer), move(type)));
|
||||
}
|
||||
|
||||
// https://w3c.github.io/FileAPI/#convert-line-endings-to-native
|
||||
ErrorOr<String> convert_line_endings_to_native(String const& string)
|
||||
ErrorOr<DeprecatedString> convert_line_endings_to_native(DeprecatedString const& string)
|
||||
{
|
||||
// 1. Let native line ending be be the code point U+000A LF.
|
||||
auto native_line_ending = "\n"sv;
|
||||
|
@ -76,7 +76,7 @@ ErrorOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts, Optio
|
|||
for (auto const& blob_part : blob_parts) {
|
||||
TRY(blob_part.visit(
|
||||
// 1. If element is a USVString, run the following sub-steps:
|
||||
[&](String const& string) -> ErrorOr<void> {
|
||||
[&](DeprecatedString const& string) -> ErrorOr<void> {
|
||||
// 1. Let s be element.
|
||||
auto s = string;
|
||||
|
||||
|
@ -84,7 +84,7 @@ ErrorOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts, Optio
|
|||
if (options.has_value() && options->endings == Bindings::EndingType::Native)
|
||||
s = TRY(convert_line_endings_to_native(s));
|
||||
|
||||
// NOTE: The AK::String is always UTF-8.
|
||||
// NOTE: The AK::DeprecatedString is always UTF-8.
|
||||
// 3. Append the result of UTF-8 encoding s to bytes.
|
||||
return bytes.try_append(s.to_byte_buffer());
|
||||
},
|
||||
|
@ -117,7 +117,7 @@ Blob::Blob(JS::Realm& realm)
|
|||
set_prototype(&Bindings::cached_web_prototype(realm, "Blob"));
|
||||
}
|
||||
|
||||
Blob::Blob(JS::Realm& realm, ByteBuffer byte_buffer, String type)
|
||||
Blob::Blob(JS::Realm& realm, ByteBuffer byte_buffer, DeprecatedString type)
|
||||
: PlatformObject(realm)
|
||||
, m_byte_buffer(move(byte_buffer))
|
||||
, m_type(move(type))
|
||||
|
@ -147,7 +147,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::create(JS::Realm& realm, Optio
|
|||
byte_buffer = TRY_OR_RETURN_OOM(realm, process_blob_parts(blob_parts.value(), options));
|
||||
}
|
||||
|
||||
auto type = String::empty();
|
||||
auto type = DeprecatedString::empty();
|
||||
// 3. If the type member of the options argument is not the empty string, run the following sub-steps:
|
||||
if (options.has_value() && !options->type.is_empty()) {
|
||||
// 1. If the type member is provided and is not the empty string, let t be set to the type dictionary member.
|
||||
|
@ -173,7 +173,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::construct_impl(JS::Realm& real
|
|||
}
|
||||
|
||||
// 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<JS::NonnullGCPtr<Blob>> Blob::slice(Optional<i64> start, Optional<i64> end, Optional<DeprecatedString> const& content_type)
|
||||
{
|
||||
// 1. The optional start parameter is a value for the start point of a slice() call, and must be treated as a byte-order position, with the zeroth position representing the first byte.
|
||||
// User agents must process slice() with start normalized according to the following:
|
||||
|
@ -212,7 +212,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::slice(Optional<i64> start, Opt
|
|||
|
||||
// 3. The optional contentType parameter is used to set the ASCII-encoded string in lower case representing the media type of the Blob.
|
||||
// User agents must process the slice() with contentType normalized according to the following:
|
||||
String relative_content_type;
|
||||
DeprecatedString relative_content_type;
|
||||
if (!content_type.has_value()) {
|
||||
// a. If the contentType parameter is not provided, let relativeContentType be set to the empty string.
|
||||
relative_content_type = "";
|
||||
|
@ -245,7 +245,7 @@ JS::Promise* Blob::text()
|
|||
// FIXME: We still need to implement ReadableStream for this step to be fully valid.
|
||||
// 3. Let promise be the result of reading all bytes from stream with reader
|
||||
auto* promise = JS::Promise::create(realm());
|
||||
auto* result = JS::js_string(vm(), String { m_byte_buffer.bytes() });
|
||||
auto* result = JS::js_string(vm(), DeprecatedString { m_byte_buffer.bytes() });
|
||||
|
||||
// 4. Return the result of transforming promise by a fulfillment handler that returns the result of running UTF-8 decode on its first argument.
|
||||
promise->fulfill(result);
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/Bindings/BlobPrototype.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
|
@ -16,14 +16,14 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
using BlobPart = Variant<JS::Handle<JS::Object>, JS::Handle<Blob>, String>;
|
||||
using BlobPart = Variant<JS::Handle<JS::Object>, JS::Handle<Blob>, DeprecatedString>;
|
||||
|
||||
struct BlobPropertyBag {
|
||||
String type = String::empty();
|
||||
DeprecatedString type = DeprecatedString::empty();
|
||||
Bindings::EndingType endings;
|
||||
};
|
||||
|
||||
[[nodiscard]] ErrorOr<String> convert_line_endings_to_native(String const& string);
|
||||
[[nodiscard]] ErrorOr<DeprecatedString> convert_line_endings_to_native(DeprecatedString const& string);
|
||||
[[nodiscard]] ErrorOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts, Optional<BlobPropertyBag> const& options = {});
|
||||
[[nodiscard]] bool is_basic_latin(StringView view);
|
||||
|
||||
|
@ -33,16 +33,16 @@ class Blob : public Bindings::PlatformObject {
|
|||
public:
|
||||
virtual ~Blob() override;
|
||||
|
||||
static JS::NonnullGCPtr<Blob> create(JS::Realm&, ByteBuffer, String type);
|
||||
static JS::NonnullGCPtr<Blob> create(JS::Realm&, ByteBuffer, DeprecatedString 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
|
||||
String const& type() const { return m_type; }
|
||||
DeprecatedString 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<JS::NonnullGCPtr<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<DeprecatedString> const& content_type = {});
|
||||
|
||||
JS::Promise* text();
|
||||
JS::Promise* array_buffer();
|
||||
|
@ -50,14 +50,14 @@ public:
|
|||
ReadonlyBytes bytes() const { return m_byte_buffer.bytes(); }
|
||||
|
||||
protected:
|
||||
Blob(JS::Realm&, ByteBuffer, String type);
|
||||
Blob(JS::Realm&, ByteBuffer, DeprecatedString type);
|
||||
Blob(JS::Realm&, ByteBuffer);
|
||||
|
||||
private:
|
||||
explicit Blob(JS::Realm&);
|
||||
|
||||
ByteBuffer m_byte_buffer {};
|
||||
String m_type {};
|
||||
DeprecatedString m_type {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace Web::FileAPI {
|
||||
|
||||
File::File(JS::Realm& realm, ByteBuffer byte_buffer, String file_name, String type, i64 last_modified)
|
||||
File::File(JS::Realm& realm, ByteBuffer byte_buffer, DeprecatedString file_name, DeprecatedString type, i64 last_modified)
|
||||
: Blob(realm, move(byte_buffer), move(type))
|
||||
, m_name(move(file_name))
|
||||
, m_last_modified(last_modified)
|
||||
|
@ -21,7 +21,7 @@ File::File(JS::Realm& realm, ByteBuffer byte_buffer, String file_name, String ty
|
|||
File::~File() = default;
|
||||
|
||||
// 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<JS::NonnullGCPtr<File>> File::create(JS::Realm& realm, Vector<BlobPart> const& file_bits, DeprecatedString const& file_name, Optional<FilePropertyBag> const& options)
|
||||
{
|
||||
// 1. Let bytes be the result of processing blob parts given fileBits and options.
|
||||
auto bytes = TRY_OR_RETURN_OOM(realm, process_blob_parts(file_bits, static_cast<Optional<BlobPropertyBag> const&>(*options)));
|
||||
|
@ -30,7 +30,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> File::create(JS::Realm& realm, Vecto
|
|||
// NOTE: Underlying OS filesystems use differing conventions for file name; with constructed files, mandating UTF-16 lessens ambiquity when file names are converted to byte sequences.
|
||||
auto name = file_name;
|
||||
|
||||
auto type = String::empty();
|
||||
auto type = DeprecatedString::empty();
|
||||
i64 last_modified = 0;
|
||||
// 3. Process FilePropertyBag dictionary argument by running the following substeps:
|
||||
if (options.has_value()) {
|
||||
|
@ -61,7 +61,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> File::create(JS::Realm& realm, Vecto
|
|||
return JS::NonnullGCPtr(*realm.heap().allocate<File>(realm, 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<JS::NonnullGCPtr<File>> File::construct_impl(JS::Realm& realm, Vector<BlobPart> const& file_bits, DeprecatedString const& file_name, Optional<FilePropertyBag> const& options)
|
||||
{
|
||||
return create(realm, file_bits, file_name, options);
|
||||
}
|
||||
|
|
|
@ -18,20 +18,20 @@ class File : public Blob {
|
|||
WEB_PLATFORM_OBJECT(File, Blob);
|
||||
|
||||
public:
|
||||
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 WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> create(JS::Realm&, Vector<BlobPart> const& file_bits, DeprecatedString const& file_name, Optional<FilePropertyBag> const& options = {});
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<File>> construct_impl(JS::Realm&, Vector<BlobPart> const& file_bits, DeprecatedString const& file_name, Optional<FilePropertyBag> const& options = {});
|
||||
|
||||
virtual ~File() override;
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dfn-name
|
||||
String const& name() const { return m_name; }
|
||||
DeprecatedString const& name() const { return m_name; }
|
||||
// https://w3c.github.io/FileAPI/#dfn-lastModified
|
||||
i64 last_modified() const { return m_last_modified; }
|
||||
|
||||
private:
|
||||
File(JS::Realm&, ByteBuffer, String file_name, String type, i64 last_modified);
|
||||
File(JS::Realm&, ByteBuffer, DeprecatedString file_name, DeprecatedString type, i64 last_modified);
|
||||
|
||||
String m_name;
|
||||
DeprecatedString m_name;
|
||||
i64 m_last_modified { 0 };
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue