Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: sky/engine/bindings/core/v8/V8PersistentValueMap.h

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef SKY_ENGINE_BINDINGS_CORE_V8_V8PERSISTENTVALUEMAP_H_
32 #define SKY_ENGINE_BINDINGS_CORE_V8_V8PERSISTENTVALUEMAP_H_
33
34 #include "sky/engine/wtf/HashMap.h"
35 #include "sky/engine/wtf/text/StringHash.h"
36 #include "v8/include/v8-util.h"
37 #include "v8/include/v8.h"
38
39 namespace blink {
40
41 /**
42 * A Traits class for v8::PersistentValueMap that uses wtf/HashMap as a
43 * backing store.
44 *
45 * The parameter is_weak will determine whether the references are 'weak'.
46 * If so, entries will be removed from the map as the weak references are
47 * collected.
48 */
49 template<class KeyType, class ValueType, bool is_weak>
50 class V8PersistentValueMapTraits {
51 public:
52 // Map traits:
53 typedef HashMap<KeyType, v8::PersistentContainerValue> Impl;
54 typedef typename Impl::iterator Iterator;
55 static size_t Size(const Impl* impl) { return impl->size(); }
56 static bool Empty(Impl* impl) { return impl->isEmpty(); }
57 static void Swap(Impl& impl, Impl& other) { impl.swap(other); }
58 static Iterator Begin(Impl* impl) { return impl->begin(); }
59 static Iterator End(Impl* impl) { return impl->end(); }
60 static v8::PersistentContainerValue Value(Iterator& iter)
61 {
62 return iter->value;
63 }
64 static KeyType Key(Iterator& iter) { return iter->key; }
65 static v8::PersistentContainerValue Set(
66 Impl* impl, KeyType key, v8::PersistentContainerValue value)
67 {
68 v8::PersistentContainerValue oldValue = Get(impl, key);
69 impl->set(key, value);
70 return oldValue;
71 }
72 static v8::PersistentContainerValue Get(const Impl* impl, KeyType key)
73 {
74 return impl->get(key);
75 }
76
77 static v8::PersistentContainerValue Remove(Impl* impl, KeyType key)
78 {
79 return impl->take(key);
80 }
81
82 // Weak traits:
83 static const v8::PersistentContainerCallbackType kCallbackType = is_weak ? v 8::kWeak : v8::kNotWeak;
84 typedef v8::PersistentValueMap<KeyType, ValueType, V8PersistentValueMapTrait s<KeyType, ValueType, is_weak> > MapType;
85
86 typedef void WeakCallbackDataType;
87
88 static WeakCallbackDataType* WeakCallbackParameter(MapType* map, KeyType key , const v8::Local<ValueType>& value)
89 {
90 return 0;
91 }
92
93 static void DisposeCallbackData(WeakCallbackDataType* callbackData)
94 {
95 }
96
97 static MapType* MapFromWeakCallbackData(
98 const v8::WeakCallbackData<ValueType, WeakCallbackDataType>& data)
99 {
100 return 0;
101 }
102
103 static KeyType KeyFromWeakCallbackData(
104 const v8::WeakCallbackData<ValueType, WeakCallbackDataType>& data)
105 {
106 return KeyType();
107 }
108
109 // Dispose traits:
110 static void Dispose(v8::Isolate* isolate, v8::UniquePersistent<ValueType> va lue, KeyType key) { }
111 };
112
113 /**
114 * A map for safely storing persistent V8 values, based on
115 * v8::PersistentValueMap.
116 *
117 * If is_weak is set, values will be held weakly and map entries will be
118 * removed as their values are being collected.
119 */
120 template<class KeyType, class ValueType, bool is_weak = true>
121 class V8PersistentValueMap : public v8::PersistentValueMap<KeyType, ValueType, V 8PersistentValueMapTraits<KeyType, ValueType, is_weak> > {
122 public:
123 typedef V8PersistentValueMapTraits<KeyType, ValueType, is_weak> Traits;
124 explicit V8PersistentValueMap(v8::Isolate* isolate) : v8::PersistentValueMap <KeyType, ValueType, Traits>(isolate) { }
125 };
126
127 } // namespace blink
128
129 #endif // SKY_ENGINE_BINDINGS_CORE_V8_V8PERSISTENTVALUEMAP_H_
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/V8PerIsolateData.cpp ('k') | sky/engine/bindings/core/v8/V8PersistentValueVector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698