LibWeb: Stub CacheStorage interface

With this change we can again open login form https://discord.com/login
instead of failing in js because `caches.open()` is not defined.
This commit is contained in:
Aliaksandr Kalenik 2025-06-05 17:50:08 +02:00 committed by Alexander Kalenik
commit 7efdd1c1ec
Notes: github-actions[bot] 2025-06-05 21:03:31 +00:00
10 changed files with 102 additions and 0 deletions

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/CacheStoragePrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/ServiceWorker/CacheStorage.h>
#include <LibWeb/WebIDL/Promise.h>
namespace Web::ServiceWorker {
GC_DEFINE_ALLOCATOR(CacheStorage);
CacheStorage::CacheStorage(JS::Realm& realm)
: Bindings::PlatformObject(realm)
{
}
void CacheStorage::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(CacheStorage);
}
// https://w3c.github.io/ServiceWorker/#cache-storage-open
GC::Ref<WebIDL::Promise> CacheStorage::open(String const&)
{
return WebIDL::create_rejected_promise(realm(), WebIDL::NotSupportedError::create(realm(), "CacheStorage.open() is not yet implemented"_string));
}
}

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/WebIDL/Promise.h>
namespace Web::ServiceWorker {
// https://w3c.github.io/ServiceWorker/#cachestorage-interface
class CacheStorage : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(CacheStorage, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(CacheStorage);
public:
GC::Ref<WebIDL::Promise> open(String const& cache_name);
private:
explicit CacheStorage(JS::Realm&);
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,15 @@
#import <Fetch/Request.idl>
// https://w3c.github.io/ServiceWorker/#cachestorage-interface
[SecureContext, Exposed=(Window,Worker)]
interface CacheStorage {
//[NewObject] Promise<(Response or undefined)> match(RequestInfo request, optional MultiCacheQueryOptions options = {});
//[NewObject] Promise<boolean> has(DOMString cacheName);
[NewObject] Promise<Cache> open(DOMString cacheName);
//[NewObject] Promise<boolean> delete(DOMString cacheName);
//[NewObject] Promise<sequence<DOMString>> keys();
};
//dictionary MultiCacheQueryOptions : CacheQueryOptions {
// DOMString cacheName;
//};