// Copyright 2014 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_UTIL_H_ #define V8_UTIL_H_ #include <assert.h> #include <map> #include <vector> #include "v8-function-callback.h" // NOLINT(build/include_directory) #include "v8-persistent-handle.h" // NOLINT(build/include_directory) /** * Support for Persistent containers. * * C++11 embedders can use STL containers with Global values, * but pre-C++11 does not support the required move semantic and hence * may want these container classes. */ namespace v8 { template <typename K, typename V, typename Traits> class GlobalValueMap; PersistentContainerValue; static const uintptr_t kPersistentContainerNotFound = …; enum PersistentContainerCallbackType { … }; /** * A default trait implementation for PersistentValueMap which uses std::map * as a backing map. * * Users will have to implement their own weak callbacks & dispose traits. */ template<typename K, typename V> class StdMapTraits { … }; /** * A default trait implementation for PersistentValueMap, which inherits * a std:map backing map from StdMapTraits and holds non-weak persistent * objects and has no special Dispose handling. * * You should not derive from this class, since MapType depends on the * surrounding class, and hence a subclass cannot simply inherit the methods. */ template<typename K, typename V> class DefaultPersistentValueMapTraits : public StdMapTraits<K, V> { … }; template <typename K, typename V> class DefaultGlobalMapTraits : public StdMapTraits<K, V> { … }; /** * A map wrapper that allows using Global as a mapped value. * C++11 embedders don't need this class, as they can use Global * directly in std containers. * * The map relies on a backing map, whose type and accessors are described * by the Traits class. The backing map will handle values of type * PersistentContainerValue, with all conversion into and out of V8 * handles being transparently handled by this class. */ template <typename K, typename V, typename Traits> class PersistentValueMapBase { … }; template <typename K, typename V, typename Traits> class PersistentValueMap : public PersistentValueMapBase<K, V, Traits> { … }; template <typename K, typename V, typename Traits> class GlobalValueMap : public PersistentValueMapBase<K, V, Traits> { … }; /** * A map that uses Global as value and std::map as the backing * implementation. Persistents are held non-weak. * * C++11 embedders don't need this class, as they can use * Global directly in std containers. */ template<typename K, typename V, typename Traits = DefaultPersistentValueMapTraits<K, V> > class StdPersistentValueMap : public PersistentValueMap<K, V, Traits> { … }; /** * A map that uses Global as value and std::map as the backing * implementation. Globals are held non-weak. * * C++11 embedders don't need this class, as they can use * Global directly in std containers. */ template <typename K, typename V, typename Traits = DefaultGlobalMapTraits<K, V> > class StdGlobalValueMap : public GlobalValueMap<K, V, Traits> { … }; } // namespace v8 #endif // V8_UTIL_H