Commit 44d897b0 authored by Michael Lippautz's avatar Michael Lippautz Committed by Commit Bot

[wrapper-tracing] Properly trace rule lists of StyleSheet

Otherwise the JS wrappers will get lost.

Bug: chromium:830910
Change-Id: I7f746698b6ce05d9b2e3ce26f778a2e08d0c3cd6
Reviewed-on: https://chromium-review.googlesource.com/1059251
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558742}
parent d64dd608
......@@ -4,23 +4,23 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS document.styleSheets[0].cssRules[0].type is CSSRule.IMPORT_RULE
FAIL document.styleSheets[0].cssRules[0].media.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[0].media.foo is 'bar'
PASS document.styleSheets[0].cssRules[0].type is CSSRule.IMPORT_RULE
FAIL document.styleSheets[0].cssRules[0].styleSheet.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[0].styleSheet.foo is 'bar'
PASS document.styleSheets[0].cssRules[1].type is CSSRule.STYLE_RULE
FAIL document.styleSheets[0].cssRules[1].style.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[1].style.foo is 'bar'
PASS document.styleSheets[0].cssRules[2].type is CSSRule.FONT_FACE_RULE
FAIL document.styleSheets[0].cssRules[2].style.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[2].style.foo is 'bar'
PASS document.styleSheets[0].cssRules[3].type is CSSRule.MEDIA_RULE
FAIL document.styleSheets[0].cssRules[3].cssRules.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[3].cssRules.foo is 'bar'
PASS document.styleSheets[0].cssRules[3].type is CSSRule.MEDIA_RULE
FAIL document.styleSheets[0].cssRules[3].media.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[3].media.foo is 'bar'
PASS document.styleSheets[0].cssRules[4].type is CSSRule.KEYFRAMES_RULE
FAIL document.styleSheets[0].cssRules[4].cssRules.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[4].cssRules.foo is 'bar'
PASS document.styleSheets[0].cssRules[4].cssRules[0].type is CSSRule.KEYFRAME_RULE
FAIL document.styleSheets[0].cssRules[4].cssRules[0].style.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[5].type is CSSRule.PAGE_RULE
FAIL document.styleSheets[0].cssRules[5].style.foo should be bar (of type string). Was undefined (of type undefined).
PASS document.styleSheets[0].cssRules[5].style.foo is 'bar'
PASS successfullyParsed is true
TEST COMPLETE
......
......@@ -87,7 +87,7 @@ FAIL: document.body.style.myCustomProperty should be 1 but instead is undefined.
PASS: document.styleSheets.myCustomProperty should be 1 and is.
PASS: document.styleSheets[0].myCustomProperty should be 1 and is.
PASS: document.styleSheets[0].cssRules.myCustomProperty should be 1 and is.
FAIL: document.styleSheets[0].cssRules[0].myCustomProperty should be 1 but instead is undefined.
PASS: document.styleSheets[0].cssRules[0].myCustomProperty should be 1 and is.
PASS: document.getElementsByTagName('style')[0].sheet.myCustomProperty should be 1 and is.
PASS: document.getElementsByTagName('svg')[0].firstChild.sheet.myCustomProperty should be 1 and is.
PASS: new XPathEvaluator().myCustomProperty should be undefined and is.
......
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<head>
<style>
.doesntexit { display: none }
</style>
<script>
test(() => {
document.styleSheets[0].cssRules[0].custom_property = 'persist';
gc();
assert_equals(
"persist",
document.styleSheets[0].cssRules[0].custom_property,
"Should not loose property on GC.")
}, 'Tests properties on style sheet rules are not lost. See http://crbug.com/830910.');
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
......@@ -60,6 +60,11 @@ class StyleSheetCSSRuleList final : public CSSRuleList {
CSSRuleList::Trace(visitor);
}
void TraceWrappers(ScriptWrappableVisitor* visitor) const override {
visitor->TraceWrappers(style_sheet_);
CSSRuleList::TraceWrappers(visitor);
}
private:
StyleSheetCSSRuleList(CSSStyleSheet* sheet) : style_sheet_(sheet) {}
......@@ -70,7 +75,7 @@ class StyleSheetCSSRuleList final : public CSSRuleList {
CSSStyleSheet* GetStyleSheet() const override { return style_sheet_; }
Member<CSSStyleSheet> style_sheet_;
TraceWrapperMember<CSSStyleSheet> style_sheet_;
};
#if DCHECK_IS_ON()
......@@ -577,4 +582,13 @@ void CSSStyleSheet::Trace(blink::Visitor* visitor) {
StyleSheet::Trace(visitor);
}
void CSSStyleSheet::TraceWrappers(
blink::ScriptWrappableVisitor* visitor) const {
for (auto& rule : child_rule_cssom_wrappers_) {
visitor->TraceWrappers(rule);
}
visitor->TraceWrappers(rule_list_cssom_wrapper_);
StyleSheet::TraceWrappers(visitor);
}
} // namespace blink
......@@ -28,6 +28,7 @@
#include "third_party/blink/renderer/core/css/media_query_evaluator.h"
#include "third_party/blink/renderer/core/css/style_sheet.h"
#include "third_party/blink/renderer/core/dom/tree_scope.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_member.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/noncopyable.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding.h"
......@@ -182,6 +183,7 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet {
bool CanBeActivated(const String& current_preferrable_name) const;
void Trace(blink::Visitor*) override;
void TraceWrappers(blink::ScriptWrappableVisitor*) const override;
private:
CSSStyleSheet(StyleSheetContents*, CSSImportRule* owner_rule);
......@@ -228,8 +230,8 @@ class CORE_EXPORT CSSStyleSheet final : public StyleSheet {
TextPosition start_position_;
Member<MediaList> media_cssom_wrapper_;
mutable HeapVector<Member<CSSRule>> child_rule_cssom_wrappers_;
mutable Member<CSSRuleList> rule_list_cssom_wrapper_;
mutable HeapVector<TraceWrapperMember<CSSRule>> child_rule_cssom_wrappers_;
mutable TraceWrapperMember<CSSRuleList> rule_list_cssom_wrapper_;
DISALLOW_COPY_AND_ASSIGN(CSSStyleSheet);
};
......
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