mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-09 11:06:10 +00:00
LibWeb: Move deserialize_* methods outside scope of Deserializer class
These methods are useful independent of the class Deserializer, so let's move their declarations to the header file and and outside the scope of the Deserializer class.
This commit is contained in:
parent
5a1944ce64
commit
985d0dd270
Notes:
sideshowbarker
2024-07-17 16:23:06 +09:00
Author: https://github.com/kennethmyhra
Commit: 985d0dd270
Pull-request: https://github.com/SerenityOS/serenity/pull/23323
Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 50 additions and 45 deletions
|
@ -894,8 +894,9 @@ private:
|
||||||
m_position += 2;
|
m_position += 2;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static WebIDL::ExceptionOr<ByteBuffer> deserialize_bytes(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position)
|
WebIDL::ExceptionOr<ByteBuffer> deserialize_bytes(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position)
|
||||||
{
|
{
|
||||||
u32 size_bits[2];
|
u32 size_bits[2];
|
||||||
size_bits[0] = vector[position++];
|
size_bits[0] = vector[position++];
|
||||||
|
@ -915,13 +916,13 @@ private:
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WebIDL::ExceptionOr<String> deserialize_string(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position)
|
WebIDL::ExceptionOr<String> deserialize_string(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position)
|
||||||
{
|
{
|
||||||
auto bytes = TRY(deserialize_bytes(vm, vector, position));
|
auto bytes = TRY(deserialize_bytes(vm, vector, position));
|
||||||
return TRY_OR_THROW_OOM(vm, String::from_utf8(StringView { bytes }));
|
return TRY_OR_THROW_OOM(vm, String::from_utf8(StringView { bytes }));
|
||||||
}
|
}
|
||||||
|
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::PrimitiveString>> deserialize_string_primitive(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position)
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::PrimitiveString>> deserialize_string_primitive(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position)
|
||||||
{
|
{
|
||||||
auto bytes = TRY(deserialize_bytes(vm, vector, position));
|
auto bytes = TRY(deserialize_bytes(vm, vector, position));
|
||||||
|
|
||||||
|
@ -930,7 +931,7 @@ private:
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::BigInt>> deserialize_big_int_primitive(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position)
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::BigInt>> deserialize_big_int_primitive(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position)
|
||||||
{
|
{
|
||||||
auto string = TRY(deserialize_string_primitive(vm, vector, position));
|
auto string = TRY(deserialize_string_primitive(vm, vector, position));
|
||||||
auto string_view = TRY(Bindings::throw_dom_exception_if_needed(vm, [&string]() {
|
auto string_view = TRY(Bindings::throw_dom_exception_if_needed(vm, [&string]() {
|
||||||
|
@ -939,7 +940,6 @@ private:
|
||||||
auto bigint = MUST(::Crypto::SignedBigInteger::from_base(10, string_view.substring_view(0, string_view.length() - 1)));
|
auto bigint = MUST(::Crypto::SignedBigInteger::from_base(10, string_view.substring_view(0, string_view.length() - 1)));
|
||||||
return JS::BigInt::create(vm, bigint);
|
return JS::BigInt::create(vm, bigint);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializewithtransfer
|
// https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializewithtransfer
|
||||||
WebIDL::ExceptionOr<SerializedTransferRecord> structured_serialize_with_transfer(JS::VM& vm, JS::Value value, Vector<JS::Handle<JS::Object>> const& transfer_list)
|
WebIDL::ExceptionOr<SerializedTransferRecord> structured_serialize_with_transfer(JS::VM& vm, JS::Value value, Vector<JS::Handle<JS::Object>> const& transfer_list)
|
||||||
|
|
|
@ -50,6 +50,11 @@ WebIDL::ExceptionOr<SerializationRecord> structured_serialize_internal(JS::VM& v
|
||||||
|
|
||||||
WebIDL::ExceptionOr<JS::Value> structured_deserialize(JS::VM& vm, SerializationRecord const& serialized, JS::Realm& target_realm, Optional<DeserializationMemory>);
|
WebIDL::ExceptionOr<JS::Value> structured_deserialize(JS::VM& vm, SerializationRecord const& serialized, JS::Realm& target_realm, Optional<DeserializationMemory>);
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<ByteBuffer> deserialize_bytes(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position);
|
||||||
|
WebIDL::ExceptionOr<String> deserialize_string(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position);
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::PrimitiveString>> deserialize_string_primitive(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position);
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::BigInt>> deserialize_big_int_primitive(JS::VM& vm, ReadonlySpan<u32> vector, size_t& position);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<SerializedTransferRecord> structured_serialize_with_transfer(JS::VM& vm, JS::Value value, Vector<JS::Handle<JS::Object>> const& transfer_list);
|
WebIDL::ExceptionOr<SerializedTransferRecord> structured_serialize_with_transfer(JS::VM& vm, JS::Value value, Vector<JS::Handle<JS::Object>> const& transfer_list);
|
||||||
WebIDL::ExceptionOr<DeserializedTransferRecord> structured_deserialize_with_transfer(JS::VM& vm, SerializedTransferRecord&);
|
WebIDL::ExceptionOr<DeserializedTransferRecord> structured_deserialize_with_transfer(JS::VM& vm, SerializedTransferRecord&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue