summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2023-02-12 21:25:57 +0100
committerLinus Groh <mail@linusgroh.de>2023-02-18 00:52:47 +0100
commit52e9839d8b452916428b4dc16b5c3107723bc277 (patch)
treec895a93b3f2e1f269c8d9e5c3a167f513607fcf7
parent58af8e202169077b9df99fd0fd3bf933fcd79ac1 (diff)
downloadserenity-52e9839d8b452916428b4dc16b5c3107723bc277.zip
LibWeb: Make factory method of Crypto::SubtleCrypto fallible
-rw-r--r--Userland/Libraries/LibWeb/Crypto/Crypto.cpp5
-rw-r--r--Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h2
3 files changed, 8 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp
index 3a02c11aa9..7797876daf 100644
--- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp
+++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp
@@ -8,6 +8,7 @@
#include <AK/Random.h>
#include <AK/StringBuilder.h>
#include <LibJS/Runtime/TypedArray.h>
+#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Crypto/Crypto.h>
#include <LibWeb/Crypto/SubtleCrypto.h>
@@ -30,7 +31,9 @@ JS::ThrowCompletionOr<void> Crypto::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::CryptoPrototype>(realm, "Crypto"));
- m_subtle = SubtleCrypto::create(realm);
+ m_subtle = TRY(Bindings::throw_dom_exception_if_needed(realm.vm(), [&]() {
+ return SubtleCrypto::create(realm);
+ }));
return {};
}
diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
index 8aefaf0427..fb64d3a1df 100644
--- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
+++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
@@ -10,13 +10,13 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Crypto/SubtleCrypto.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
-#include <LibWeb/WebIDL/DOMException.h>
+#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::Crypto {
-JS::NonnullGCPtr<SubtleCrypto> SubtleCrypto::create(JS::Realm& realm)
+WebIDL::ExceptionOr<JS::NonnullGCPtr<SubtleCrypto>> SubtleCrypto::create(JS::Realm& realm)
{
- return realm.heap().allocate<SubtleCrypto>(realm, realm).release_allocated_value_but_fixme_should_propagate_errors();
+ return MUST_OR_THROW_OOM(realm.heap().allocate<SubtleCrypto>(realm, realm));
}
SubtleCrypto::SubtleCrypto(JS::Realm& realm)
diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h
index bf13e9f723..2139c4b690 100644
--- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h
+++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.h
@@ -15,7 +15,7 @@ class SubtleCrypto final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(SubtleCrypto, Bindings::PlatformObject);
public:
- static JS::NonnullGCPtr<SubtleCrypto> create(JS::Realm&);
+ static WebIDL::ExceptionOr<JS::NonnullGCPtr<SubtleCrypto>> create(JS::Realm&);
virtual ~SubtleCrypto() override;