refactor: make TrackableObjectBase::weak_map_id_
const (#46556)
refactor: make TrackableObjectBase::weak_map_id_ const simplify declaration and initialization Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
1ebad64192
commit
cbc150486c
1 changed files with 5 additions and 9 deletions
|
@ -42,11 +42,12 @@ class TrackableObjectBase : public CleanedUpAtExit {
|
|||
// Returns a closure that can destroy the native class.
|
||||
base::OnceClosure GetDestroyClosure();
|
||||
|
||||
int32_t weak_map_id_ = 0;
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
|
||||
static inline int32_t next_id_ = 0;
|
||||
const int32_t weak_map_id_ = ++next_id_;
|
||||
|
||||
base::WeakPtrFactory<TrackableObjectBase> weak_factory_{this};
|
||||
};
|
||||
|
||||
|
@ -111,26 +112,21 @@ class TrackableObject : public TrackableObjectBase, public EventEmitter<T> {
|
|||
}
|
||||
|
||||
protected:
|
||||
TrackableObject() { weak_map_id_ = ++next_id_; }
|
||||
|
||||
TrackableObject() = default;
|
||||
~TrackableObject() override { RemoveFromWeakMap(); }
|
||||
|
||||
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) override {
|
||||
if (!weak_map_) {
|
||||
weak_map_ = new electron::KeyWeakMap<int32_t>;
|
||||
}
|
||||
weak_map_->Set(isolate, weak_map_id_, wrapper);
|
||||
weak_map_->Set(isolate, weak_map_id(), wrapper);
|
||||
gin_helper::WrappableBase::InitWith(isolate, wrapper);
|
||||
}
|
||||
|
||||
private:
|
||||
static int32_t next_id_;
|
||||
static electron::KeyWeakMap<int32_t>* weak_map_; // leaked on purpose
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
int32_t TrackableObject<T>::next_id_ = 0;
|
||||
|
||||
template <typename T>
|
||||
electron::KeyWeakMap<int32_t>* TrackableObject<T>::weak_map_ = nullptr;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue