2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-25 10:25:18 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-05-12 16:32:04 +00:00
|
|
|
#ifndef SHELL_COMMON_API_OBJECT_LIFE_MONITOR_H_
|
|
|
|
#define SHELL_COMMON_API_OBJECT_LIFE_MONITOR_H_
|
2013-04-25 10:25:18 +00:00
|
|
|
|
2015-08-27 08:41:51 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "v8/include/v8.h"
|
2013-04-25 10:25:18 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-04-25 10:25:18 +00:00
|
|
|
|
|
|
|
class ObjectLifeMonitor {
|
2016-04-26 07:10:27 +00:00
|
|
|
protected:
|
|
|
|
ObjectLifeMonitor(v8::Isolate* isolate, v8::Local<v8::Object> target);
|
|
|
|
virtual ~ObjectLifeMonitor();
|
2013-04-25 10:25:18 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
ObjectLifeMonitor(const ObjectLifeMonitor&) = delete;
|
|
|
|
ObjectLifeMonitor& operator=(const ObjectLifeMonitor&) = delete;
|
|
|
|
|
2016-04-26 07:10:27 +00:00
|
|
|
virtual void RunDestructor() = 0;
|
2013-04-25 10:25:18 +00:00
|
|
|
|
2016-04-26 07:10:27 +00:00
|
|
|
private:
|
2015-08-27 08:41:51 +00:00
|
|
|
static void OnObjectGC(const v8::WeakCallbackInfo<ObjectLifeMonitor>& data);
|
2016-03-21 12:42:12 +00:00
|
|
|
static void Free(const v8::WeakCallbackInfo<ObjectLifeMonitor>& data);
|
2013-04-25 10:25:18 +00:00
|
|
|
|
2015-08-27 08:41:51 +00:00
|
|
|
v8::Global<v8::Object> target_;
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<ObjectLifeMonitor> weak_ptr_factory_{this};
|
2013-04-25 10:25:18 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2013-04-25 10:25:18 +00:00
|
|
|
|
2020-05-12 16:32:04 +00:00
|
|
|
#endif // SHELL_COMMON_API_OBJECT_LIFE_MONITOR_H_
|