mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
LibWeb/IDB: Implement IDBRecord
This commit is contained in:
parent
fe5d5639ef
commit
752210aec1
Notes:
github-actions[bot]
2025-08-27 14:15:43 +00:00
Author: https://github.com/stelar7
Commit: 752210aec1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5385
Reviewed-by: https://github.com/gmta ✅
11 changed files with 111 additions and 29 deletions
|
@ -647,6 +647,7 @@ set(SOURCES
|
|||
IndexedDB/IDBKeyRange.cpp
|
||||
IndexedDB/IDBObjectStore.cpp
|
||||
IndexedDB/IDBOpenDBRequest.cpp
|
||||
IndexedDB/IDBRecord.cpp
|
||||
IndexedDB/IDBRequest.cpp
|
||||
IndexedDB/IDBTransaction.cpp
|
||||
IndexedDB/IDBVersionChangeEvent.cpp
|
||||
|
|
|
@ -779,6 +779,7 @@ class IDBIndex;
|
|||
class IDBKeyRange;
|
||||
class IDBObjectStore;
|
||||
class IDBOpenDBRequest;
|
||||
class IDBRecord;
|
||||
class IDBRequest;
|
||||
class IDBTransaction;
|
||||
class IDBVersionChangeEvent;
|
||||
|
|
43
Libraries/LibWeb/IndexedDB/IDBRecord.cpp
Normal file
43
Libraries/LibWeb/IndexedDB/IDBRecord.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2025, stelar7 <dudedbz@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/IDBRecordPrototype.h>
|
||||
#include <LibWeb/IndexedDB/IDBRecord.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(IDBRecord);
|
||||
|
||||
IDBRecord::~IDBRecord() = default;
|
||||
|
||||
GC::Ref<IDBRecord> IDBRecord::create(JS::Realm& realm, GC::Ref<Key> key, JS::Value value, GC::Ref<Key> primary_key)
|
||||
{
|
||||
return realm.create<IDBRecord>(realm, move(key), move(value), move(primary_key));
|
||||
}
|
||||
|
||||
IDBRecord::IDBRecord(JS::Realm& realm, GC::Ref<Key> key, JS::Value value, GC::Ref<Key> primary_key)
|
||||
: PlatformObject(realm)
|
||||
, m_key(move(key))
|
||||
, m_value(move(value))
|
||||
, m_primary_key(move(primary_key))
|
||||
{
|
||||
}
|
||||
|
||||
void IDBRecord::initialize(JS::Realm& realm)
|
||||
{
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBRecord);
|
||||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
void IDBRecord::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_key);
|
||||
visitor.visit(m_value);
|
||||
visitor.visit(m_primary_key);
|
||||
}
|
||||
|
||||
}
|
54
Libraries/LibWeb/IndexedDB/IDBRecord.h
Normal file
54
Libraries/LibWeb/IndexedDB/IDBRecord.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2025, stelar7 <dudedbz@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/HTML/StructuredSerializeTypes.h>
|
||||
#include <LibWeb/IndexedDB/Internal/Key.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#object-store-record
|
||||
struct ObjectStoreRecord {
|
||||
GC::Ref<Key> key;
|
||||
HTML::SerializationRecord value;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#index-list-of-records
|
||||
struct IndexRecord {
|
||||
GC::Ref<Key> key;
|
||||
GC::Ref<Key> value;
|
||||
};
|
||||
|
||||
// https://pr-preview.s3.amazonaws.com/w3c/IndexedDB/pull/461.html#record-snapshot
|
||||
// https://pr-preview.s3.amazonaws.com/w3c/IndexedDB/461/95f98c0...43e154b.html#record-interface
|
||||
class IDBRecord : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(IDBRecord, Bindings::PlatformObject);
|
||||
GC_DECLARE_ALLOCATOR(IDBRecord);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static GC::Ref<IDBRecord> create(JS::Realm& realm, GC::Ref<Key> key, JS::Value value, GC::Ref<Key> primary_key);
|
||||
virtual ~IDBRecord();
|
||||
|
||||
GC::Ref<Key> key() const { return m_key; }
|
||||
GC::Ref<Key> primary_key() const { return m_primary_key; }
|
||||
JS::Value value() const { return m_value; }
|
||||
|
||||
protected:
|
||||
explicit IDBRecord(JS::Realm&, GC::Ref<Key> key, JS::Value value, GC::Ref<Key> primary_key);
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Visitor& visitor) override;
|
||||
|
||||
private:
|
||||
GC::Ref<Key> m_key;
|
||||
JS::Value m_value;
|
||||
GC::Ref<Key> m_primary_key;
|
||||
};
|
||||
|
||||
}
|
7
Libraries/LibWeb/IndexedDB/IDBRecord.idl
Normal file
7
Libraries/LibWeb/IndexedDB/IDBRecord.idl
Normal file
|
@ -0,0 +1,7 @@
|
|||
// https://pr-preview.s3.amazonaws.com/w3c/IndexedDB/pull/461.html#record-interface
|
||||
[Exposed=(Window,Worker)]
|
||||
interface IDBRecord {
|
||||
readonly attribute any key;
|
||||
readonly attribute any primaryKey;
|
||||
readonly attribute any value;
|
||||
};
|
|
@ -10,8 +10,8 @@
|
|||
#include <LibGC/Ptr.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibWeb/IndexedDB/IDBRecord.h>
|
||||
#include <LibWeb/IndexedDB/Internal/ObjectStore.h>
|
||||
#include <LibWeb/IndexedDB/Internal/Record.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
|
|
|
@ -14,11 +14,11 @@
|
|||
#include <LibGC/Ptr.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibJS/Runtime/Realm.h>
|
||||
#include <LibWeb/IndexedDB/IDBRecord.h>
|
||||
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
|
||||
#include <LibWeb/IndexedDB/Internal/Database.h>
|
||||
#include <LibWeb/IndexedDB/Internal/Index.h>
|
||||
#include <LibWeb/IndexedDB/Internal/KeyGenerator.h>
|
||||
#include <LibWeb/IndexedDB/Internal/Record.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025, stelar7 <dudedbz@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibGC/Ptr.h>
|
||||
#include <LibWeb/HTML/StructuredSerializeTypes.h>
|
||||
#include <LibWeb/IndexedDB/Internal/Key.h>
|
||||
|
||||
namespace Web::IndexedDB {
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#object-store-record
|
||||
struct ObjectStoreRecord {
|
||||
GC::Ref<Key> key;
|
||||
HTML::SerializationRecord value;
|
||||
};
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#index-list-of-records
|
||||
struct IndexRecord {
|
||||
GC::Ref<Key> key;
|
||||
GC::Ref<Key> value;
|
||||
};
|
||||
|
||||
}
|
|
@ -290,6 +290,7 @@ libweb_js_bindings(IndexedDB/IDBIndex)
|
|||
libweb_js_bindings(IndexedDB/IDBKeyRange)
|
||||
libweb_js_bindings(IndexedDB/IDBObjectStore)
|
||||
libweb_js_bindings(IndexedDB/IDBOpenDBRequest)
|
||||
libweb_js_bindings(IndexedDB/IDBRecord)
|
||||
libweb_js_bindings(IndexedDB/IDBRequest)
|
||||
libweb_js_bindings(IndexedDB/IDBTransaction)
|
||||
libweb_js_bindings(IndexedDB/IDBVersionChangeEvent)
|
||||
|
|
|
@ -79,6 +79,7 @@ static bool is_platform_object(Type const& type)
|
|||
"IDBIndex"sv,
|
||||
"IDBKeyRange"sv,
|
||||
"IDBObjectStore"sv,
|
||||
"IDBRecord"sv,
|
||||
"IDBTransaction"sv,
|
||||
"ImageBitmap"sv,
|
||||
"ImageData"sv,
|
||||
|
|
|
@ -239,6 +239,7 @@ IDBIndex
|
|||
IDBKeyRange
|
||||
IDBObjectStore
|
||||
IDBOpenDBRequest
|
||||
IDBRecord
|
||||
IDBRequest
|
||||
IDBTransaction
|
||||
IDBVersionChangeEvent
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue