2013-04-25 10:25:18 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
|
|
// Copyright (c) 2012 Intel Corp. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "common/api/object_life_monitor.h"
|
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
// static
|
|
|
|
void ObjectLifeMonitor::BindTo(v8::Handle<v8::Object> target,
|
|
|
|
v8::Handle<v8::Value> destructor) {
|
|
|
|
target->SetHiddenValue(v8::String::New("destructor"), destructor);
|
|
|
|
|
|
|
|
ObjectLifeMonitor* olm = new ObjectLifeMonitor();
|
2013-12-11 07:48:19 +00:00
|
|
|
olm->handle_.reset(target);
|
|
|
|
olm->handle_.MakeWeak(olm, WeakCallback);
|
2013-04-25 10:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectLifeMonitor::ObjectLifeMonitor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void ObjectLifeMonitor::WeakCallback(v8::Isolate* isolate,
|
2013-12-11 07:48:19 +00:00
|
|
|
v8::Persistent<v8::Object>* value,
|
|
|
|
ObjectLifeMonitor* self) {
|
2013-04-25 10:25:18 +00:00
|
|
|
// destructor.call(object, object);
|
|
|
|
{
|
2013-12-11 07:48:19 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Local<v8::Object> obj = self->handle_.NewHandle();
|
2013-04-25 10:25:18 +00:00
|
|
|
v8::Local<v8::Function>::Cast(obj->GetHiddenValue(
|
2013-12-11 07:48:19 +00:00
|
|
|
v8::String::New("destructor")))->Call(obj, 0, NULL);
|
2013-04-25 10:25:18 +00:00
|
|
|
}
|
|
|
|
|
2013-12-11 07:48:19 +00:00
|
|
|
delete self;
|
2013-04-25 10:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|