Skip to content

Commit

Permalink
style: Add check for non-Copy specified value to ensure specified_is_…
Browse files Browse the repository at this point in the history
…copy always returns the right result.

Differential Revision: https://phabricator.services.mozilla.com/D2931
  • Loading branch information
upsuper authored and emilio committed Aug 18, 2018
1 parent e7945bb commit e22850d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
13 changes: 13 additions & 0 deletions components/style/properties/data.py
Expand Up @@ -290,14 +290,22 @@ def specified_is_copy(self):
"AlignContent",
"AlignItems",
"AlignSelf",
"Appearance",
"BackgroundRepeat",
"BorderImageRepeat",
"BorderStyle",
"Clear",
"ColumnCount",
"Contain",
"Display",
"Float",
"FontSizeAdjust",
"FontStretch",
"FontStyle",
"FontStyleAdjust",
"FontSynthesis",
"FontWeight",
"GreaterThanOrEqualToOneNumber",
"GridAutoFlow",
"InitialLetter",
"Integer",
Expand All @@ -311,17 +319,22 @@ def specified_is_copy(self):
"NonNegativeNumber",
"Opacity",
"OutlineStyle",
"OverflowClipBox",
"OverscrollBehavior",
"Percentage",
"SVGOpacity",
"SVGPaintOrder",
"ScrollSnapType",
"TextAlign",
"TextDecorationLine",
"TouchAction",
"TransformStyle",
"XSpan",
"XTextZoom",
"ZIndex",
}
if self.name == "overflow-y":
return True
return bool(self.keyword)

def animated_type(self):
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhands/box.mako.rs
Expand Up @@ -448,7 +448,7 @@ ${helpers.predefined_type(

${helpers.predefined_type(
"perspective-origin",
"position::Position",
"Position",
"computed::position::Position::center()",
boxed=True,
extra_prefixes=transform_extra_prefixes,
Expand Down
15 changes: 15 additions & 0 deletions components/style/properties/properties.mako.rs
Expand Up @@ -305,6 +305,21 @@ impl Clone for PropertyDeclaration {
}
}

// This function ensures that all properties not handled above
// do not have a specified value implements Copy. If you hit
// compile error here, you may want to add the type name into
// Longhand.specified_is_copy in data.py.
fn _static_assert_others_are_not_copy() {
struct Helper<T>(T);
trait AssertCopy { fn assert() {} }
trait AssertNotCopy { fn assert() {} }
impl<T: Copy> AssertCopy for Helper<T> {}
% for ty in set(x["type"] for x in others):
impl AssertNotCopy for Helper<${ty}> {}
Helper::<${ty}>::assert();
% endfor
}

match *self {
${" |\n".join("{}(..)".format(v["name"]) for v in copy)} => {
unsafe { debug_unreachable!() }
Expand Down

0 comments on commit e22850d

Please sign in to comment.