mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:37:36 +00:00
LibWeb: Make DOMException GC-allocated
This commit is contained in:
parent
0e47754ac8
commit
497ead37bc
58 changed files with 307 additions and 278 deletions
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue