Bug 1777982 - Propagate flags from original property to aliases. r=AlaskanEmily

Even we don't have internal aliases right now (and that seems a bit
silly) we do have pref-gated aliases. An alias ID passed to IsEnabled
with the wrong EnabledState would misbehave, assert, and crash.

Though we don't have such callers in the tree because InspectorUtils
passes only arguments that make us not look at the flags, it seems more
reliable this way.

Differential Revision: https://phabricator.services.mozilla.com/D151594
This commit is contained in:
Emilio Cobos Álvarez 2022-07-12 22:22:17 +00:00
parent daab9825a4
commit 7c3737dc89
7 changed files with 29 additions and 26 deletions

View File

@ -14,7 +14,7 @@ def generate(output, dataFile):
)
def can_animate_on_compositor(p):
return "CanAnimateOnCompositor" in p.flags
return "CanAnimateOnCompositor" in p.flags and p.type() != "alias"
properties = runpy.run_path(dataFile)["data"]
properties = filter(can_animate_on_compositor, properties)

View File

@ -65,7 +65,7 @@ def generate_header(output, data):
#endif
#ifndef CSS_PROP_ALIAS
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, pref_) /* nothing */
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, flags_, pref_) /* nothing */
#define DEFINED_CSS_PROP_ALIAS
#endif
@ -83,22 +83,22 @@ def generate_header(output, data):
}
for prop in data:
is_internal = "Internal" in prop.flags
flags = " | ".join(
"CSSPropFlags::{}".format(flag)
for flag in prop.flags
if flag not in COMPILE_TIME_FLAGS
)
if not flags:
flags = "CSSPropFlags(0)"
pref = '"' + prop.pref + '"'
method = prop.method
if prop.type() == "alias":
params = [prop.name, prop.alias_id, prop.prop_id, prop.method, pref]
params = [prop.name, prop.alias_id, prop.prop_id, method, flags, pref]
else:
method = prop.method
if method == "CssFloat":
method = "CSS_PROP_PUBLIC_OR_PRIVATE(CssFloat, Float)"
elif method.startswith("Moz"):
method = "CSS_PROP_DOMPROP_PREFIXED({})".format(method[3:])
flags = " | ".join(
"CSSPropFlags::{}".format(flag)
for flag in prop.flags
if flag not in COMPILE_TIME_FLAGS
)
if not flags:
flags = "CSSPropFlags(0)"
params = [prop.name, prop.id, method, flags, pref]
excludes = []
if is_internal:

View File

@ -98,7 +98,7 @@ LONGHANDS_NOT_SERIALIZED_WITH_SERVO = [
]
def serialized_by_servo(prop):
if prop.type() == "shorthand":
if prop.type() == "shorthand" or prop.type() == "alias":
return True
# Keywords are all fine, except -moz-osx-font-smoothing, which does
# resistfingerprinting stuff.
@ -158,6 +158,6 @@ data = [
% endfor
% for prop in data.all_aliases():
Alias("${prop.name}", "${prop.camel_case}", "${prop.ident}", "${prop.original.ident}", [${rules(prop)}], [], ${pref(prop)}),
Alias("${prop.name}", "${prop.camel_case}", "${prop.ident}", "${prop.original.ident}", [${rules(prop)}], [${flags(prop)}], ${pref(prop)}),
% endfor
]

View File

@ -178,10 +178,12 @@ const nsCString& nsCSSProps::GetStringValue(nsCSSCounterDesc aCounterDesc) {
return sNullStr;
}
const CSSPropFlags nsCSSProps::kFlagsTable[eCSSProperty_COUNT] = {
const CSSPropFlags nsCSSProps::kFlagsTable[eCSSProperty_COUNT_with_aliases] = {
#define CSS_PROP_LONGHAND(name_, id_, method_, flags_, ...) flags_,
#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, ...) flags_,
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, flags_, ...) flags_,
#include "mozilla/ServoCSSPropList.h"
#undef CSS_PROP_ALIAS
#undef CSS_PROP_SHORTHAND
#undef CSS_PROP_LONGHAND
};
@ -200,7 +202,8 @@ bool nsCSSProps::gPropertyEnabled[eCSSProperty_COUNT_with_aliases] = {
IS_ENABLED_BY_DEFAULT(flags_),
#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, ...) \
IS_ENABLED_BY_DEFAULT(flags_),
#define CSS_PROP_ALIAS(...) true,
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, flags_, ...) \
IS_ENABLED_BY_DEFAULT(flags_),
#include "mozilla/ServoCSSPropList.h"
#undef CSS_PROP_ALIAS
#undef CSS_PROP_SHORTHAND

View File

@ -99,11 +99,11 @@ class nsCSSProps {
static const nsCString& GetStringValue(nsCSSCounterDesc aCounterDesc);
private:
static const Flags kFlagsTable[eCSSProperty_COUNT];
static const Flags kFlagsTable[eCSSProperty_COUNT_with_aliases];
public:
static bool PropHasFlags(nsCSSPropertyID aProperty, Flags aFlags) {
MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT,
MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT_with_aliases,
"out of range");
return (nsCSSProps::kFlagsTable[aProperty] & aFlags) == aFlags;
}
@ -183,21 +183,20 @@ class nsCSSProps {
return kIDLNameSortPositionTable[aProperty];
}
static bool IsEnabled(nsCSSPropertyID aProperty) {
public:
static bool IsEnabled(nsCSSPropertyID aProperty, EnabledState aEnabled) {
MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT_with_aliases,
"out of range");
// In the child process, assert that we're not trying to parse stylesheets
// before we've gotten all our prefs.
MOZ_ASSERT_IF(!XRE_IsParentProcess(),
mozilla::Preferences::ArePrefsInitedInContentProcess());
return gPropertyEnabled[aProperty];
}
public:
static bool IsEnabled(nsCSSPropertyID aProperty, EnabledState aEnabled) {
if (IsEnabled(aProperty)) {
if (gPropertyEnabled[aProperty]) {
return true;
}
MOZ_ASSERT(aProperty < eCSSProperty_COUNT,
"gPropertyEnabled[aProperty] should have been true for alias "
"properties");
if (aEnabled == EnabledState::IgnoreEnabledState) {
return true;
}

View File

@ -58,7 +58,7 @@ const PropertyInfo gShorthandProperties[] = {
#define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_
#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) \
{#name_, STRINGIFY_METHOD(method_), pref_},
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, pref_) \
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, flags_, pref_) \
{#name_, #method_, pref_},
#include "mozilla/ServoCSSPropList.h"
@ -74,7 +74,7 @@ const char* gShorthandPropertiesWithDOMProp[] = {
#define CSS_PROP_LIST_EXCLUDE_INTERNAL
#define CSS_PROP_SHORTHAND(name_, id_, method_, flags_, pref_) #name_,
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, pref_) #name_,
#define CSS_PROP_ALIAS(name_, aliasid_, id_, method_, flags_, pref_) #name_,
#include "mozilla/ServoCSSPropList.h"

View File

@ -606,6 +606,7 @@ class Alias(object):
self.gecko_pref = gecko_pref
self.transitionable = original.transitionable
self.rule_types_allowed = original.rule_types_allowed
self.flags = original.flags
@staticmethod
def type():