summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Crypto
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-04 16:56:15 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-06 00:27:09 +0200
commit497ead37bcc959a9325aa22b0a233e302b071229 (patch)
tree5657266abb6d64bef43e251c002d05a392055562 /Userland/Libraries/LibWeb/Crypto
parent0e47754ac82b3c9996732fc29dac9d2a1abed8ac (diff)
downloadserenity-497ead37bcc959a9325aa22b0a233e302b071229.zip
LibWeb: Make DOMException GC-allocated
Diffstat (limited to 'Userland/Libraries/LibWeb/Crypto')
-rw-r--r--Userland/Libraries/LibWeb/Crypto/Crypto.cpp6
-rw-r--r--Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp7
2 files changed, 6 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp
index 414b92a5f9..f9f1a3b2a2 100644
--- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp
+++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp
@@ -43,16 +43,16 @@ DOM::ExceptionOr<JS::Value> Crypto::get_random_values(JS::Value array) const
{
// 1. If array is not an Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array, then throw a TypeMismatchError and terminate the algorithm.
if (!array.is_object() || !(is<JS::Int8Array>(array.as_object()) || is<JS::Uint8Array>(array.as_object()) || is<JS::Uint8ClampedArray>(array.as_object()) || is<JS::Int16Array>(array.as_object()) || is<JS::Uint16Array>(array.as_object()) || is<JS::Int32Array>(array.as_object()) || is<JS::Uint32Array>(array.as_object()) || is<JS::BigInt64Array>(array.as_object()) || is<JS::BigUint64Array>(array.as_object())))
- return DOM::TypeMismatchError::create("array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array");
+ return DOM::TypeMismatchError::create(global_object(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array");
auto& typed_array = static_cast<JS::TypedArrayBase&>(array.as_object());
// 2. If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
if (typed_array.byte_length() > 65536)
- return DOM::QuotaExceededError::create("array's byteLength may not be greater than 65536");
+ return DOM::QuotaExceededError::create(global_object(), "array's byteLength may not be greater than 65536");
// IMPLEMENTATION DEFINED: If the viewed array buffer is detached, throw a InvalidStateError and terminate the algorithm.
if (typed_array.viewed_array_buffer()->is_detached())
- return DOM::InvalidStateError::create("array is detached");
+ return DOM::InvalidStateError::create(global_object(), "array is detached");
// FIXME: Handle SharedArrayBuffers
// 3. Overwrite all elements of array with cryptographically strong random values of the appropriate type.
diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
index bcad3cf09d..575339a254 100644
--- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
+++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp
@@ -7,7 +7,6 @@
#include <LibCrypto/Hash/HashManager.h>
#include <LibJS/Runtime/ArrayBuffer.h>
#include <LibJS/Runtime/Promise.h>
-#include <LibWeb/Bindings/DOMExceptionWrapper.h>
#include <LibWeb/Bindings/IDLAbstractOperations.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Crypto/SubtleCrypto.h>
@@ -38,7 +37,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
// 2. Let data be the result of getting a copy of the bytes held by the data parameter passed to the digest() method.
auto data_buffer_or_error = Bindings::IDL::get_buffer_source_copy(*data.cell());
if (data_buffer_or_error.is_error()) {
- auto* error = wrap(realm, DOM::OperationError::create("Failed to copy bytes from ArrayBuffer"));
+ auto* error = wrap(realm, DOM::OperationError::create(global_object(), "Failed to copy bytes from ArrayBuffer"));
auto* promise = JS::Promise::create(realm);
promise->reject(error);
return promise;
@@ -59,7 +58,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
}
// 4. If an error occurred, return a Promise rejected with normalizedAlgorithm.
else {
- auto* error = wrap(realm, DOM::NotSupportedError::create(String::formatted("Invalid hash function '{}'", algorithm)));
+ auto* error = wrap(realm, DOM::NotSupportedError::create(global_object(), String::formatted("Invalid hash function '{}'", algorithm)));
auto* promise = JS::Promise::create(realm);
promise->reject(error);
return promise;
@@ -80,7 +79,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
auto digest = hash.digest();
auto result_buffer = ByteBuffer::copy(digest.immutable_data(), hash.digest_size());
if (result_buffer.is_error()) {
- auto* error = wrap(realm, DOM::OperationError::create("Failed to create result buffer"));
+ auto* error = wrap(realm, DOM::OperationError::create(global_object(), "Failed to create result buffer"));
promise->reject(error);
return promise;
}