LibWeb: Expose crypto object to workers

This change moves the `crypto()` getter from `Window` to
`WorkerOrWindowGlobalScope`. This aligns our implementation with the
WebCrypto specification.
This commit is contained in:
Tim Ledbetter 2024-09-17 16:44:42 +01:00 committed by Andreas Kling
commit 89b6cd3fb1
Notes: github-actions[bot] 2024-09-18 08:09:56 +00:00
9 changed files with 33 additions and 19 deletions

View file

@ -15,6 +15,7 @@
#include <LibJS/Runtime/Array.h>
#include <LibTextCodec/Decoder.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Crypto/Crypto.h>
#include <LibWeb/Fetch/FetchMethod.h>
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
#include <LibWeb/HTML/ErrorEvent.h>
@ -72,6 +73,7 @@ void WindowOrWorkerGlobalScopeMixin::visit_edges(JS::Cell::Visitor& visitor)
for (auto& entry : m_performance_entry_buffer_map)
entry.value.visit_edges(visitor);
visitor.visit(m_registered_event_sources);
visitor.visit(m_crypto);
}
void WindowOrWorkerGlobalScopeMixin::finalize()
@ -838,4 +840,15 @@ void WindowOrWorkerGlobalScopeMixin::report_error(JS::Value e)
}
}
// https://w3c.github.io/webcrypto/#dom-windoworworkerglobalscope-crypto
JS::NonnullGCPtr<Crypto::Crypto> WindowOrWorkerGlobalScopeMixin::crypto()
{
auto& platform_object = this_impl();
auto& realm = platform_object.realm();
if (!m_crypto)
m_crypto = platform_object.heap().allocate<Crypto::Crypto>(realm, realm);
return JS::NonnullGCPtr { *m_crypto };
}
}