diff --git a/atom/common/api/atom_api_id_weak_map.cc b/atom/common/api/atom_api_id_weak_map.cc deleted file mode 100644 index 93457943fce5..000000000000 --- a/atom/common/api/atom_api_id_weak_map.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "atom/common/api/atom_api_id_weak_map.h" - -#include "atom/common/node_includes.h" -#include "native_mate/dictionary.h" - -namespace atom { - -namespace api { - -IDWeakMap::IDWeakMap(v8::Isolate* isolate) { - Init(isolate); -} - -IDWeakMap::~IDWeakMap() { -} - -void IDWeakMap::Set(v8::Isolate* isolate, - int32_t id, - v8::Local object) { - id_weak_map_.Set(isolate, id, object); -} - -v8::Local IDWeakMap::Get(v8::Isolate* isolate, int32_t id) { - return id_weak_map_.Get(isolate, id).ToLocalChecked(); -} - -bool IDWeakMap::Has(int32_t id) { - return id_weak_map_.Has(id); -} - -void IDWeakMap::Remove(int32_t id) { - id_weak_map_.Remove(id); -} - -// static -void IDWeakMap::BuildPrototype(v8::Isolate* isolate, - v8::Local prototype) { - mate::ObjectTemplateBuilder(isolate, prototype) - .SetMethod("set", &IDWeakMap::Set) - .SetMethod("get", &IDWeakMap::Get) - .SetMethod("has", &IDWeakMap::Has) - .SetMethod("remove", &IDWeakMap::Remove); -} - -// static -mate::Handle IDWeakMap::Create(v8::Isolate* isolate) { - return mate::CreateHandle(isolate, new IDWeakMap(isolate)); -} - -} // namespace api - -} // namespace atom - -namespace { - -using atom::api::IDWeakMap; - -void Initialize(v8::Local exports, v8::Local unused, - v8::Local context, void* priv) { - mate::Dictionary dict(context->GetIsolate(), exports); - dict.SetMethod("createIDWeakMap", &atom::api::IDWeakMap::Create); -} - -} // namespace - -NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_id_weak_map, Initialize) diff --git a/atom/common/api/atom_api_id_weak_map.h b/atom/common/api/atom_api_id_weak_map.h deleted file mode 100644 index 6d5a8bf7f430..000000000000 --- a/atom/common/api/atom_api_id_weak_map.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2015 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_ID_WEAK_MAP_H_ -#define ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_ - -#include "atom/common/key_weak_map.h" -#include "native_mate/object_template_builder.h" -#include "native_mate/handle.h" - -namespace atom { - -namespace api { - -class IDWeakMap : public mate::Wrappable { - public: - static mate::Handle Create(v8::Isolate* isolate); - - static void BuildPrototype(v8::Isolate* isolate, - v8::Local prototype); - - protected: - explicit IDWeakMap(v8::Isolate* isolate); - ~IDWeakMap(); - - private: - // Api for IDWeakMap. - void Set(v8::Isolate* isolate, int32_t id, v8::Local object); - v8::Local Get(v8::Isolate* isolate, int32_t id); - bool Has(int32_t id); - void Remove(int32_t id); - - atom::KeyWeakMap id_weak_map_; - - DISALLOW_COPY_AND_ASSIGN(IDWeakMap); -}; - -} // namespace api - -} // namespace atom - -#endif // ATOM_COMMON_API_ATOM_API_ID_WEAK_MAP_H_ diff --git a/atom/common/api/atom_api_key_weak_map.cc b/atom/common/api/atom_api_key_weak_map.cc new file mode 100644 index 000000000000..be703c2b15d2 --- /dev/null +++ b/atom/common/api/atom_api_key_weak_map.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/common/api/atom_api_key_weak_map.h" + +#include "atom/common/node_includes.h" +#include "native_mate/dictionary.h" + +namespace { + +void Initialize(v8::Local exports, v8::Local unused, + v8::Local context, void* priv) { + mate::Dictionary dict(context->GetIsolate(), exports); + dict.SetMethod("createIDWeakMap", + &atom::api::KeyWeakMap::Create); +} + +} // namespace + +NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_id_weak_map, Initialize) diff --git a/atom/common/api/atom_api_key_weak_map.h b/atom/common/api/atom_api_key_weak_map.h new file mode 100644 index 000000000000..b13338badd5b --- /dev/null +++ b/atom/common/api/atom_api_key_weak_map.h @@ -0,0 +1,65 @@ +// 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/object_template_builder.h" +#include "native_mate/handle.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) { + mate::ObjectTemplateBuilder(isolate, prototype) + .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_ diff --git a/filenames.gypi b/filenames.gypi index fa1b1d770a32..e85f150615a3 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -288,8 +288,8 @@ 'atom/common/api/atom_api_asar.cc', 'atom/common/api/atom_api_clipboard.cc', 'atom/common/api/atom_api_crash_reporter.cc', - 'atom/common/api/atom_api_id_weak_map.cc', - 'atom/common/api/atom_api_id_weak_map.h', + 'atom/common/api/atom_api_key_weak_map.cc', + 'atom/common/api/atom_api_key_weak_map.h', 'atom/common/api/atom_api_native_image.cc', 'atom/common/api/atom_api_native_image.h', 'atom/common/api/atom_api_native_image_mac.mm',