diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-10-08 16:00:05 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-08 23:02:57 +0200 |
commit | bc0ef5f69d31369922d82ee468e90c34d7eea8c7 (patch) | |
tree | 3381c22b344817d69f4d55dc7d6a721a2c7192f7 /Userland/Libraries/LibWeb/Bindings | |
parent | b1f8a73a0578e85b983eaa2edeb1ccf28ef0cfaf (diff) | |
download | serenity-bc0ef5f69d31369922d82ee468e90c34d7eea8c7.zip |
LibWeb: Implement `CSS.supports(string)` function :^)
Websites being able to query whether we support a given CSS feature
should prevent them from loading unnecessary polyfills for things we
already support! Or at least, that's the nice theory. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings')
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp b/Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp index 3cc12c444f..d43e86aed7 100644 --- a/Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp +++ b/Userland/Libraries/LibWeb/Bindings/CSSNamespace.cpp @@ -79,12 +79,19 @@ JS_DEFINE_NATIVE_FUNCTION(CSSNamespace::supports) return JS::Value(false); } else { // When the supports(conditionText) method is invoked with a single conditionText argument: - // - // If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true. - // - // Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true. - // - // Otherwise, return false. + String supports_text = vm.argument(0).to_string(global_object); + if (vm.exception()) + return {}; + + // 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()) + return JS::Value(true); + + // Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true. + if (auto supports = parse_css_supports({}, String::formatted("({})", supports_text)); supports && supports->matches()) + return JS::Value(true); + + // Otherwise, return false. return JS::Value(false); } } |