1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:07:34 +00:00

LibJS: Convert to_u32() to ThrowCompletionOr

This commit is contained in:
Idan Horowitz 2021-10-17 23:43:29 +03:00
parent f6a5ff7b00
commit cc94bba5c0
14 changed files with 32 additions and 69 deletions

View file

@ -41,17 +41,12 @@ JS::Value WebAssemblyMemoryConstructor::construct(FunctionObject&)
return {};
}
auto initial = initial_value.to_u32(global_object);
if (vm.exception())
return {};
auto initial = TRY_OR_DISCARD(initial_value.to_u32(global_object));
Optional<u32> maximum;
if (!maximum_value.is_empty()) {
maximum = maximum_value.to_u32(global_object);
if (vm.exception())
return {};
}
if (!maximum_value.is_empty())
maximum = TRY_OR_DISCARD(maximum_value.to_u32(global_object));
auto address = WebAssemblyObject::s_abstract_machine.store().allocate(Wasm::MemoryType { Wasm::Limits { initial, maximum } });
if (!address.has_value()) {

View file

@ -19,9 +19,7 @@ void WebAssemblyMemoryPrototype::initialize(JS::GlobalObject& global_object)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
{
auto page_count = vm.argument(0).to_u32(global_object);
if (vm.exception())
return {};
auto page_count = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object));
auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
if (!is<WebAssemblyMemoryObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");

View file

@ -56,17 +56,12 @@ JS::Value WebAssemblyTableConstructor::construct(FunctionObject&)
auto initial_value = TRY_OR_DISCARD(descriptor->get("initial"));
auto maximum_value = TRY_OR_DISCARD(descriptor->get("maximum"));
auto initial = initial_value.to_u32(global_object);
if (vm.exception())
return {};
auto initial = TRY_OR_DISCARD(initial_value.to_u32(global_object));
Optional<u32> maximum;
if (!maximum_value.is_undefined()) {
maximum = maximum_value.to_u32(global_object);
if (vm.exception())
return {};
}
if (!maximum_value.is_undefined())
maximum = TRY_OR_DISCARD(maximum_value.to_u32(global_object));
if (maximum.has_value() && maximum.value() < initial) {
vm.throw_exception<JS::RangeError>(global_object, "maximum should be larger than or equal to initial");

View file

@ -21,9 +21,8 @@ void WebAssemblyTablePrototype::initialize(JS::GlobalObject& global_object)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
{
auto delta = vm.argument(0).to_u32(global_object);
if (vm.exception())
return {};
auto delta = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object));
auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
if (!is<WebAssemblyTableObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
@ -59,9 +58,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
{
auto index = vm.argument(0).to_u32(global_object);
if (vm.exception())
return {};
auto index = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object));
auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
if (!is<WebAssemblyTableObject>(this_object)) {
@ -89,9 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
{
auto index = vm.argument(0).to_u32(global_object);
if (vm.exception())
return {};
auto index = TRY_OR_DISCARD(vm.argument(0).to_u32(global_object));
auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
if (!is<WebAssemblyTableObject>(this_object)) {