refactor: ginify powerMonitor (#22751)
This commit is contained in:
parent
aeae0d47bd
commit
07cd70a37e
10 changed files with 216 additions and 176 deletions
34
shell/common/gin_helper/pinnable.h
Normal file
34
shell/common/gin_helper/pinnable.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright (c) 2020 Slack Technologies, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_COMMON_GIN_HELPER_PINNABLE_H_
|
||||
#define SHELL_COMMON_GIN_HELPER_PINNABLE_H_
|
||||
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
namespace gin_helper {
|
||||
|
||||
template <typename T>
|
||||
class Pinnable {
|
||||
protected:
|
||||
// Prevent the object from being garbage collected until Unpin() is called.
|
||||
void Pin(v8::Isolate* isolate) {
|
||||
v8::Locker locker(isolate);
|
||||
v8::HandleScope scope(isolate);
|
||||
v8::Local<v8::Value> wrapper;
|
||||
if (static_cast<T*>(this)->GetWrapper(isolate).ToLocal(&wrapper)) {
|
||||
pinned_.Reset(isolate, wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
// Allow the object to be garbage collected.
|
||||
void Unpin() { pinned_.Reset(); }
|
||||
|
||||
private:
|
||||
v8::Global<v8::Value> pinned_;
|
||||
};
|
||||
|
||||
} // namespace gin_helper
|
||||
|
||||
#endif // SHELL_COMMON_GIN_HELPER_PINNABLE_H_
|
Loading…
Add table
Add a link
Reference in a new issue