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

LibJS: Convert to_string() to ThrowCompletionOr

Also update get_function_name() to use ThrowCompletionOr, but this is
not a standard AO and should be refactored out of existence eventually.
This commit is contained in:
Linus Groh 2021-10-12 17:49:01 +01:00
parent 5d38cf4973
commit 4d8912a92b
48 changed files with 171 additions and 415 deletions

View file

@ -38,9 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::escape)
return {};
}
auto identifier = vm.argument(0).to_string(global_object);
if (vm.exception())
return {};
auto identifier = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
return JS::js_string(vm, Web::CSS::serialize_an_identifier(identifier));
}
@ -55,17 +53,13 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
if (vm.argument_count() >= 2) {
// When the supports(property, value) method is invoked with two arguments property and value:
String property_name = vm.argument(0).to_string(global_object);
if (vm.exception())
return {};
auto property_name = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
// If property is an ASCII case-insensitive match for any defined CSS property that the UA supports,
// and value successfully parses according to that propertys grammar, return true.
auto property = CSS::property_id_from_string(property_name);
if (property != CSS::PropertyID::Invalid) {
auto value_string = vm.argument(1).to_string(global_object);
if (vm.exception())
return {};
auto value_string = TRY_OR_DISCARD(vm.argument(1).to_string(global_object));
if (parse_css_value({}, value_string, property))
return JS::Value(true);
}
@ -79,9 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
return JS::Value(false);
} else {
// When the supports(conditionText) method is invoked with a single conditionText argument:
String supports_text = vm.argument(0).to_string(global_object);
if (vm.exception())
return {};
auto supports_text = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
// If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.
if (auto supports = parse_css_supports({}, supports_text); supports && supports->matches())