// Copyright (c) 2016 GitHub, Inc. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. #ifndef ATOM_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_ #define ATOM_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_ #include "atom/common/key_weak_map.h" #include "native_mate/handle.h" #include "native_mate/object_template_builder.h" #include "native_mate/wrappable.h" namespace atom { namespace api { template class KeyWeakMap : public mate::Wrappable> { public: static mate::Handle> Create(v8::Isolate* isolate) { return mate::CreateHandle(isolate, new KeyWeakMap(isolate)); } static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { prototype->SetClassName(mate::StringToV8(isolate, "KeyWeakMap")); mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("set", &KeyWeakMap::Set) .SetMethod("get", &KeyWeakMap::Get) .SetMethod("has", &KeyWeakMap::Has) .SetMethod("remove", &KeyWeakMap::Remove); } protected: explicit KeyWeakMap(v8::Isolate* isolate) { mate::Wrappable>::Init(isolate); } ~KeyWeakMap() override {} private: // API for KeyWeakMap. void Set(v8::Isolate* isolate, const K& key, v8::Local object) { key_weak_map_.Set(isolate, key, object); } v8::Local Get(v8::Isolate* isolate, const K& key) { return key_weak_map_.Get(isolate, key).ToLocalChecked(); } bool Has(const K& key) { return key_weak_map_.Has(key); } void Remove(const K& key) { key_weak_map_.Remove(key); } atom::KeyWeakMap key_weak_map_; DISALLOW_COPY_AND_ASSIGN(KeyWeakMap); }; } // namespace api } // namespace atom #endif // ATOM_COMMON_API_ATOM_API_KEY_WEAK_MAP_H_