Bug 1647845 Part 1 - Ignore any properties which aren't valid for a style rule when generating CSS2Properties and testing properties r=emilio

To know the valid rules for each property, we need to put this information
into the Servo prop list and add an appropriate getter to Longhand/Shorthand.

Differential Revision: https://phabricator.services.mozilla.com/D105825
This commit is contained in:
Emily McDonough 2021-03-16 19:54:27 +00:00
Родитель 8c6c55a9de
Коммит 6f8201b62d
7 изменённых файлов: 81 добавлений и 9 удалений

Просмотреть файл

@ -25,6 +25,11 @@ def generate(output, idlFilename, dataFile):
for p in propList:
if "Internal" in p.flags:
continue
# Skip properties which aren't valid in style rules.
if "Style" not in p.rules:
continue
# Unfortunately, even some of the getters here are fallible
# (e.g. on nsComputedDOMStyle).
extendedAttrs = [

Просмотреть файл

@ -100,11 +100,20 @@ def generate_header(output, data):
if not flags:
flags = "CSSPropFlags(0)"
params = [prop.name, prop.id, method, flags, pref]
excludes = []
if is_internal:
excludes.append("CSS_PROP_LIST_EXCLUDE_INTERNAL")
if "Style" not in prop.rules:
excludes.append("CSS_PROP_LIST_EXCLUDE_NOT_IN_STYLE")
if is_internal:
output.write("#ifndef CSS_PROP_LIST_EXCLUDE_INTERNAL\n")
if excludes:
output.write(
"#if {}\n".format(
" || ".join("!defined " + exclude for exclude in excludes)
)
)
output.write("{}({})\n".format(MACRO_NAMES[prop.type()], ", ".join(params)))
if is_internal:
if excludes:
output.write("#endif\n")
output.write(

Просмотреть файл

@ -8,7 +8,7 @@ def _assign_slots(obj, args):
class Longhand(object):
__slots__ = ["name", "method", "id", "flags", "pref"]
__slots__ = ["name", "method", "id", "rules", "flags", "pref"]
def __init__(self, *args):
_assign_slots(self, args)
@ -19,7 +19,7 @@ class Longhand(object):
class Shorthand(object):
__slots__ = ["name", "method", "id", "flags", "pref", "subprops"]
__slots__ = ["name", "method", "id", "rules", "flags", "pref", "subprops"]
def __init__(self, *args):
_assign_slots(self, args)
@ -30,7 +30,7 @@ class Shorthand(object):
class Alias(object):
__slots__ = ["name", "method", "alias_id", "prop_id", "flags", "pref"]
__slots__ = ["name", "method", "alias_id", "prop_id", "rules", "flags", "pref"]
def __init__(self, *args):
_assign_slots(self, args)
@ -123,6 +123,9 @@ def exposed_on_getcs(prop):
if prop.type() == "shorthand":
return "SHORTHAND_IN_GETCS" in prop.flags
def rules(prop):
return ", ".join('"{}"'.format(rule) for rule in prop.rule_types_allowed_names())
def flags(prop):
result = []
if prop.explicitly_enabled_in_chrome():
@ -154,15 +157,15 @@ def sub_properties(prop):
data = [
% for prop in data.longhands:
Longhand("${prop.name}", "${method(prop)}", "${prop.ident}", [${flags(prop)}], ${pref(prop)}),
Longhand("${prop.name}", "${method(prop)}", "${prop.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)}),
% endfor
% for prop in data.shorthands:
Shorthand("${prop.name}", "${prop.camel_case}", "${prop.ident}", [${flags(prop)}], ${pref(prop)},
Shorthand("${prop.name}", "${prop.camel_case}", "${prop.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)},
[${sub_properties(prop)}]),
% endfor
% for prop in data.all_aliases():
Alias("${prop.name}", "${prop.camel_case}", "${prop.ident}", "${prop.original.ident}", [], ${pref(prop)}),
Alias("${prop.name}", "${prop.camel_case}", "${prop.ident}", "${prop.original.ident}", [${rules(prop)}], [], ${pref(prop)}),
% endfor
]

Просмотреть файл

@ -107,6 +107,7 @@ class nsDOMCSSDeclaration : public nsICSSDeclaration {
}
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
#define CSS_PROP_LIST_EXCLUDE_NOT_IN_STYLE
#define CSS_PROP_LONGHAND(name_, id_, method_, ...) CSS_PROP(id_, method_)
#define CSS_PROP_SHORTHAND(name_, id_, method_, ...) CSS_PROP(id_, method_)
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, ...) \
@ -116,6 +117,7 @@ class nsDOMCSSDeclaration : public nsICSSDeclaration {
#undef CSS_PROP_SHORTHAND
#undef CSS_PROP_LONGHAND
#undef CSS_PROP_LIST_EXCLUDE_INTERNAL
#undef CSS_PROP_LIST_EXCLUDE_NOT_IN_STYLE
#undef CSS_PROP
#undef CSS_PROP_PUBLIC_OR_PRIVATE

Просмотреть файл

@ -10,6 +10,9 @@
#include <stdlib.h>
#include "mozilla/ArrayUtils.h"
// Do not consider properties not valid in style rules
#define CSS_PROP_LIST_EXCLUDE_NOT_IN_STYLE
// Need an extra level of macro nesting to force expansion of method_
// params before they get pasted.
#define STRINGIFY_METHOD(method_) #method_

Просмотреть файл

@ -261,6 +261,11 @@ class Property(object):
self.extra_prefixes = parse_property_aliases(extra_prefixes)
self.flags = flags.split() if flags else []
def rule_types_allowed_names(self):
for name in RULE_VALUES:
if self.rule_types_allowed & RULE_VALUES[name] != 0:
yield name
def experimental(self, engine):
if engine == "gecko":
return bool(self.gecko_pref)
@ -598,6 +603,11 @@ class Alias(object):
def type():
return "alias"
def rule_types_allowed_names(self):
for name in RULE_VALUES:
if self.rule_types_allowed & RULE_VALUES[name] != 0:
yield name
def experimental(self, engine):
if engine == "gecko":
return bool(self.gecko_pref)

Просмотреть файл

@ -0,0 +1,40 @@
<!DOCTYPE HTML>
<html>
<head>
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://drafts.csswg.org/cssom/#the-cssstyledeclaration-interface">
<title>Page descriptors shouldn't be exposed to CSS Style declarations</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="target"></div>
<script>
'use strict';
let element = document.getElementById("target");
let computedStyle = window.getComputedStyle(element);
let style = element.style;
test(t => {
assert_equals(computedStyle.size, undefined,
"computed style should not have size property");
assert_equals(computedStyle.getPropertyValue("size"), "",
"computed style getPropertyValue(\"size\") should be empty");
assert_equals(style.size, undefined,
"style should not have size property");
assert_equals(style.getPropertyValue("size"), "",
"style getPropertyValue(\"size\") should be empty");
for(const val of ["initial", "auto", "100px"]){
style.setProperty("size", val);
assert_false(CSS.supports("size", val));
assert_equals(style.size, undefined,
"style should not have size property after assigning size=" + val);
assert_equals(style.getPropertyValue("size"), "",
"style getPropertyValue(\"size\") should be empty after assigning size=" + val);
}
});
</script>
</body>
</html>