AttachAsUserData now can assume the existence of wrapper
This commit is contained in:
parent
1505a46ed0
commit
846ec5ba49
3 changed files with 6 additions and 15 deletions
|
@ -29,7 +29,7 @@ class IDUserData : public base::SupportsUserData::Data {
|
|||
} // namespace
|
||||
|
||||
TrackableObjectBase::TrackableObjectBase()
|
||||
: weak_map_id_(0), wrapped_(nullptr), weak_factory_(this) {
|
||||
: weak_map_id_(0), weak_factory_(this) {
|
||||
cleanup_ = RegisterDestructionCallback(GetDestroyClosure());
|
||||
}
|
||||
|
||||
|
@ -46,14 +46,7 @@ void TrackableObjectBase::Destroy() {
|
|||
}
|
||||
|
||||
void TrackableObjectBase::AttachAsUserData(base::SupportsUserData* wrapped) {
|
||||
if (weak_map_id_ != 0) {
|
||||
wrapped->SetUserData(kTrackedObjectKey, new IDUserData(weak_map_id_));
|
||||
wrapped_ = nullptr;
|
||||
} else {
|
||||
// If the TrackableObjectBase is not ready yet then delay SetUserData until
|
||||
// AfterInit is called.
|
||||
wrapped_ = wrapped;
|
||||
}
|
||||
wrapped->SetUserData(kTrackedObjectKey, new IDUserData(weak_map_id_));
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -44,7 +44,6 @@ class TrackableObjectBase {
|
|||
static base::Closure RegisterDestructionCallback(const base::Closure& c);
|
||||
|
||||
int32_t weak_map_id_;
|
||||
base::SupportsUserData* wrapped_;
|
||||
|
||||
private:
|
||||
void Destroy();
|
||||
|
@ -110,14 +109,13 @@ class TrackableObject : public TrackableObjectBase,
|
|||
RemoveFromWeakMap();
|
||||
}
|
||||
|
||||
void AfterInit(v8::Isolate* isolate) override {
|
||||
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) override {
|
||||
WrappableBase::InitWith(isolate, wrapper);
|
||||
if (!weak_map_) {
|
||||
weak_map_ = new atom::KeyWeakMap<int32_t>;
|
||||
}
|
||||
weak_map_id_ = ++next_id_;
|
||||
weak_map_->Set(isolate, weak_map_id_, Wrappable<T>::GetWrapper());
|
||||
if (wrapped_)
|
||||
AttachAsUserData(wrapped_);
|
||||
weak_map_->Set(isolate, weak_map_id_, wrapper);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
2
vendor/native_mate
vendored
2
vendor/native_mate
vendored
|
@ -1 +1 @@
|
|||
Subproject commit bd20bde1a257b1b740dfeafc220c331ead3b66ab
|
||||
Subproject commit ab62755a886d424727f4959f4339555865490ae8
|
Loading…
Add table
Reference in a new issue