OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "wtf/Noncopyable.h" | 39 #include "wtf/Noncopyable.h" |
40 #include "wtf/StdLibExtras.h" | 40 #include "wtf/StdLibExtras.h" |
41 | 41 |
42 namespace WebCore { | 42 namespace WebCore { |
43 | 43 |
44 class Node; | 44 class Node; |
45 | 45 |
46 class DOMDataStore { | 46 class DOMDataStore { |
47 WTF_MAKE_NONCOPYABLE(DOMDataStore); | 47 WTF_MAKE_NONCOPYABLE(DOMDataStore); |
48 public: | 48 public: |
49 explicit DOMDataStore(WrapperWorldType); | 49 explicit DOMDataStore(bool isMainWorld); |
50 ~DOMDataStore(); | 50 ~DOMDataStore(); |
51 | 51 |
52 static DOMDataStore& current(v8::Isolate*); | 52 static DOMDataStore& current(v8::Isolate*); |
53 | 53 |
54 // We can use a wrapper stored in a ScriptWrappable when we're in the main w
orld. | 54 // We can use a wrapper stored in a ScriptWrappable when we're in the main w
orld. |
55 // This method does the fast check if we're in the main world. If this metho
d returns true, | 55 // This method does the fast check if we're in the main world. If this metho
d returns true, |
56 // it is guaranteed that we're in the main world. On the other hand, if this
method returns | 56 // it is guaranteed that we're in the main world. On the other hand, if this
method returns |
57 // false, nothing is guaranteed (we might be in the main world). | 57 // false, nothing is guaranteed (we might be in the main world). |
58 template<typename T> | 58 template<typename T> |
59 static bool canUseScriptWrappable(T* object) | 59 static bool canUseScriptWrappable(T* object) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 template<typename V8T, typename T> | 133 template<typename V8T, typename T> |
134 static bool containsWrapper(T* object, v8::Isolate* isolate) | 134 static bool containsWrapper(T* object, v8::Isolate* isolate) |
135 { | 135 { |
136 return current(isolate).template containsWrapper<V8T>(object); | 136 return current(isolate).template containsWrapper<V8T>(object); |
137 } | 137 } |
138 | 138 |
139 template<typename V8T, typename T> | 139 template<typename V8T, typename T> |
140 inline v8::Handle<v8::Object> get(T* object, v8::Isolate* isolate) | 140 inline v8::Handle<v8::Object> get(T* object, v8::Isolate* isolate) |
141 { | 141 { |
142 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai
nWorld) | 142 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) |
143 return ScriptWrappable::getUnsafeWrapperFromObject(object).newLocal(
isolate); | 143 return ScriptWrappable::getUnsafeWrapperFromObject(object).newLocal(
isolate); |
144 return m_wrapperMap.newLocal(V8T::toInternalPointer(object), isolate); | 144 return m_wrapperMap.newLocal(V8T::toInternalPointer(object), isolate); |
145 } | 145 } |
146 | 146 |
147 template<typename V8T, typename T> | 147 template<typename V8T, typename T> |
148 inline void setReference(const v8::Persistent<v8::Object>& parent, T* child,
v8::Isolate* isolate) | 148 inline void setReference(const v8::Persistent<v8::Object>& parent, T* child,
v8::Isolate* isolate) |
149 { | 149 { |
150 if (ScriptWrappable::wrapperCanBeStoredInObject(child) && m_type == Main
World) { | 150 if (ScriptWrappable::wrapperCanBeStoredInObject(child) && m_isMainWorld)
{ |
151 ScriptWrappable::getUnsafeWrapperFromObject(child).setReferenceFrom(
parent, isolate); | 151 ScriptWrappable::getUnsafeWrapperFromObject(child).setReferenceFrom(
parent, isolate); |
152 return; | 152 return; |
153 } | 153 } |
154 m_wrapperMap.setReference(parent, V8T::toInternalPointer(child), isolate
); | 154 m_wrapperMap.setReference(parent, V8T::toInternalPointer(child), isolate
); |
155 } | 155 } |
156 | 156 |
157 template<typename V8T, typename T> | 157 template<typename V8T, typename T> |
158 inline bool setReturnValueFrom(v8::ReturnValue<v8::Value> returnValue, T* ob
ject) | 158 inline bool setReturnValueFrom(v8::ReturnValue<v8::Value> returnValue, T* ob
ject) |
159 { | 159 { |
160 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai
nWorld) | 160 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) |
161 return ScriptWrappable::setReturnValue(returnValue, object); | 161 return ScriptWrappable::setReturnValue(returnValue, object); |
162 return m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPoint
er(object)); | 162 return m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPoint
er(object)); |
163 } | 163 } |
164 | 164 |
165 template<typename V8T, typename T> | 165 template<typename V8T, typename T> |
166 inline bool containsWrapper(T* object) | 166 inline bool containsWrapper(T* object) |
167 { | 167 { |
168 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai
nWorld) | 168 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) |
169 return !ScriptWrappable::getUnsafeWrapperFromObject(object).isEmpty(
); | 169 return !ScriptWrappable::getUnsafeWrapperFromObject(object).isEmpty(
); |
170 return m_wrapperMap.containsKey(V8T::toInternalPointer(object)); | 170 return m_wrapperMap.containsKey(V8T::toInternalPointer(object)); |
171 } | 171 } |
172 | 172 |
173 private: | 173 private: |
174 template<typename V8T, typename T> | 174 template<typename V8T, typename T> |
175 inline void set(T* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isol
ate, const WrapperConfiguration& configuration) | 175 inline void set(T* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isol
ate, const WrapperConfiguration& configuration) |
176 { | 176 { |
177 ASSERT(!!object); | 177 ASSERT(!!object); |
178 ASSERT(!wrapper.IsEmpty()); | 178 ASSERT(!wrapper.IsEmpty()); |
179 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai
nWorld) { | 179 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) { |
180 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, config
uration); | 180 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, config
uration); |
181 return; | 181 return; |
182 } | 182 } |
183 m_wrapperMap.set(V8T::toInternalPointer(object), wrapper, configuration)
; | 183 m_wrapperMap.set(V8T::toInternalPointer(object), wrapper, configuration)
; |
184 } | 184 } |
185 | 185 |
186 static bool canExistInWorker(void*) { return true; } | 186 static bool canExistInWorker(void*) { return true; } |
187 static bool canExistInWorker(Node*) { return false; } | 187 static bool canExistInWorker(Node*) { return false; } |
188 | 188 |
189 static bool holderContainsWrapper(v8::Local<v8::Object>, void*) | 189 static bool holderContainsWrapper(v8::Local<v8::Object>, void*) |
190 { | 190 { |
191 return false; | 191 return false; |
192 } | 192 } |
193 | 193 |
194 static bool holderContainsWrapper(v8::Local<v8::Object> holder, ScriptWrappa
ble* wrappable) | 194 static bool holderContainsWrapper(v8::Local<v8::Object> holder, ScriptWrappa
ble* wrappable) |
195 { | 195 { |
196 // Verify our assumptions about the main world. | 196 // Verify our assumptions about the main world. |
197 UnsafePersistent<v8::Object> unsafePersistent = wrappable->unsafePersist
ent(); | 197 UnsafePersistent<v8::Object> unsafePersistent = wrappable->unsafePersist
ent(); |
198 ASSERT(unsafePersistent.isEmpty() || !(holder == *unsafePersistent.persi
stent()) || current(v8::Isolate::GetCurrent()).m_type == MainWorld); | 198 ASSERT(unsafePersistent.isEmpty() || !(holder == *unsafePersistent.persi
stent()) || current(v8::Isolate::GetCurrent()).m_isMainWorld); |
199 return holder == *unsafePersistent.persistent(); | 199 return holder == *unsafePersistent.persistent(); |
200 } | 200 } |
201 | 201 |
202 WrapperWorldType m_type; | 202 bool m_isMainWorld; |
203 DOMWrapperMap<void> m_wrapperMap; | 203 DOMWrapperMap<void> m_wrapperMap; |
204 }; | 204 }; |
205 | 205 |
206 } // namespace WebCore | 206 } // namespace WebCore |
207 | 207 |
208 #endif // DOMDataStore_h | 208 #endif // DOMDataStore_h |
OLD | NEW |