mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-22 16:09:23 +00:00
LibWeb: Implement CookieStore::set(options)
This commit is contained in:
parent
1f37130703
commit
f724f542ed
Notes:
github-actions[bot]
2025-08-08 17:11:52 +00:00
Author: https://github.com/IdanHo
Commit: f724f542ed
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5766
Reviewed-by: https://github.com/trflynn89 ✅
3 changed files with 68 additions and 0 deletions
|
@ -522,4 +522,48 @@ GC::Ref<WebIDL::Promise> CookieStore::set(String name, String value)
|
|||
return promise;
|
||||
}
|
||||
|
||||
// https://cookiestore.spec.whatwg.org/#dom-cookiestore-set-options
|
||||
GC::Ref<WebIDL::Promise> CookieStore::set(CookieInit const& options)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 1. Let settings be this’s relevant settings object.
|
||||
auto const& settings = HTML::relevant_settings_object(*this);
|
||||
|
||||
// 2. Let origin be settings’s origin.
|
||||
auto const& origin = settings.origin();
|
||||
|
||||
// 3. If origin is an opaque origin, then return a promise rejected with a "SecurityError" DOMException.
|
||||
if (origin.is_opaque())
|
||||
return WebIDL::create_rejected_promise(realm, WebIDL::SecurityError::create(realm, "Document origin is opaque"_string));
|
||||
|
||||
// 4. Let url be settings’s creation URL.
|
||||
auto url = settings.creation_url;
|
||||
|
||||
// 5. Let p be a new promise.
|
||||
auto promise = WebIDL::create_promise(realm);
|
||||
|
||||
// 6. Run the following steps in parallel:
|
||||
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(realm.heap(), [&realm, client = m_client, promise, url = move(url), options = options]() {
|
||||
// 1. Let r be the result of running set a cookie with url, options["name"], options["value"], options["expires"],
|
||||
// options["domain"], options["path"], options["sameSite"], and options["partitioned"].
|
||||
auto result = set_a_cookie(client, url, options.name, options.value, options.expires, options.domain, options.path, options.same_site, options.partitioned);
|
||||
|
||||
// AD-HOC: Queue a global task to perform the next steps
|
||||
// Spec issue: https://github.com/whatwg/cookiestore/issues/239
|
||||
queue_global_task(HTML::Task::Source::Unspecified, realm.global_object(), GC::create_function(realm.heap(), [&realm, promise, result]() {
|
||||
HTML::TemporaryExecutionContext execution_context { realm };
|
||||
// 2. If r is failure, then reject p with a TypeError and abort these steps.
|
||||
if (!result)
|
||||
return WebIDL::reject_promise(realm, promise, JS::TypeError::create(realm, "Name, value, domain or path are malformed"sv));
|
||||
|
||||
// 3. Resolve p with undefined.
|
||||
WebIDL::resolve_promise(realm, promise);
|
||||
}));
|
||||
}));
|
||||
|
||||
// 7. Return p.
|
||||
return promise;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue