mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:17:44 +00:00
LibJS: Convert ErrorPrototype functions to ThrowCompletionOr
This commit is contained in:
parent
c815519a65
commit
47f762ab42
2 changed files with 9 additions and 11 deletions
|
@ -26,28 +26,26 @@ void ErrorPrototype::initialize(GlobalObject& global_object)
|
||||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||||
define_direct_property(vm.names.name, js_string(vm, "Error"), attr);
|
define_direct_property(vm.names.name, js_string(vm, "Error"), attr);
|
||||||
define_direct_property(vm.names.message, js_string(vm, ""), attr);
|
define_direct_property(vm.names.message, js_string(vm, ""), attr);
|
||||||
define_old_native_function(vm.names.toString, to_string, 0, attr);
|
define_native_function(vm.names.toString, to_string, 0, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 20.5.3.4 Error.prototype.toString ( ), https://tc39.es/ecma262/#sec-error.prototype.tostring
|
// 20.5.3.4 Error.prototype.toString ( ), https://tc39.es/ecma262/#sec-error.prototype.tostring
|
||||||
JS_DEFINE_OLD_NATIVE_FUNCTION(ErrorPrototype::to_string)
|
JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string)
|
||||||
{
|
{
|
||||||
auto this_value = vm.this_value(global_object);
|
auto this_value = vm.this_value(global_object);
|
||||||
if (!this_value.is_object()) {
|
if (!this_value.is_object())
|
||||||
vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, this_value.to_string_without_side_effects());
|
return vm.throw_completion<TypeError>(global_object, ErrorType::NotAnObject, this_value.to_string_without_side_effects());
|
||||||
return {};
|
|
||||||
}
|
|
||||||
auto& this_object = this_value.as_object();
|
auto& this_object = this_value.as_object();
|
||||||
|
|
||||||
String name = "Error";
|
String name = "Error";
|
||||||
auto name_property = TRY_OR_DISCARD(this_object.get(vm.names.name));
|
auto name_property = TRY(this_object.get(vm.names.name));
|
||||||
if (!name_property.is_undefined())
|
if (!name_property.is_undefined())
|
||||||
name = TRY_OR_DISCARD(name_property.to_string(global_object));
|
name = TRY(name_property.to_string(global_object));
|
||||||
|
|
||||||
String message = "";
|
String message = "";
|
||||||
auto message_property = TRY_OR_DISCARD(this_object.get(vm.names.message));
|
auto message_property = TRY(this_object.get(vm.names.message));
|
||||||
if (!message_property.is_undefined())
|
if (!message_property.is_undefined())
|
||||||
message = TRY_OR_DISCARD(message_property.to_string(global_object));
|
message = TRY(message_property.to_string(global_object));
|
||||||
|
|
||||||
if (name.is_empty())
|
if (name.is_empty())
|
||||||
return js_string(vm, message);
|
return js_string(vm, message);
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
virtual ~ErrorPrototype() override = default;
|
virtual ~ErrorPrototype() override = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_string);
|
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_NATIVE_ERROR_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
#define DECLARE_NATIVE_ERROR_PROTOTYPE(ClassName, snake_name, PrototypeName, ConstructorName) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue