mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb/IDB: Update convert_a_value_to_a_key to latest changes
This commit is contained in:
parent
ad4ade3f07
commit
a0b252c0dd
Notes:
github-actions[bot]
2025-03-13 10:24:16 +00:00
Author: https://github.com/stelar7
Commit: a0b252c0dd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3746
Reviewed-by: https://github.com/gmta ✅
3 changed files with 35 additions and 2 deletions
|
@ -22,6 +22,7 @@
|
|||
#include <LibWeb/IndexedDB/Internal/Database.h>
|
||||
#include <LibWeb/StorageAPI/StorageKey.h>
|
||||
#include <LibWeb/WebIDL/AbstractOperations.h>
|
||||
#include <LibWeb/WebIDL/Buffers.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
|
@ -213,10 +214,14 @@ ErrorOr<GC::Ref<Key>> convert_a_value_to_a_key(JS::Realm& realm, JS::Value input
|
|||
// - If input is a buffer source type
|
||||
if (input.is_object() && (is<JS::TypedArrayBase>(input.as_object()) || is<JS::ArrayBuffer>(input.as_object()) || is<JS::DataView>(input.as_object()))) {
|
||||
|
||||
// 1. Let bytes be the result of getting a copy of the bytes held by the buffer source input. Rethrow any exceptions.
|
||||
// 1. If input is [detached] then return invalid.
|
||||
if (WebIDL::is_buffer_source_detached(input))
|
||||
return Error::from_string_literal("Detached buffer is not supported as key");
|
||||
|
||||
// 2. Let bytes be the result of getting a copy of the bytes held by the buffer source input.
|
||||
auto data_buffer = TRY(WebIDL::get_buffer_source_copy(input.as_object()));
|
||||
|
||||
// 2. Return a new key with type binary and value bytes.
|
||||
// 3. Return a new key with type binary and value bytes.
|
||||
return Key::create_binary(realm, data_buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,4 +127,30 @@ void ArrayBufferView::write(ReadonlyBytes bytes, u32 starting_offset)
|
|||
|
||||
BufferSource::~BufferSource() = default;
|
||||
|
||||
// https://webidl.spec.whatwg.org/#buffersource-detached
|
||||
bool is_buffer_source_detached(JS::Value const& buffer_source)
|
||||
{
|
||||
// A buffer source type instance bufferSource is detached if the following steps return true:
|
||||
|
||||
// 1. Let jsArrayBuffer be the result of converting bufferSource to a JavaScript value.
|
||||
// 2. If jsArrayBuffer has a [[ViewedArrayBuffer]] internal slot, then set jsArrayBuffer to jsArrayBuffer.[[ViewedArrayBuffer]].
|
||||
if (!buffer_source.is_object())
|
||||
return false;
|
||||
|
||||
JS::ArrayBuffer const* js_array_buffer = nullptr;
|
||||
auto const& array_buffer_object = buffer_source.as_object();
|
||||
if (auto const* array_buffer = as_if<JS::ArrayBuffer>(array_buffer_object)) {
|
||||
js_array_buffer = array_buffer;
|
||||
} else if (auto const* typed_array_base = as_if<JS::TypedArrayBase>(array_buffer_object)) {
|
||||
js_array_buffer = typed_array_base->viewed_array_buffer();
|
||||
} else if (auto const* data_view = as_if<JS::DataView>(array_buffer_object)) {
|
||||
js_array_buffer = data_view->viewed_array_buffer();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. Return IsDetachedBuffer(jsArrayBuffer).
|
||||
return js_array_buffer->is_detached();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
namespace Web::WebIDL {
|
||||
|
||||
bool is_buffer_source_detached(JS::Value const&);
|
||||
|
||||
using BufferableObject = Variant<
|
||||
GC::Ref<JS::TypedArrayBase>,
|
||||
GC::Ref<JS::DataView>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue