2016-05-11 09:21:35 +00:00
|
|
|
// Copyright (c) 2016 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_
|
|
|
|
#define SHELL_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_
|
2016-05-11 09:21:35 +00:00
|
|
|
|
2019-12-05 09:46:34 +00:00
|
|
|
#include "gin/handle.h"
|
2019-09-19 15:09:15 +00:00
|
|
|
#include "shell/common/gin_converters/std_converter.h"
|
|
|
|
#include "shell/common/gin_helper/object_template_builder.h"
|
2019-12-05 09:46:34 +00:00
|
|
|
#include "shell/common/gin_helper/wrappable.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/key_weak_map.h"
|
2016-05-11 09:21:35 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2016-05-11 09:21:35 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
template <typename K>
|
2019-12-05 09:46:34 +00:00
|
|
|
class KeyWeakMap : public gin_helper::Wrappable<KeyWeakMap<K>> {
|
2016-05-11 09:21:35 +00:00
|
|
|
public:
|
2019-12-05 09:46:34 +00:00
|
|
|
static gin::Handle<KeyWeakMap<K>> Create(v8::Isolate* isolate) {
|
|
|
|
return gin::CreateHandle(isolate, new KeyWeakMap<K>(isolate));
|
2016-05-11 09:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
2019-09-19 15:09:15 +00:00
|
|
|
prototype->SetClassName(gin::StringToV8(isolate, "KeyWeakMap"));
|
|
|
|
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2016-05-11 09:21:35 +00:00
|
|
|
.SetMethod("set", &KeyWeakMap<K>::Set)
|
|
|
|
.SetMethod("get", &KeyWeakMap<K>::Get)
|
|
|
|
.SetMethod("has", &KeyWeakMap<K>::Has)
|
|
|
|
.SetMethod("remove", &KeyWeakMap<K>::Remove);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit KeyWeakMap(v8::Isolate* isolate) {
|
2019-12-05 09:46:34 +00:00
|
|
|
gin_helper::Wrappable<KeyWeakMap<K>>::Init(isolate);
|
2016-05-11 09:21:35 +00:00
|
|
|
}
|
|
|
|
~KeyWeakMap() override {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// API for KeyWeakMap.
|
|
|
|
void Set(v8::Isolate* isolate, const K& key, v8::Local<v8::Object> object) {
|
|
|
|
key_weak_map_.Set(isolate, key, object);
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Object> Get(v8::Isolate* isolate, const K& key) {
|
|
|
|
return key_weak_map_.Get(isolate, key).ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
bool Has(const K& key) { return key_weak_map_.Has(key); }
|
2016-05-11 09:21:35 +00:00
|
|
|
|
2018-04-18 01:44:10 +00:00
|
|
|
void Remove(const K& key) { key_weak_map_.Remove(key); }
|
2016-05-11 09:21:35 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::KeyWeakMap<K> key_weak_map_;
|
2016-05-11 09:21:35 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(KeyWeakMap);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2016-05-11 09:21:35 +00:00
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_
|