mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +00:00
LibWeb: Convert the CSS namespace object to ThrowCompletionOr
This commit is contained in:
parent
85dc3a8099
commit
0f93c9d6c8
2 changed files with 14 additions and 19 deletions
|
@ -26,40 +26,35 @@ void CSSNamespace::initialize(JS::GlobalObject& global_object)
|
||||||
{
|
{
|
||||||
Object::initialize(global_object);
|
Object::initialize(global_object);
|
||||||
u8 attr = JS::Attribute::Enumerable;
|
u8 attr = JS::Attribute::Enumerable;
|
||||||
define_old_native_function("escape", escape, 1, attr);
|
define_native_function("escape", escape, 1, attr);
|
||||||
define_old_native_function("supports", supports, 2, attr);
|
define_native_function("supports", supports, 2, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/cssom-1/#dom-css-escape
|
// https://www.w3.org/TR/cssom-1/#dom-css-escape
|
||||||
JS_DEFINE_OLD_NATIVE_FUNCTION(CSSNamespace::escape)
|
JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::escape)
|
||||||
{
|
{
|
||||||
if (!vm.argument_count()) {
|
if (!vm.argument_count())
|
||||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "CSS.escape");
|
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "CSS.escape");
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
auto identifier = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
|
|
||||||
|
|
||||||
|
auto identifier = TRY(vm.argument(0).to_string(global_object));
|
||||||
return JS::js_string(vm, Web::CSS::serialize_an_identifier(identifier));
|
return JS::js_string(vm, Web::CSS::serialize_an_identifier(identifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
|
// https://www.w3.org/TR/css-conditional-3/#dom-css-supports
|
||||||
JS_DEFINE_OLD_NATIVE_FUNCTION(CSSNamespace::supports)
|
JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports)
|
||||||
{
|
{
|
||||||
if (!vm.argument_count()) {
|
if (!vm.argument_count())
|
||||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "CSS.supports");
|
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountAtLeastOne, "CSS.supports");
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vm.argument_count() >= 2) {
|
if (vm.argument_count() >= 2) {
|
||||||
// When the supports(property, value) method is invoked with two arguments property and value:
|
// When the supports(property, value) method is invoked with two arguments property and value:
|
||||||
auto property_name = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
|
auto property_name = TRY(vm.argument(0).to_string(global_object));
|
||||||
|
|
||||||
// If property is an ASCII case-insensitive match for any defined CSS property that the UA supports,
|
// If property is an ASCII case-insensitive match for any defined CSS property that the UA supports,
|
||||||
// and value successfully parses according to that property’s grammar, return true.
|
// and value successfully parses according to that property’s grammar, return true.
|
||||||
auto property = CSS::property_id_from_string(property_name);
|
auto property = CSS::property_id_from_string(property_name);
|
||||||
if (property != CSS::PropertyID::Invalid) {
|
if (property != CSS::PropertyID::Invalid) {
|
||||||
auto value_string = TRY_OR_DISCARD(vm.argument(1).to_string(global_object));
|
auto value_string = TRY(vm.argument(1).to_string(global_object));
|
||||||
if (parse_css_value({}, value_string, property))
|
if (parse_css_value({}, value_string, property))
|
||||||
return JS::Value(true);
|
return JS::Value(true);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +68,7 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(CSSNamespace::supports)
|
||||||
return JS::Value(false);
|
return JS::Value(false);
|
||||||
} else {
|
} else {
|
||||||
// When the supports(conditionText) method is invoked with a single conditionText argument:
|
// When the supports(conditionText) method is invoked with a single conditionText argument:
|
||||||
auto supports_text = TRY_OR_DISCARD(vm.argument(0).to_string(global_object));
|
auto supports_text = TRY(vm.argument(0).to_string(global_object));
|
||||||
|
|
||||||
// If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true.
|
// 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())
|
if (auto supports = parse_css_supports({}, supports_text); supports && supports->matches())
|
||||||
|
|
|
@ -21,8 +21,8 @@ public:
|
||||||
virtual ~CSSNamespace() override;
|
virtual ~CSSNamespace() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(escape);
|
JS_DECLARE_NATIVE_FUNCTION(escape);
|
||||||
JS_DECLARE_OLD_NATIVE_FUNCTION(supports);
|
JS_DECLARE_NATIVE_FUNCTION(supports);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue