Przeglądaj źródła

LibWeb: Error out SubtleCrypto.digest with a OOM on Buffer copy error

Instead of returning a custom OperationError, let's just return a LibJS
defined OOM error instead.
Andrew Kaster 1 rok temu
rodzic
commit
ae4d90c88a

+ 5 - 2
Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp

@@ -123,13 +123,16 @@ WebIDL::ExceptionOr<NormalizedAlgorithmAndParameter> normalize_an_algorithm(JS::
 JS::NonnullGCPtr<JS::Promise> SubtleCrypto::digest(AlgorithmIdentifier const& algorithm, JS::Handle<WebIDL::BufferSource> const& data)
 JS::NonnullGCPtr<JS::Promise> SubtleCrypto::digest(AlgorithmIdentifier const& algorithm, JS::Handle<WebIDL::BufferSource> const& data)
 {
 {
     auto& realm = this->realm();
     auto& realm = this->realm();
+    auto& vm = this->vm();
 
 
     // 1. Let algorithm be the algorithm parameter passed to the digest() method.
     // 1. Let algorithm be the algorithm parameter passed to the digest() method.
 
 
     // 2. Let data be the result of getting a copy of the bytes held by the data parameter passed to the digest() method.
     // 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 = WebIDL::get_buffer_source_copy(*data->raw_object());
     auto data_buffer_or_error = WebIDL::get_buffer_source_copy(*data->raw_object());
-    if (data_buffer_or_error.is_error())
-        return WebIDL::create_rejected_promise_from_exception(realm, WebIDL::OperationError::create(realm, "Failed to copy bytes from ArrayBuffer"_fly_string));
+    if (data_buffer_or_error.is_error()) {
+        VERIFY(data_buffer_or_error.error().code() == ENOMEM);
+        return WebIDL::create_rejected_promise_from_exception(realm, vm.throw_completion<JS::InternalError>(vm.error_message(JS::VM::ErrorMessage::OutOfMemory)));
+    }
     auto data_buffer = data_buffer_or_error.release_value();
     auto data_buffer = data_buffer_or_error.release_value();
 
 
     // 3. Let normalizedAlgorithm be the result of normalizing an algorithm, with alg set to algorithm and op set to "digest".
     // 3. Let normalizedAlgorithm be the result of normalizing an algorithm, with alg set to algorithm and op set to "digest".