Skip to content

Commit 1ab3e28

Browse files
committed
fix: fix member memory management.
1 parent 0253965 commit 1ab3e28

File tree

7 files changed

+9
-48
lines changed

7 files changed

+9
-48
lines changed

bridge/bindings/qjs/cppgc/member.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,12 @@ class Member {
3636
raw_ = other.raw_;
3737
runtime_ = other.runtime_;
3838
js_object_ptr_ = other.js_object_ptr_;
39+
((JSRefCountHeader*) other.js_object_ptr_)->ref_count++;
3940
}
4041
~Member() {
4142
if (raw_ != nullptr) {
4243
assert(runtime_ != nullptr);
43-
// There are two ways to free the member values:
44-
// One is by GC marking and sweep stage.
45-
// Two is by free directly when running out of function body.
46-
// We detect the GC phase to handle case two, and free our members by hand(call JS_FreeValueRT directly).
47-
JSGCPhaseEnum phase = JS_GetEnginePhase(runtime_);
48-
if (phase == JS_GC_PHASE_DECREF || phase == JS_GC_PHASE_REMOVE_CYCLES) {
49-
JS_FreeValueRT(runtime_, JS_MKPTR(JS_TAG_OBJECT, js_object_ptr_));
50-
}
44+
JS_FreeValueRT(runtime_, JS_MKPTR(JS_TAG_OBJECT, js_object_ptr_));
5145
}
5246
};
5347

@@ -75,6 +69,7 @@ class Member {
7569
raw_ = other.raw_;
7670
runtime_ = other.runtime_;
7771
js_object_ptr_ = other.js_object_ptr_;
72+
((JSRefCountHeader*) other.js_object_ptr_)->ref_count++;
7873
return *this;
7974
}
8075
// Move assignment.

bridge/core/dom/child_list_mutation_scope.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ ChildListMutationAccumulator::ChildListMutationAccumulator(Node* target,
5252
: target_(target), last_added_(nullptr), observers_(observers), mutation_scopes_(0) {}
5353

5454
ChildListMutationAccumulator::~ChildListMutationAccumulator() {
55-
for(auto& node : removed_nodes_) {
56-
node.Clear();
57-
}
58-
59-
for(auto& node : added_nodes_) {
60-
node.Clear();
61-
}
62-
63-
target_.Clear();
64-
previous_sibling_.Clear();
65-
next_sibling_.Clear();
66-
last_added_.Clear();
6755
}
6856

6957
void ChildListMutationAccumulator::LeaveMutationScope() {

bridge/core/dom/child_list_mutation_scope.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ class ChildListMutationScope final {
8181
}
8282

8383
void ChildAdded(Node& child) {
84-
// if (accumulator_ && accumulator_->HasObservers())
85-
// accumulator_->ChildAdded(child);
84+
if (accumulator_ && accumulator_->HasObservers())
85+
accumulator_->ChildAdded(child);
8686
}
8787

8888
void WillRemoveChild(Node& child) {
89-
// if (accumulator_ && accumulator_->HasObservers())
90-
// accumulator_->WillRemoveChild(child);
89+
if (accumulator_ && accumulator_->HasObservers())
90+
accumulator_->WillRemoveChild(child);
9191
}
9292

9393
private:

bridge/core/dom/collection_items_cache.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ template <typename Collection, typename NodeType>
7272
void CollectionItemsCache<Collection, NodeType>::Invalidate() {
7373
Base::Invalidate();
7474
if (list_valid_) {
75-
for (auto& item : cached_list_) {
76-
item.Clear();
77-
}
7875
cached_list_.clear();
7976
list_valid_ = false;
8077
}
@@ -88,7 +85,8 @@ unsigned CollectionItemsCache<Collection, NodeType>::NodeCount(const Collection&
8885
NodeType* current_node = collection.TraverseToFirst();
8986
unsigned current_index = 0;
9087
while (current_node) {
91-
cached_list_.push_back(current_node);
88+
cached_list_.emplace_back(current_node);
89+
// cached_list_.push_back(current_node);
9290
current_node = collection.TraverseForwardToOffset(current_index + 1, *current_node, current_index);
9391
}
9492

bridge/core/dom/mutation_observer_interest_group.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ MutationObserverInterestGroup::MutationObserverInterestGroup(
6060
}
6161

6262
MutationObserverInterestGroup::~MutationObserverInterestGroup() {
63-
WEBF_LOG(VERBOSE) << "INTERST";
64-
for(auto& observer : observers_) {
65-
observer.first.Clear();
66-
}
6763
}
6864

6965
bool MutationObserverInterestGroup::IsOldValueRequested() {

bridge/core/dom/mutation_observer_registration.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,11 @@ MutationObserverRegistration::MutationObserverRegistration(MutationObserver& obs
4949
}
5050

5151
MutationObserverRegistration::~MutationObserverRegistration() {
52-
registration_node_.Clear();
53-
registration_node_keep_alive_.Clear();
54-
observer_.Clear();
55-
56-
for(auto& node : transient_registration_nodes_) {
57-
node.Clear();
58-
}
5952
}
6053

6154
void MutationObserverRegistration::Dispose() {
6255
ClearTransientRegistrations();
6356
observer_->ObservationEnded(shared_from_this());
64-
observer_.Clear();
6557
}
6658

6759
void MutationObserverRegistration::ResetObservation(

bridge/core/timing/performance.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ void Performance::clearMarks(ExceptionState& exception_state) {
107107
while (it != entries_.end()) {
108108
if ((*it)->entryType() != performance_entry_names::kmark) {
109109
new_entries.emplace_back(*it);
110-
} else {
111-
it->Clear();
112110
}
113111
it++;
114112
}
@@ -123,8 +121,6 @@ void Performance::clearMarks(const AtomicString& name, ExceptionState& exception
123121
while (it != std::end(entries_)) {
124122
if (!((*it)->entryType() == performance_entry_names::kmark && (*it)->name() == name)) {
125123
new_entries.emplace_back(*it);
126-
} else {
127-
it->Clear();
128124
}
129125
it++;
130126
}
@@ -139,8 +135,6 @@ void Performance::clearMeasures(ExceptionState& exception_state) {
139135
while (it != std::end(entries_)) {
140136
if ((*it)->entryType() != performance_entry_names::kmeasure) {
141137
new_entries.emplace_back(*it);
142-
} else {
143-
it->Clear();
144138
}
145139
it++;
146140
}
@@ -155,8 +149,6 @@ void Performance::clearMeasures(const AtomicString& name, ExceptionState& except
155149
while (it != std::end(entries_)) {
156150
if (!((*it)->entryType() == performance_entry_names::kmeasure && (*it)->name() == name)) {
157151
new_entries.emplace_back(*it);
158-
} else {
159-
it->Clear();
160152
}
161153
it++;
162154
}

0 commit comments

Comments
 (0)