Skip to content

Commit

Permalink
fix: fix document member leak.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Oct 31, 2024
1 parent 4d3f4d4 commit 10e63cd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions bridge/core/css/css_style_sheet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ void CSSStyleSheet::Trace(GCVisitor* visitor) const {
}
visitor->TraceMember(rule_list_cssom_wrapper_);
visitor->TraceMember(constructor_document_);
contents_->Trace(visitor);
StyleSheet::Trace(visitor);
}

Expand Down
2 changes: 1 addition & 1 deletion bridge/core/css/style_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void StyleElement::ClearSheet(Element& owner_element) {
sheet_.Release()->ClearOwnerNode();
}

StyleElement::ProcessingResult StyleElement:: CreateSheet(Element& element, const std::string& text) {
StyleElement::ProcessingResult StyleElement::CreateSheet(Element& element, const std::string& text) {
assert(element.isConnected());
assert(IsSameObject(element));
Document& document = element.GetDocument();
Expand Down
58 changes: 29 additions & 29 deletions bridge/core/html/html_style_element_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@
using namespace webf;

TEST(HTMLStyleElement, appendStyleToDocument) {
// bool static errorCalled = false;
// bool static logCalled = false;
// webf::WebFPage::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
// EXPECT_STREQ(message.c_str(), "1234");
// logCalled = true;
// };
// auto env = TEST_init([](double contextId, const char* errmsg) {
// WEBF_LOG(VERBOSE) << errmsg;
// errorCalled = true;
// });
// auto context = env->page()->executingContext();
// const char* code = R"(
// const style = document.createElement('style');
// style.innerHTML = `
//.container {
// width: 20px;
// height: 20px;
// border: 1px solid #000;
//}
//`;
// document.head.appendChild(style);
//
// const div = document.createElement('div');
// div.className = 'container';
// document.body.appendChild(div);
//)";
// env->page()->evaluateScript(code, strlen(code), "vm://", 0);
//
// EXPECT_EQ(errorCalled, false);
bool static errorCalled = false;
bool static logCalled = false;
webf::WebFPage::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
EXPECT_STREQ(message.c_str(), "1234");
logCalled = true;
};
auto env = TEST_init([](double contextId, const char* errmsg) {
WEBF_LOG(VERBOSE) << errmsg;
errorCalled = true;
});
auto context = env->page()->executingContext();
const char* code = R"(
const style = document.createElement('style');
style.innerHTML = `
.container {
width: 20px;
height: 20px;
border: 1px solid #000;
}
`;
document.head.appendChild(style);
const div = document.createElement('div');
div.className = 'container';
document.body.appendChild(div);
)";
env->page()->evaluateScript(code, strlen(code), "vm://", 0);

EXPECT_EQ(errorCalled, false);
}

0 comments on commit 10e63cd

Please sign in to comment.