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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 return ScriptWrappable::fromObject(object)->setReturnValue(returnVal
ue); | 78 return ScriptWrappable::fromObject(object)->setReturnValue(returnVal
ue); |
79 } | 79 } |
80 // The second fastest way to check if we're in the main world is to chec
k if | 80 // The second fastest way to check if we're in the main world is to chec
k if |
81 // the wrappable's wrapper is the same as the holder. | 81 // the wrappable's wrapper is the same as the holder. |
82 // FIXME: Investigate if it's worth having this check for performance. | 82 // FIXME: Investigate if it's worth having this check for performance. |
83 if (holderContainsWrapper(holder, wrappable)) { | 83 if (holderContainsWrapper(holder, wrappable)) { |
84 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) { | 84 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) { |
85 ScriptWrappable::assertWrapperSanity<V8T, T>(object, object); | 85 ScriptWrappable::assertWrapperSanity<V8T, T>(object, object); |
86 return ScriptWrappable::fromObject(object)->setReturnValue(retur
nValue); | 86 return ScriptWrappable::fromObject(object)->setReturnValue(retur
nValue); |
87 } | 87 } |
88 return DOMWrapperWorld::mainWorld().domDataStore().m_wrapperMap.setR
eturnValueFrom(returnValue, V8T::toInternalPointer(object)); | 88 return DOMWrapperWorld::mainWorld().domDataStore().m_wrapperMap.setR
eturnValueFrom(returnValue, V8T::toScriptWrappableBase(object)); |
89 } | 89 } |
90 return current(returnValue.GetIsolate()).template setReturnValueFrom<V8T
>(returnValue, object); | 90 return current(returnValue.GetIsolate()).template setReturnValueFrom<V8T
>(returnValue, object); |
91 } | 91 } |
92 | 92 |
93 template<typename V8T, typename T> | 93 template<typename V8T, typename T> |
94 static bool setReturnValueFromWrapper(v8::ReturnValue<v8::Value> returnValue
, T* object) | 94 static bool setReturnValueFromWrapper(v8::ReturnValue<v8::Value> returnValue
, T* object) |
95 { | 95 { |
96 if (canUseScriptWrappable(object)) { | 96 if (canUseScriptWrappable(object)) { |
97 ScriptWrappable::assertWrapperSanity<V8T, T>(object, object); | 97 ScriptWrappable::assertWrapperSanity<V8T, T>(object, object); |
98 return ScriptWrappable::fromObject(object)->setReturnValue(returnVal
ue); | 98 return ScriptWrappable::fromObject(object)->setReturnValue(returnVal
ue); |
99 } | 99 } |
100 return current(returnValue.GetIsolate()).template setReturnValueFrom<V8T
>(returnValue, object); | 100 return current(returnValue.GetIsolate()).template setReturnValueFrom<V8T
>(returnValue, object); |
101 } | 101 } |
102 | 102 |
103 template<typename V8T, typename T> | 103 template<typename V8T, typename T> |
104 static bool setReturnValueFromWrapperForMainWorld(v8::ReturnValue<v8::Value>
returnValue, T* object) | 104 static bool setReturnValueFromWrapperForMainWorld(v8::ReturnValue<v8::Value>
returnValue, T* object) |
105 { | 105 { |
106 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) | 106 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) |
107 return ScriptWrappable::fromObject(object)->setReturnValue(returnVal
ue); | 107 return ScriptWrappable::fromObject(object)->setReturnValue(returnVal
ue); |
108 return DOMWrapperWorld::mainWorld().domDataStore().m_wrapperMap.setRetur
nValueFrom(returnValue, V8T::toInternalPointer(object)); | 108 return DOMWrapperWorld::mainWorld().domDataStore().m_wrapperMap.setRetur
nValueFrom(returnValue, V8T::toScriptWrappableBase(object)); |
109 } | 109 } |
110 | 110 |
111 template<typename V8T, typename T> | 111 template<typename V8T, typename T> |
112 static v8::Handle<v8::Object> getWrapper(T* object, v8::Isolate* isolate) | 112 static v8::Handle<v8::Object> getWrapper(T* object, v8::Isolate* isolate) |
113 { | 113 { |
114 if (canUseScriptWrappable(object)) { | 114 if (canUseScriptWrappable(object)) { |
115 v8::Handle<v8::Object> result = ScriptWrappable::fromObject(object)-
>newLocalWrapper(isolate); | 115 v8::Handle<v8::Object> result = ScriptWrappable::fromObject(object)-
>newLocalWrapper(isolate); |
116 // Security: always guard against malicious tampering. | 116 // Security: always guard against malicious tampering. |
117 ScriptWrappable::assertWrapperSanity<V8T, T>(result, object); | 117 ScriptWrappable::assertWrapperSanity<V8T, T>(result, object); |
118 return result; | 118 return result; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 static bool containsWrapperNonTemplate(ScriptWrappable* object, v8::Isolate*
isolate) | 195 static bool containsWrapperNonTemplate(ScriptWrappable* object, v8::Isolate*
isolate) |
196 { | 196 { |
197 return current(isolate).containsWrapperNonTemplate(object); | 197 return current(isolate).containsWrapperNonTemplate(object); |
198 } | 198 } |
199 | 199 |
200 template<typename V8T, typename T> | 200 template<typename V8T, typename T> |
201 v8::Handle<v8::Object> get(T* object, v8::Isolate* isolate) | 201 v8::Handle<v8::Object> get(T* object, v8::Isolate* isolate) |
202 { | 202 { |
203 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) | 203 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) |
204 return ScriptWrappable::fromObject(object)->newLocalWrapper(isolate)
; | 204 return ScriptWrappable::fromObject(object)->newLocalWrapper(isolate)
; |
205 return m_wrapperMap.newLocal(V8T::toInternalPointer(object), isolate); | 205 return m_wrapperMap.newLocal(V8T::toScriptWrappableBase(object), isolate
); |
206 } | 206 } |
207 | 207 |
208 v8::Handle<v8::Object> getNonTemplate(ScriptWrappableBase* object, v8::Isola
te* isolate) | 208 v8::Handle<v8::Object> getNonTemplate(ScriptWrappableBase* object, v8::Isola
te* isolate) |
209 { | 209 { |
210 return m_wrapperMap.newLocal(object->toInternalPointer(), isolate); | 210 return m_wrapperMap.newLocal(object->toScriptWrappableBase(), isolate); |
211 } | 211 } |
212 | 212 |
213 v8::Handle<v8::Object> getNonTemplate(ScriptWrappable* object, v8::Isolate*
isolate) | 213 v8::Handle<v8::Object> getNonTemplate(ScriptWrappable* object, v8::Isolate*
isolate) |
214 { | 214 { |
215 if (m_isMainWorld) | 215 if (m_isMainWorld) |
216 return object->newLocalWrapper(isolate); | 216 return object->newLocalWrapper(isolate); |
217 return m_wrapperMap.newLocal(object->toInternalPointer(), isolate); | 217 return m_wrapperMap.newLocal(object->toScriptWrappableBase(), isolate); |
218 } | 218 } |
219 | 219 |
220 template<typename V8T, typename T> | 220 template<typename V8T, typename T> |
221 void setReference(const v8::Persistent<v8::Object>& parent, T* child, v8::Is
olate* isolate) | 221 void setReference(const v8::Persistent<v8::Object>& parent, T* child, v8::Is
olate* isolate) |
222 { | 222 { |
223 if (ScriptWrappable::wrapperCanBeStoredInObject(child) && m_isMainWorld)
{ | 223 if (ScriptWrappable::wrapperCanBeStoredInObject(child) && m_isMainWorld)
{ |
224 ScriptWrappable::fromObject(child)->setReference(parent, isolate); | 224 ScriptWrappable::fromObject(child)->setReference(parent, isolate); |
225 return; | 225 return; |
226 } | 226 } |
227 m_wrapperMap.setReference(parent, V8T::toInternalPointer(child), isolate
); | 227 m_wrapperMap.setReference(parent, V8T::toScriptWrappableBase(child), iso
late); |
228 } | 228 } |
229 | 229 |
230 template<typename V8T, typename T> | 230 template<typename V8T, typename T> |
231 bool setReturnValueFrom(v8::ReturnValue<v8::Value> returnValue, T* object) | 231 bool setReturnValueFrom(v8::ReturnValue<v8::Value> returnValue, T* object) |
232 { | 232 { |
233 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) | 233 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) |
234 return ScriptWrappable::fromObject(object)->setReturnValue(returnVal
ue); | 234 return ScriptWrappable::fromObject(object)->setReturnValue(returnVal
ue); |
235 return m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPoint
er(object)); | 235 return m_wrapperMap.setReturnValueFrom(returnValue, V8T::toScriptWrappab
leBase(object)); |
236 } | 236 } |
237 | 237 |
238 template<typename V8T, typename T> | 238 template<typename V8T, typename T> |
239 bool containsWrapper(T* object) | 239 bool containsWrapper(T* object) |
240 { | 240 { |
241 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) | 241 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) |
242 return ScriptWrappable::fromObject(object)->containsWrapper(); | 242 return ScriptWrappable::fromObject(object)->containsWrapper(); |
243 return m_wrapperMap.containsKey(V8T::toInternalPointer(object)); | 243 return m_wrapperMap.containsKey(V8T::toScriptWrappableBase(object)); |
244 } | 244 } |
245 | 245 |
246 bool containsWrapperNonTemplate(ScriptWrappableBase* object) | 246 bool containsWrapperNonTemplate(ScriptWrappableBase* object) |
247 { | 247 { |
248 return m_wrapperMap.containsKey(object->toInternalPointer()); | 248 return m_wrapperMap.containsKey(object->toScriptWrappableBase()); |
249 } | 249 } |
250 | 250 |
251 bool containsWrapperNonTemplate(ScriptWrappable* object) | 251 bool containsWrapperNonTemplate(ScriptWrappable* object) |
252 { | 252 { |
253 if (m_isMainWorld) | 253 if (m_isMainWorld) |
254 return object->containsWrapper(); | 254 return object->containsWrapper(); |
255 return m_wrapperMap.containsKey(object->toInternalPointer()); | 255 return m_wrapperMap.containsKey(object->toScriptWrappableBase()); |
256 } | 256 } |
257 | 257 |
258 private: | 258 private: |
259 template<typename V8T, typename T> | 259 template<typename V8T, typename T> |
260 void set(T* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, co
nst WrapperTypeInfo* wrapperTypeInfo) | 260 void set(T* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, co
nst WrapperTypeInfo* wrapperTypeInfo) |
261 { | 261 { |
262 ASSERT(object); | 262 ASSERT(object); |
263 ASSERT(!wrapper.IsEmpty()); | 263 ASSERT(!wrapper.IsEmpty()); |
264 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) { | 264 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_isMainWorld
) { |
265 ScriptWrappable::fromObject(object)->setWrapper(wrapper, isolate, wr
apperTypeInfo); | 265 ScriptWrappable::fromObject(object)->setWrapper(wrapper, isolate, wr
apperTypeInfo); |
266 return; | 266 return; |
267 } | 267 } |
268 m_wrapperMap.set(V8T::toInternalPointer(object), wrapper, wrapperTypeInf
o); | 268 m_wrapperMap.set(V8T::toScriptWrappableBase(object), wrapper, wrapperTyp
eInfo); |
269 } | 269 } |
270 | 270 |
271 void setNonTemplate(ScriptWrappableBase* object, v8::Handle<v8::Object> wrap
per, v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) | 271 void setNonTemplate(ScriptWrappableBase* object, v8::Handle<v8::Object> wrap
per, v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) |
272 { | 272 { |
273 ASSERT(object); | 273 ASSERT(object); |
274 ASSERT(!wrapper.IsEmpty()); | 274 ASSERT(!wrapper.IsEmpty()); |
275 m_wrapperMap.set(object->toInternalPointer(), wrapper, wrapperTypeInfo); | 275 m_wrapperMap.set(object->toScriptWrappableBase(), wrapper, wrapperTypeIn
fo); |
276 } | 276 } |
277 | 277 |
278 void setNonTemplate(ScriptWrappable* object, v8::Handle<v8::Object> wrapper,
v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) | 278 void setNonTemplate(ScriptWrappable* object, v8::Handle<v8::Object> wrapper,
v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) |
279 { | 279 { |
280 ASSERT(object); | 280 ASSERT(object); |
281 ASSERT(!wrapper.IsEmpty()); | 281 ASSERT(!wrapper.IsEmpty()); |
282 if (m_isMainWorld) { | 282 if (m_isMainWorld) { |
283 ScriptWrappable::fromObject(object)->setWrapper(wrapper, isolate, wr
apperTypeInfo); | 283 ScriptWrappable::fromObject(object)->setWrapper(wrapper, isolate, wr
apperTypeInfo); |
284 return; | 284 return; |
285 } | 285 } |
286 m_wrapperMap.set(object->toInternalPointer(), wrapper, wrapperTypeInfo); | 286 m_wrapperMap.set(object->toScriptWrappableBase(), wrapper, wrapperTypeIn
fo); |
287 } | 287 } |
288 | 288 |
289 static bool canExistInWorker(void*) { return true; } | 289 static bool canExistInWorker(void*) { return true; } |
290 static bool canExistInWorker(Node*) { return false; } | 290 static bool canExistInWorker(Node*) { return false; } |
291 | 291 |
292 static bool holderContainsWrapper(v8::Local<v8::Object>, void*) | 292 static bool holderContainsWrapper(v8::Local<v8::Object>, void*) |
293 { | 293 { |
294 return false; | 294 return false; |
295 } | 295 } |
296 | 296 |
(...skipping 15 matching lines...) Expand all Loading... |
312 v8::UniquePersistent<v8::Object> value, | 312 v8::UniquePersistent<v8::Object> value, |
313 ScriptWrappableBase* key) | 313 ScriptWrappableBase* key) |
314 { | 314 { |
315 RELEASE_ASSERT(!value.IsEmpty()); // See crbug.com/368095. | 315 RELEASE_ASSERT(!value.IsEmpty()); // See crbug.com/368095. |
316 releaseObject(v8::Local<v8::Object>::New(isolate, value)); | 316 releaseObject(v8::Local<v8::Object>::New(isolate, value)); |
317 } | 317 } |
318 | 318 |
319 } // namespace blink | 319 } // namespace blink |
320 | 320 |
321 #endif // DOMDataStore_h | 321 #endif // DOMDataStore_h |
OLD | NEW |