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

Side by Side Diff: Source/bindings/v8/DOMDataStore.h

Issue 68173017: Have DOMDataStore::current() return a reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/v8/DOMDataStore.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(WrapperWorldType);
50 ~DOMDataStore(); 50 ~DOMDataStore();
51 51
52 static DOMDataStore* current(v8::Isolate*); 52 static DOMDataStore& current(v8::Isolate*);
53 53
54 template<typename V8T, typename T, typename Wrappable> 54 template<typename V8T, typename T, typename Wrappable>
55 static bool setReturnValueFromWrapperFast(v8::ReturnValue<v8::Value> returnV alue, T* object, v8::Local<v8::Object> holder, Wrappable* wrappable) 55 static bool setReturnValueFromWrapperFast(v8::ReturnValue<v8::Value> returnV alue, T* object, v8::Local<v8::Object> holder, Wrappable* wrappable)
56 { 56 {
57 // What we'd really like to check here is whether we're in the 57 // What we'd really like to check here is whether we're in the
58 // main world or in an isolated world. The fastest way to do that 58 // main world or in an isolated world. The fastest way to do that
59 // is to check that there is no isolated world and the 'object' 59 // is to check that there is no isolated world and the 'object'
60 // is an object that can exist in the main world. The second fastest 60 // is an object that can exist in the main world. The second fastest
61 // way is to check whether the wrappable's wrapper is the same as 61 // way is to check whether the wrappable's wrapper is the same as
62 // the holder. 62 // the holder.
63 if ((!DOMWrapperWorld::isolatedWorldsExist() && !canExistInWorker(object )) || holderContainsWrapper(holder, wrappable)) { 63 if ((!DOMWrapperWorld::isolatedWorldsExist() && !canExistInWorker(object )) || holderContainsWrapper(holder, wrappable)) {
64 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 64 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
65 return ScriptWrappable::setReturnValueWithSecurityCheck<V8T>(ret urnValue, object); 65 return ScriptWrappable::setReturnValueWithSecurityCheck<V8T>(ret urnValue, object);
66 return mainWorldStore()->m_wrapperMap.setReturnValueFrom(returnValue , V8T::toInternalPointer(object)); 66 return mainWorldStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T::toInternalPointer(object));
67 } 67 }
68 return current(returnValue.GetIsolate())->template setReturnValueFrom<V8 T>(returnValue, object); 68 return current(returnValue.GetIsolate()).template setReturnValueFrom<V8T >(returnValue, object);
69 } 69 }
70 70
71 template<typename V8T, typename T> 71 template<typename V8T, typename T>
72 static bool setReturnValueFromWrapper(v8::ReturnValue<v8::Value> returnValue , T* object) 72 static bool setReturnValueFromWrapper(v8::ReturnValue<v8::Value> returnValue , T* object)
73 { 73 {
74 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) { 74 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) {
75 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) 75 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist()))
76 return ScriptWrappable::setReturnValueWithSecurityCheck<V8T>(ret urnValue, object); 76 return ScriptWrappable::setReturnValueWithSecurityCheck<V8T>(ret urnValue, object);
77 } 77 }
78 return current(returnValue.GetIsolate())->template setReturnValueFrom<V8 T>(returnValue, object); 78 return current(returnValue.GetIsolate()).template setReturnValueFrom<V8T >(returnValue, object);
79 } 79 }
80 80
81 template<typename V8T, typename T> 81 template<typename V8T, typename T>
82 static bool setReturnValueFromWrapperForMainWorld(v8::ReturnValue<v8::Value> returnValue, T* object) 82 static bool setReturnValueFromWrapperForMainWorld(v8::ReturnValue<v8::Value> returnValue, T* object)
83 { 83 {
84 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) 84 if (ScriptWrappable::wrapperCanBeStoredInObject(object))
85 return ScriptWrappable::setReturnValue(returnValue, object); 85 return ScriptWrappable::setReturnValue(returnValue, object);
86 return mainWorldStore()->m_wrapperMap.setReturnValueFrom(returnValue, V8 T::toInternalPointer(object)); 86 return mainWorldStore().m_wrapperMap.setReturnValueFrom(returnValue, V8T ::toInternalPointer(object));
87 } 87 }
88 88
89 template<typename V8T, typename T> 89 template<typename V8T, typename T>
90 static v8::Handle<v8::Object> getWrapper(T* object, v8::Isolate* isolate) 90 static v8::Handle<v8::Object> getWrapper(T* object, v8::Isolate* isolate)
91 { 91 {
92 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) { 92 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) {
93 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) { 93 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) {
94 v8::Handle<v8::Object> result = ScriptWrappable::getUnsafeWrappe rFromObject(object).newLocal(isolate); 94 v8::Handle<v8::Object> result = ScriptWrappable::getUnsafeWrappe rFromObject(object).newLocal(isolate);
95 // Security: always guard against malicious tampering. 95 // Security: always guard against malicious tampering.
96 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.IsEmpty() || res ult->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == V8T::toInter nalPointer(object)); 96 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(result.IsEmpty() || res ult->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex) == V8T::toInter nalPointer(object));
97 return result; 97 return result;
98 } 98 }
99 } 99 }
100 return current(isolate)->template get<V8T>(object, isolate); 100 return current(isolate).template get<V8T>(object, isolate);
101 } 101 }
102 102
103 template<typename V8T, typename T> 103 template<typename V8T, typename T>
104 static void setWrapperReference(const v8::Persistent<v8::Object>& parent, T* child, v8::Isolate* isolate) 104 static void setWrapperReference(const v8::Persistent<v8::Object>& parent, T* child, v8::Isolate* isolate)
105 { 105 {
106 if (ScriptWrappable::wrapperCanBeStoredInObject(child) && !canExistInWor ker(child)) { 106 if (ScriptWrappable::wrapperCanBeStoredInObject(child) && !canExistInWor ker(child)) {
107 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) { 107 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) {
108 UnsafePersistent<v8::Object> unsafePersistent = ScriptWrappable: :getUnsafeWrapperFromObject(child); 108 UnsafePersistent<v8::Object> unsafePersistent = ScriptWrappable: :getUnsafeWrapperFromObject(child);
109 // Security: always guard against malicious tampering. 109 // Security: always guard against malicious tampering.
110 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(unsafePersistent.isEmpt y() || unsafePersistent.value()->GetAlignedPointerFromInternalField(v8DOMWrapper ObjectIndex) == V8T::toInternalPointer(child)); 110 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(unsafePersistent.isEmpt y() || unsafePersistent.value()->GetAlignedPointerFromInternalField(v8DOMWrapper ObjectIndex) == V8T::toInternalPointer(child));
111 unsafePersistent.setReferenceFrom(parent, isolate); 111 unsafePersistent.setReferenceFrom(parent, isolate);
112 } 112 }
113 } 113 }
114 current(isolate)->template setReference<V8T>(parent, child, isolate); 114 current(isolate).template setReference<V8T>(parent, child, isolate);
115 } 115 }
116 116
117 template<typename V8T, typename T> 117 template<typename V8T, typename T>
118 static void setWrapper(T* object, v8::Handle<v8::Object> wrapper, v8::Isolat e* isolate, const WrapperConfiguration& configuration) 118 static void setWrapper(T* object, v8::Handle<v8::Object> wrapper, v8::Isolat e* isolate, const WrapperConfiguration& configuration)
119 { 119 {
120 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) { 120 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && !canExistInWo rker(object)) {
121 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) { 121 if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) {
122 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, co nfiguration); 122 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, co nfiguration);
123 return; 123 return;
124 } 124 }
125 } 125 }
126 return current(isolate)->template set<V8T>(object, wrapper, isolate, con figuration); 126 return current(isolate).template set<V8T>(object, wrapper, isolate, conf iguration);
127 } 127 }
128 128
129 template<typename V8T, typename T> 129 template<typename V8T, typename T>
130 static bool containsWrapper(T* object, v8::Isolate* isolate) 130 static bool containsWrapper(T* object, v8::Isolate* isolate)
131 { 131 {
132 return current(isolate)->template containsWrapper<V8T>(object); 132 return current(isolate).template containsWrapper<V8T>(object);
133 } 133 }
134 134
135 template<typename V8T, typename T> 135 template<typename V8T, typename T>
136 inline v8::Handle<v8::Object> get(T* object, v8::Isolate* isolate) 136 inline v8::Handle<v8::Object> get(T* object, v8::Isolate* isolate)
137 { 137 {
138 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai nWorld) 138 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai nWorld)
139 return ScriptWrappable::getUnsafeWrapperFromObject(object).newLocal( isolate); 139 return ScriptWrappable::getUnsafeWrapperFromObject(object).newLocal( isolate);
140 return m_wrapperMap.newLocal(V8T::toInternalPointer(object), isolate); 140 return m_wrapperMap.newLocal(V8T::toInternalPointer(object), isolate);
141 } 141 }
142 142
(...skipping 29 matching lines...) Expand all
172 { 172 {
173 ASSERT(!!object); 173 ASSERT(!!object);
174 ASSERT(!wrapper.IsEmpty()); 174 ASSERT(!wrapper.IsEmpty());
175 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai nWorld) { 175 if (ScriptWrappable::wrapperCanBeStoredInObject(object) && m_type == Mai nWorld) {
176 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, config uration); 176 ScriptWrappable::setWrapperInObject(object, wrapper, isolate, config uration);
177 return; 177 return;
178 } 178 }
179 m_wrapperMap.set(V8T::toInternalPointer(object), wrapper, configuration) ; 179 m_wrapperMap.set(V8T::toInternalPointer(object), wrapper, configuration) ;
180 } 180 }
181 181
182 static DOMDataStore* mainWorldStore(); 182 static DOMDataStore& mainWorldStore();
183 183
184 static bool canExistInWorker(void*) { return true; } 184 static bool canExistInWorker(void*) { return true; }
185 static bool canExistInWorker(Node*) { return false; } 185 static bool canExistInWorker(Node*) { return false; }
186 186
187 static bool holderContainsWrapper(v8::Local<v8::Object>, void*) 187 static bool holderContainsWrapper(v8::Local<v8::Object>, void*)
188 { 188 {
189 return false; 189 return false;
190 } 190 }
191 191
192 static bool holderContainsWrapper(v8::Local<v8::Object> holder, ScriptWrappa ble* wrappable) 192 static bool holderContainsWrapper(v8::Local<v8::Object> holder, ScriptWrappa ble* wrappable)
193 { 193 {
194 // Verify our assumptions about the main world. 194 // Verify our assumptions about the main world.
195 UnsafePersistent<v8::Object> unsafePersistent = wrappable->unsafePersist ent(); 195 UnsafePersistent<v8::Object> unsafePersistent = wrappable->unsafePersist ent();
196 ASSERT(unsafePersistent.isEmpty() || !(holder == *unsafePersistent.persi stent()) || current(v8::Isolate::GetCurrent())->m_type == MainWorld); 196 ASSERT(unsafePersistent.isEmpty() || !(holder == *unsafePersistent.persi stent()) || current(v8::Isolate::GetCurrent()).m_type == MainWorld);
197 return holder == *unsafePersistent.persistent(); 197 return holder == *unsafePersistent.persistent();
198 } 198 }
199 199
200 WrapperWorldType m_type; 200 WrapperWorldType m_type;
201 DOMWrapperMap<void> m_wrapperMap; 201 DOMWrapperMap<void> m_wrapperMap;
202 }; 202 };
203 203
204 } // namespace WebCore 204 } // namespace WebCore
205 205
206 #endif // DOMDataStore_h 206 #endif // DOMDataStore_h
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/v8/DOMDataStore.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698