mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-23 01:38:56 +00:00
LibWeb: Implement most of IDBFactory::open
This commit is contained in:
parent
47d6499f6d
commit
64eea90f29
Notes:
github-actions[bot]
2024-11-08 18:12:20 +00:00
Author: https://github.com/stelar7
Commit: 64eea90f29
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2165
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/shannonbooth
3 changed files with 46 additions and 2 deletions
|
@ -1,12 +1,18 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
||||||
|
* Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibWeb/Bindings/IDBFactoryPrototype.h>
|
#include <LibWeb/Bindings/IDBFactoryPrototype.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/DOM/Event.h>
|
||||||
|
#include <LibWeb/HTML/EventNames.h>
|
||||||
|
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
|
||||||
#include <LibWeb/IndexedDB/IDBFactory.h>
|
#include <LibWeb/IndexedDB/IDBFactory.h>
|
||||||
|
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||||
|
#include <LibWeb/StorageAPI/StorageKey.h>
|
||||||
|
|
||||||
namespace Web::IndexedDB {
|
namespace Web::IndexedDB {
|
||||||
|
|
||||||
|
@ -25,4 +31,39 @@ void IDBFactory::initialize(JS::Realm& realm)
|
||||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBFactory);
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#dom-idbfactory-open
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<IDBOpenDBRequest>> IDBFactory::open(String const& name, Optional<u64> version)
|
||||||
|
{
|
||||||
|
auto& realm = this->realm();
|
||||||
|
|
||||||
|
// 1. If version is 0 (zero), throw a TypeError.
|
||||||
|
if (version.has_value() && version.value() == 0)
|
||||||
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "The version provided must not be 0"_string };
|
||||||
|
|
||||||
|
// 2. Let environment be this's relevant settings object.
|
||||||
|
auto& environment = HTML::relevant_settings_object(*this);
|
||||||
|
|
||||||
|
// 3. Let storageKey be the result of running obtain a storage key given environment.
|
||||||
|
// If failure is returned, then throw a "SecurityError" DOMException and abort these steps.
|
||||||
|
auto storage_key = StorageAPI::obtain_a_storage_key(environment);
|
||||||
|
if (!storage_key.has_value())
|
||||||
|
return WebIDL::SecurityError::create(realm, "Failed to obtain a storage key"_string);
|
||||||
|
|
||||||
|
// 4. Let request be a new open request.
|
||||||
|
auto request = IDBOpenDBRequest::create(realm);
|
||||||
|
|
||||||
|
// 5. Run these steps in parallel:
|
||||||
|
Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, storage_key, name, version, request] {
|
||||||
|
HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes);
|
||||||
|
|
||||||
|
(void)storage_key;
|
||||||
|
(void)name;
|
||||||
|
(void)version;
|
||||||
|
(void)request;
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 6. Return a new IDBOpenDBRequest object for request.
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
||||||
|
* Copyright (c) 2024, stelar7 <dudedbz@gmail.com>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -7,6 +8,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibWeb/Bindings/PlatformObject.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
#include <LibWeb/IndexedDB/IDBOpenDBRequest.h>
|
||||||
|
|
||||||
namespace Web::IndexedDB {
|
namespace Web::IndexedDB {
|
||||||
|
|
||||||
|
@ -18,6 +20,8 @@ class IDBFactory : public Bindings::PlatformObject {
|
||||||
public:
|
public:
|
||||||
virtual ~IDBFactory() override;
|
virtual ~IDBFactory() override;
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<IDBOpenDBRequest>> open(String const& name, Optional<u64> version);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit IDBFactory(JS::Realm&);
|
explicit IDBFactory(JS::Realm&);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
// https://w3c.github.io/IndexedDB/#idbfactory
|
// https://w3c.github.io/IndexedDB/#idbfactory
|
||||||
[Exposed=(Window,Worker)]
|
[Exposed=(Window,Worker)]
|
||||||
interface IDBFactory {
|
interface IDBFactory {
|
||||||
[FIXME, NewObject] IDBOpenDBRequest open(DOMString name,
|
[NewObject] IDBOpenDBRequest open(DOMString name, optional [EnforceRange] unsigned long long version);
|
||||||
optional [EnforceRange] unsigned long long version);
|
|
||||||
[FIXME, NewObject] IDBOpenDBRequest deleteDatabase(DOMString name);
|
[FIXME, NewObject] IDBOpenDBRequest deleteDatabase(DOMString name);
|
||||||
|
|
||||||
[FIXME] Promise<sequence<IDBDatabaseInfo>> databases();
|
[FIXME] Promise<sequence<IDBDatabaseInfo>> databases();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue