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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // We never actually destruct the main world's DOMDataStore. | 54 // We never actually destruct the main world's DOMDataStore. |
55 ASSERT(!m_isMainWorld); | 55 ASSERT(!m_isMainWorld); |
56 m_wrapperMap.clear(); | 56 m_wrapperMap.clear(); |
57 } | 57 } |
58 | 58 |
59 static DOMDataStore& current(v8::Isolate* isolate) | 59 static DOMDataStore& current(v8::Isolate* isolate) |
60 { | 60 { |
61 return DOMWrapperWorld::current(isolate).domDataStore(); | 61 return DOMWrapperWorld::current(isolate).domDataStore(); |
62 } | 62 } |
63 | 63 |
64 static bool setReturnValueFast(v8::ReturnValue<v8::Value> returnValue, Scrip
tWrappable* object, v8::Local<v8::Object> holder, const ScriptWrappable* wrappab
le) | |
65 { | |
66 // The second fastest way to check if we're in the main world is to chec
k if | |
67 // the wrappable's wrapper is the same as the holder. | |
68 if (holderContainsWrapper(holder, wrappable)) | |
69 return object->setReturnValue(returnValue); | |
70 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
object); | |
71 } | |
72 | |
73 static bool setReturnValueFast(v8::ReturnValue<v8::Value> returnValue, Node*
node, v8::Local<v8::Object> holder, const ScriptWrappable* wrappable) | |
74 { | |
75 if (canUseScriptWrappable(node) | |
76 // The second fastest way to check if we're in the main world is to | |
77 // check if the wrappable's wrapper is the same as the holder. | |
78 || holderContainsWrapper(holder, wrappable)) | |
79 return ScriptWrappable::fromNode(node)->setReturnValue(returnValue); | |
80 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
ScriptWrappable::fromNode(node)); | |
81 } | |
82 | |
83 static bool setReturnValue(v8::ReturnValue<v8::Value> returnValue, ScriptWra
ppableBase* object) | |
84 { | |
85 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
object); | |
86 } | |
87 | |
88 static bool setReturnValue(v8::ReturnValue<v8::Value> returnValue, ScriptWra
ppable* object) | 64 static bool setReturnValue(v8::ReturnValue<v8::Value> returnValue, ScriptWra
ppable* object) |
89 { | 65 { |
90 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
object); | 66 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
object); |
91 } | 67 } |
92 | 68 |
93 static bool setReturnValue(v8::ReturnValue<v8::Value> returnValue, Node* obj
ect) | 69 static bool setReturnValue(v8::ReturnValue<v8::Value> returnValue, Node* obj
ect) |
94 { | 70 { |
95 if (canUseScriptWrappable(object)) | 71 if (canUseScriptWrappable(object)) |
96 return ScriptWrappable::fromNode(object)->setReturnValue(returnValue
); | 72 return ScriptWrappable::fromNode(object)->setReturnValue(returnValue
); |
97 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
ScriptWrappable::fromNode(object)); | 73 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
ScriptWrappable::fromNode(object)); |
98 } | 74 } |
99 | 75 |
100 static bool setReturnValueForMainWorld(v8::ReturnValue<v8::Value> returnValu
e, ScriptWrappable* object) | 76 static bool setReturnValueForMainWorld(v8::ReturnValue<v8::Value> returnValu
e, ScriptWrappable* object) |
101 { | 77 { |
102 return object->setReturnValue(returnValue); | 78 return object->setReturnValue(returnValue); |
103 } | 79 } |
104 | 80 |
105 static v8::Handle<v8::Object> getWrapper(ScriptWrappableBase* object, v8::Is
olate* isolate) | 81 static bool setReturnValueFast(v8::ReturnValue<v8::Value> returnValue, Scrip
tWrappable* object, v8::Local<v8::Object> holder, const ScriptWrappable* wrappab
le) |
106 { | 82 { |
107 return current(isolate).get(object, isolate); | 83 // The second fastest way to check if we're in the main world is to chec
k if |
| 84 // the wrappable's wrapper is the same as the holder. |
| 85 if (holderContainsWrapper(holder, wrappable)) |
| 86 return object->setReturnValue(returnValue); |
| 87 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
object); |
| 88 } |
| 89 |
| 90 static bool setReturnValueFast(v8::ReturnValue<v8::Value> returnValue, Node*
node, v8::Local<v8::Object> holder, const ScriptWrappable* wrappable) |
| 91 { |
| 92 if (canUseScriptWrappable(node) |
| 93 // The second fastest way to check if we're in the main world is to |
| 94 // check if the wrappable's wrapper is the same as the holder. |
| 95 || holderContainsWrapper(holder, wrappable)) |
| 96 return ScriptWrappable::fromNode(node)->setReturnValue(returnValue); |
| 97 return current(returnValue.GetIsolate()).setReturnValueFrom(returnValue,
ScriptWrappable::fromNode(node)); |
108 } | 98 } |
109 | 99 |
110 static v8::Handle<v8::Object> getWrapper(ScriptWrappable* object, v8::Isolat
e* isolate) | 100 static v8::Handle<v8::Object> getWrapper(ScriptWrappable* object, v8::Isolat
e* isolate) |
111 { | 101 { |
112 return current(isolate).get(object, isolate); | 102 return current(isolate).get(object, isolate); |
113 } | 103 } |
114 | 104 |
115 static v8::Handle<v8::Object> getWrapper(Node* node, v8::Isolate* isolate) | 105 static v8::Handle<v8::Object> getWrapper(Node* node, v8::Isolate* isolate) |
116 { | 106 { |
117 if (canUseScriptWrappable(node)) { | 107 if (canUseScriptWrappable(node)) { |
118 v8::Handle<v8::Object> result = ScriptWrappable::fromNode(node)->new
LocalWrapper(isolate); | 108 v8::Handle<v8::Object> result = ScriptWrappable::fromNode(node)->new
LocalWrapper(isolate); |
119 // Security: always guard against malicious tampering. | 109 // Security: always guard against malicious tampering. |
120 ScriptWrappable::fromNode(node)->assertWrapperSanity(result); | 110 ScriptWrappable::fromNode(node)->assertWrapperSanity(result); |
121 return result; | 111 return result; |
122 } | 112 } |
123 return current(isolate).get(ScriptWrappable::fromNode(node), isolate); | 113 return current(isolate).get(ScriptWrappable::fromNode(node), isolate); |
124 } | 114 } |
125 | 115 |
126 static void setWrapperReference(const v8::Persistent<v8::Object>& parent, Sc
riptWrappableBase* child, v8::Isolate* isolate) | |
127 { | |
128 current(isolate).setReference(parent, child, isolate); | |
129 } | |
130 | |
131 static void setWrapperReference(const v8::Persistent<v8::Object>& parent, Sc
riptWrappable* child, v8::Isolate* isolate) | 116 static void setWrapperReference(const v8::Persistent<v8::Object>& parent, Sc
riptWrappable* child, v8::Isolate* isolate) |
132 { | 117 { |
133 current(isolate).setReference(parent, child, isolate); | 118 current(isolate).setReference(parent, child, isolate); |
134 } | 119 } |
135 | 120 |
136 static void setWrapperReference(const v8::Persistent<v8::Object>& parent, No
de* child, v8::Isolate* isolate) | 121 static void setWrapperReference(const v8::Persistent<v8::Object>& parent, No
de* child, v8::Isolate* isolate) |
137 { | 122 { |
138 if (canUseScriptWrappable(child)) { | 123 if (canUseScriptWrappable(child)) { |
139 ScriptWrappable::fromNode(child)->setReference(parent, isolate); | 124 ScriptWrappable::fromNode(child)->setReference(parent, isolate); |
140 return; | 125 return; |
141 } | 126 } |
142 current(isolate).setReference(parent, ScriptWrappable::fromNode(child),
isolate); | 127 current(isolate).setReference(parent, ScriptWrappable::fromNode(child),
isolate); |
143 } | 128 } |
144 | 129 |
145 static void setWrapper(ScriptWrappableBase* object, v8::Handle<v8::Object> w
rapper, v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) | |
146 { | |
147 return current(isolate).set(object, wrapper, isolate, wrapperTypeInfo); | |
148 } | |
149 | |
150 static void setWrapper(ScriptWrappable* object, v8::Handle<v8::Object> wrapp
er, v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) | 130 static void setWrapper(ScriptWrappable* object, v8::Handle<v8::Object> wrapp
er, v8::Isolate* isolate, const WrapperTypeInfo* wrapperTypeInfo) |
151 { | 131 { |
152 return current(isolate).set(object, wrapper, isolate, wrapperTypeInfo); | 132 return current(isolate).set(object, wrapper, isolate, wrapperTypeInfo); |
153 } | 133 } |
154 | 134 |
155 static void setWrapper(Node* node, v8::Handle<v8::Object> wrapper, v8::Isola
te* isolate, const WrapperTypeInfo* wrapperTypeInfo) | 135 static void setWrapper(Node* node, v8::Handle<v8::Object> wrapper, v8::Isola
te* isolate, const WrapperTypeInfo* wrapperTypeInfo) |
156 { | 136 { |
157 if (canUseScriptWrappable(node)) { | 137 if (canUseScriptWrappable(node)) { |
158 ScriptWrappable::fromNode(node)->setWrapper(wrapper, isolate, wrappe
rTypeInfo); | 138 ScriptWrappable::fromNode(node)->setWrapper(wrapper, isolate, wrappe
rTypeInfo); |
159 return; | 139 return; |
160 } | 140 } |
161 return current(isolate).set(ScriptWrappable::fromNode(node), wrapper, is
olate, wrapperTypeInfo); | 141 return current(isolate).set(ScriptWrappable::fromNode(node), wrapper, is
olate, wrapperTypeInfo); |
162 } | 142 } |
163 | 143 |
164 static bool containsWrapper(ScriptWrappableBase* object, v8::Isolate* isolat
e) | |
165 { | |
166 return current(isolate).containsWrapper(object); | |
167 } | |
168 | |
169 static bool containsWrapper(ScriptWrappable* object, v8::Isolate* isolate) | 144 static bool containsWrapper(ScriptWrappable* object, v8::Isolate* isolate) |
170 { | 145 { |
171 return current(isolate).containsWrapper(object); | 146 return current(isolate).containsWrapper(object); |
172 } | 147 } |
173 | 148 |
174 v8::Handle<v8::Object> get(ScriptWrappableBase* object, v8::Isolate* isolate
) | |
175 { | |
176 return m_wrapperMap.newLocal(object->toScriptWrappableBase(), isolate); | |
177 } | |
178 | |
179 v8::Handle<v8::Object> get(ScriptWrappable* object, v8::Isolate* isolate) | 149 v8::Handle<v8::Object> get(ScriptWrappable* object, v8::Isolate* isolate) |
180 { | 150 { |
181 if (m_isMainWorld) | 151 if (m_isMainWorld) |
182 return object->newLocalWrapper(isolate); | 152 return object->newLocalWrapper(isolate); |
183 return m_wrapperMap.newLocal(object->toScriptWrappableBase(), isolate); | 153 return m_wrapperMap.newLocal(object->toScriptWrappableBase(), isolate); |
184 } | 154 } |
185 | 155 |
186 void setReference(const v8::Persistent<v8::Object>& parent, ScriptWrappableB
ase* child, v8::Isolate* isolate) | |
187 { | |
188 m_wrapperMap.setReference(parent, child, isolate); | |
189 } | |
190 | |
191 void setReference(const v8::Persistent<v8::Object>& parent, ScriptWrappable*
child, v8::Isolate* isolate) | 156 void setReference(const v8::Persistent<v8::Object>& parent, ScriptWrappable*
child, v8::Isolate* isolate) |
192 { | 157 { |
193 if (m_isMainWorld) { | 158 if (m_isMainWorld) { |
194 child->setReference(parent, isolate); | 159 child->setReference(parent, isolate); |
195 return; | 160 return; |
196 } | 161 } |
197 m_wrapperMap.setReference(parent, child->toScriptWrappableBase(), isolat
e); | 162 m_wrapperMap.setReference(parent, child->toScriptWrappableBase(), isolat
e); |
198 } | 163 } |
199 | 164 |
200 bool setReturnValueFrom(v8::ReturnValue<v8::Value> returnValue, ScriptWrappa
bleBase* object) | |
201 { | |
202 return m_wrapperMap.setReturnValueFrom(returnValue, object); | |
203 } | |
204 | |
205 bool setReturnValueFrom(v8::ReturnValue<v8::Value> returnValue, ScriptWrappa
ble* object) | 165 bool setReturnValueFrom(v8::ReturnValue<v8::Value> returnValue, ScriptWrappa
ble* object) |
206 { | 166 { |
207 if (m_isMainWorld) | 167 if (m_isMainWorld) |
208 return object->setReturnValue(returnValue); | 168 return object->setReturnValue(returnValue); |
209 return m_wrapperMap.setReturnValueFrom(returnValue, object->toScriptWrap
pableBase()); | 169 return m_wrapperMap.setReturnValueFrom(returnValue, object->toScriptWrap
pableBase()); |
210 } | 170 } |
211 | 171 |
212 bool containsWrapper(ScriptWrappableBase* object) | |
213 { | |
214 return m_wrapperMap.containsKey(object->toScriptWrappableBase()); | |
215 } | |
216 | |
217 bool containsWrapper(ScriptWrappable* object) | 172 bool containsWrapper(ScriptWrappable* object) |
218 { | 173 { |
219 if (m_isMainWorld) | 174 if (m_isMainWorld) |
220 return object->containsWrapper(); | 175 return object->containsWrapper(); |
221 return m_wrapperMap.containsKey(object->toScriptWrappableBase()); | 176 return m_wrapperMap.containsKey(object->toScriptWrappableBase()); |
222 } | 177 } |
223 | 178 |
224 private: | 179 private: |
225 void set(ScriptWrappableBase* object, v8::Handle<v8::Object> wrapper, v8::Is
olate* isolate, const WrapperTypeInfo* wrapperTypeInfo) | |
226 { | |
227 ASSERT(object); | |
228 ASSERT(!wrapper.IsEmpty()); | |
229 m_wrapperMap.set(object->toScriptWrappableBase(), wrapper, wrapperTypeIn
fo); | |
230 } | |
231 | |
232 void set(ScriptWrappable* object, v8::Handle<v8::Object> wrapper, v8::Isolat
e* isolate, const WrapperTypeInfo* wrapperTypeInfo) | 180 void set(ScriptWrappable* object, v8::Handle<v8::Object> wrapper, v8::Isolat
e* isolate, const WrapperTypeInfo* wrapperTypeInfo) |
233 { | 181 { |
234 ASSERT(object); | 182 ASSERT(object); |
235 ASSERT(!wrapper.IsEmpty()); | 183 ASSERT(!wrapper.IsEmpty()); |
236 if (m_isMainWorld) { | 184 if (m_isMainWorld) { |
237 object->setWrapper(wrapper, isolate, wrapperTypeInfo); | 185 object->setWrapper(wrapper, isolate, wrapperTypeInfo); |
238 return; | 186 return; |
239 } | 187 } |
240 m_wrapperMap.set(object->toScriptWrappableBase(), wrapper, wrapperTypeIn
fo); | 188 m_wrapperMap.set(object->toScriptWrappableBase(), wrapper, wrapperTypeIn
fo); |
241 } | 189 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 v8::UniquePersistent<v8::Object> value, | 222 v8::UniquePersistent<v8::Object> value, |
275 ScriptWrappableBase* key) | 223 ScriptWrappableBase* key) |
276 { | 224 { |
277 RELEASE_ASSERT(!value.IsEmpty()); // See crbug.com/368095. | 225 RELEASE_ASSERT(!value.IsEmpty()); // See crbug.com/368095. |
278 releaseObject(v8::Local<v8::Object>::New(isolate, value)); | 226 releaseObject(v8::Local<v8::Object>::New(isolate, value)); |
279 } | 227 } |
280 | 228 |
281 } // namespace blink | 229 } // namespace blink |
282 | 230 |
283 #endif // DOMDataStore_h | 231 #endif // DOMDataStore_h |
OLD | NEW |