Commit 829eebab authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

[mpc] Clear CachedMatchedProperties::matched_properties_types

Not really part of the MatchedPropertiesCache project, but we are
obviously missing a clear() call for the matched_properties_types
vector. It looks to me like this could potentially cause non-
deterministic crashes in case of hash collisions (operator== makes
assumptions about the size this vector), although no such crashes are
known.

Bug: 1057072
Change-Id: Ia741544fe2e69eba505c57e8315e01786674a56f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2207153
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770371}
parent 213ef4b1
...@@ -69,6 +69,7 @@ void CachedMatchedProperties::Set( ...@@ -69,6 +69,7 @@ void CachedMatchedProperties::Set(
void CachedMatchedProperties::Clear() { void CachedMatchedProperties::Clear() {
matched_properties.clear(); matched_properties.clear();
matched_properties_types.clear();
computed_style = nullptr; computed_style = nullptr;
parent_computed_style = nullptr; parent_computed_style = nullptr;
dependencies.clear(); dependencies.clear();
......
...@@ -36,7 +36,7 @@ namespace blink { ...@@ -36,7 +36,7 @@ namespace blink {
class ComputedStyle; class ComputedStyle;
class StyleResolverState; class StyleResolverState;
class CachedMatchedProperties final class CORE_EXPORT CachedMatchedProperties final
: public GarbageCollected<CachedMatchedProperties> { : public GarbageCollected<CachedMatchedProperties> {
public: public:
// Caches data of MatchedProperties. See |MatchedPropertiesCache::Cache| for // Caches data of MatchedProperties. See |MatchedPropertiesCache::Cache| for
......
...@@ -92,6 +92,35 @@ class MatchedPropertiesCacheTest : public PageTestBase, ...@@ -92,6 +92,35 @@ class MatchedPropertiesCacheTest : public PageTestBase,
} }
}; };
TEST_F(MatchedPropertiesCacheTest, ClearEntry) {
MatchResult result;
result.AddMatchedProperties(
css_test_helpers::ParseDeclarationBlock("top:inherit"));
auto style = CreateStyle();
auto parent = CreateStyle();
HashSet<CSSPropertyName> dependencies;
dependencies.insert(CSSPropertyName(CSSPropertyID::kTop));
auto* entry = MakeGarbageCollected<CachedMatchedProperties>();
entry->Set(*style, *parent, result.GetMatchedProperties(), dependencies);
EXPECT_TRUE(entry->computed_style);
EXPECT_TRUE(entry->parent_computed_style);
EXPECT_FALSE(entry->matched_properties.IsEmpty());
EXPECT_FALSE(entry->matched_properties_types.IsEmpty());
EXPECT_FALSE(entry->dependencies.IsEmpty());
entry->Clear();
EXPECT_FALSE(entry->computed_style);
EXPECT_FALSE(entry->parent_computed_style);
EXPECT_TRUE(entry->matched_properties.IsEmpty());
EXPECT_TRUE(entry->matched_properties_types.IsEmpty());
EXPECT_TRUE(entry->dependencies.IsEmpty());
}
TEST_F(MatchedPropertiesCacheTest, AllowedKeyValues) { TEST_F(MatchedPropertiesCacheTest, AllowedKeyValues) {
unsigned empty = HashTraits<unsigned>::EmptyValue(); unsigned empty = HashTraits<unsigned>::EmptyValue();
unsigned deleted = std::numeric_limits<unsigned>::max(); unsigned deleted = std::numeric_limits<unsigned>::max();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment