mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:27:35 +00:00
LibJS: Convert to_u32() to ThrowCompletionOr
This commit is contained in:
parent
f6a5ff7b00
commit
cc94bba5c0
14 changed files with 32 additions and 69 deletions
|
@ -47,16 +47,12 @@ JS::Value ImageConstructor::construct(FunctionObject&)
|
|||
auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML);
|
||||
|
||||
if (vm().argument_count() > 0) {
|
||||
u32 width = vm().argument(0).to_u32(global_object());
|
||||
if (vm().exception())
|
||||
return {};
|
||||
u32 width = TRY_OR_DISCARD(vm().argument(0).to_u32(global_object()));
|
||||
image_element->set_attribute(HTML::AttributeNames::width, String::formatted("{}", width));
|
||||
}
|
||||
|
||||
if (vm().argument_count() > 1) {
|
||||
u32 height = vm().argument(1).to_u32(global_object());
|
||||
if (vm().exception())
|
||||
return {};
|
||||
u32 height = TRY_OR_DISCARD(vm().argument(1).to_u32(global_object()));
|
||||
image_element->set_attribute(HTML::AttributeNames::height, String::formatted("{}", height));
|
||||
}
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue