diff options
author | Linus Groh <mail@linusgroh.de> | 2021-12-28 17:42:14 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-03 21:50:50 +0100 |
commit | 85f0fc2b83a83c842144018a8643ac471cf0c33f (patch) | |
tree | 5e86284cd2d10aa380c08c495a80edd8393c4d87 /Userland/Libraries/LibWeb/WebAssembly | |
parent | b39aede8fe19e7ef17ddc7f52c9ed1decef30e78 (diff) | |
download | serenity-85f0fc2b83a83c842144018a8643ac471cf0c33f.zip |
LibJS: Return Optional<T> from Completion::{value,target}(), not T
In the end this is a nicer API than having separate has_{value,target}()
and having to check those first, and then making another Optional from
the unwrapped value:
completion.has_value() ? completion.value() : Optional<Value> {}
// ^^^^^^^^^^^^^^^^^^
// Implicit creation of non-empty Optional<Value>
This way we need to unwrap the optional ourselves, but can easily pass
it to something else as well.
This is in anticipation of the AST using completions :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/WebAssembly')
-rw-r--r-- | Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index 34e33a0a4a..8c32db5c3d 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -160,7 +160,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile) auto buffer_or_error = vm.argument(0).to_object(global_object); JS::Value rejection_value; if (buffer_or_error.is_error()) { - rejection_value = buffer_or_error.throw_completion().value(); + rejection_value = *buffer_or_error.throw_completion().value(); vm.clear_exception(); vm.stop_unwind(); } @@ -172,7 +172,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile) auto* buffer = buffer_or_error.release_value(); auto result = parse_module(global_object, buffer); if (result.is_error()) - promise->reject(result.release_error().value()); + promise->reject(*result.release_error().value()); else promise->fulfill(vm.heap().allocate<WebAssemblyModuleObject>(global_object, global_object, result.release_value())); return promise; @@ -325,7 +325,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate) auto promise = JS::Promise::create(global_object); bool should_return_module = false; if (buffer_or_error.is_error()) { - auto rejection_value = buffer_or_error.throw_completion().value(); + auto rejection_value = *buffer_or_error.throw_completion().value(); vm.clear_exception(); vm.stop_unwind(); promise->reject(rejection_value); @@ -337,7 +337,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate) if (is<JS::ArrayBuffer>(buffer) || is<JS::TypedArrayBase>(buffer)) { auto result = parse_module(global_object, buffer); if (result.is_error()) { - promise->reject(result.release_error().value()); + promise->reject(*result.release_error().value()); return promise; } module = &WebAssemblyObject::s_compiled_modules.at(result.release_value()).module; @@ -353,7 +353,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate) auto result = instantiate_module(*module, vm, global_object); if (result.is_error()) { - promise->reject(result.release_error().value()); + promise->reject(*result.release_error().value()); } else { auto instance_object = vm.heap().allocate<WebAssemblyInstanceObject>(global_object, global_object, result.release_value()); if (should_return_module) { |