Skip to content

Commit 120ac74

Browse files
legendecasRafaelGSS
authored andcommitted
src: remove aliased buffer weak callback
An AliasedBuffer can be nested in a BaseObject and their weak callbacks invoke order are not guaranteed. Prevent aliased buffer from being accessed in its weak callback as its validness can be checked with the emptiness of the persistent handle. PR-URL: #47688 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent de4f14c commit 120ac74

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

src/aliased_buffer-inl.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ AliasedBufferBase<NativeT, V8T>::AliasedBufferBase(
7070
count_(that.count_),
7171
byte_offset_(that.byte_offset_),
7272
buffer_(that.buffer_) {
73-
DCHECK(is_valid());
7473
js_array_ = v8::Global<V8T>(that.isolate_, that.GetJSArray());
74+
DCHECK(is_valid());
7575
}
7676

7777
template <typename NativeT, typename V8T>
@@ -126,19 +126,10 @@ void AliasedBufferBase<NativeT, V8T>::Release() {
126126
js_array_.Reset();
127127
}
128128

129-
template <typename NativeT, typename V8T>
130-
inline void AliasedBufferBase<NativeT, V8T>::WeakCallback(
131-
const v8::WeakCallbackInfo<AliasedBufferBase<NativeT, V8T>>& data) {
132-
AliasedBufferBase<NativeT, V8T>* buffer = data.GetParameter();
133-
DCHECK(buffer->is_valid());
134-
buffer->cleared_ = true;
135-
buffer->js_array_.Reset();
136-
}
137-
138129
template <typename NativeT, typename V8T>
139130
inline void AliasedBufferBase<NativeT, V8T>::MakeWeak() {
140131
DCHECK(is_valid());
141-
js_array_.SetWeak(this, WeakCallback, v8::WeakCallbackType::kParameter);
132+
js_array_.SetWeak();
142133
}
143134

144135
template <typename NativeT, typename V8T>
@@ -223,7 +214,7 @@ void AliasedBufferBase<NativeT, V8T>::reserve(size_t new_capacity) {
223214

224215
template <typename NativeT, typename V8T>
225216
inline bool AliasedBufferBase<NativeT, V8T>::is_valid() const {
226-
return index_ == nullptr && !cleared_;
217+
return index_ == nullptr && !js_array_.IsEmpty();
227218
}
228219

229220
template <typename NativeT, typename V8T>

src/aliased_buffer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,11 @@ class AliasedBufferBase : public MemoryRetainer {
173173

174174
private:
175175
inline bool is_valid() const;
176-
static inline void WeakCallback(
177-
const v8::WeakCallbackInfo<AliasedBufferBase<NativeT, V8T>>& data);
178176
v8::Isolate* isolate_ = nullptr;
179177
size_t count_ = 0;
180178
size_t byte_offset_ = 0;
181179
NativeT* buffer_ = nullptr;
182180
v8::Global<V8T> js_array_;
183-
bool cleared_ = false;
184181

185182
// Deserialize data
186183
const AliasedBufferIndex* index_ = nullptr;

0 commit comments

Comments
 (0)