OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * Copyright (C) 2012 Ericsson AB. All rights reserved. | 3 * Copyright (C) 2012 Ericsson AB. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "platform/JSONValues.h" | 48 #include "platform/JSONValues.h" |
49 #include "platform/heap/Handle.h" | 49 #include "platform/heap/Handle.h" |
50 #include "wtf/text/AtomicString.h" | 50 #include "wtf/text/AtomicString.h" |
51 #include <v8.h> | 51 #include <v8.h> |
52 | 52 |
53 namespace blink { | 53 namespace blink { |
54 | 54 |
55 class DOMWindow; | 55 class DOMWindow; |
56 class EventListener; | 56 class EventListener; |
57 class EventTarget; | 57 class EventTarget; |
| 58 class ExceptionState; |
58 class ExecutionContext; | 59 class ExecutionContext; |
59 class ExceptionState; | |
60 class Frame; | 60 class Frame; |
61 class LocalDOMWindow; | 61 class LocalDOMWindow; |
62 class LocalFrame; | 62 class LocalFrame; |
63 class NodeFilter; | 63 class NodeFilter; |
| 64 class WorkerGlobalScope; |
64 class XPathNSResolver; | 65 class XPathNSResolver; |
65 | 66 |
66 template <typename T> | 67 template <typename T> |
67 struct V8TypeOf { | 68 struct V8TypeOf { |
68 // |Type| provides C++ -> V8 type conversion for DOM wrappers. | 69 // |Type| provides C++ -> V8 type conversion for DOM wrappers. |
69 // The Blink binding code generator will generate specialized version of | 70 // The Blink binding code generator will generate specialized version of |
70 // V8TypeOf for each wrapper class. | 71 // V8TypeOf for each wrapper class. |
71 typedef void Type; | 72 typedef void Type; |
72 }; | 73 }; |
73 | 74 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 if (UNLIKELY(!impl)) { | 210 if (UNLIKELY(!impl)) { |
210 v8SetReturnValueNull(callbackInfo); | 211 v8SetReturnValueNull(callbackInfo); |
211 return; | 212 return; |
212 } | 213 } |
213 if (DOMDataStore::setReturnValue(callbackInfo.GetReturnValue(), impl)) | 214 if (DOMDataStore::setReturnValue(callbackInfo.GetReturnValue(), impl)) |
214 return; | 215 return; |
215 v8::Handle<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap(callb
ackInfo.Holder(), callbackInfo.GetIsolate()); | 216 v8::Handle<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap(callb
ackInfo.Holder(), callbackInfo.GetIsolate()); |
216 v8SetReturnValue(callbackInfo, wrapper); | 217 v8SetReturnValue(callbackInfo, wrapper); |
217 } | 218 } |
218 | 219 |
| 220 // Special versions for DOMWindow, WorkerGlobalScope and EventTarget |
| 221 |
| 222 template<typename CallbackInfo> |
| 223 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, DOMWindow* impl) |
| 224 { |
| 225 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 226 } |
| 227 |
| 228 template<typename CallbackInfo> |
| 229 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, EventTarget* impl
) |
| 230 { |
| 231 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 232 } |
| 233 |
| 234 template<typename CallbackInfo> |
| 235 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, WorkerGlobalScope
* impl) |
| 236 { |
| 237 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 238 } |
| 239 |
219 template<typename CallbackInfo, typename T> | 240 template<typename CallbackInfo, typename T> |
220 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, PassRefPtr<T> imp
l) | 241 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, PassRefPtr<T> imp
l) |
221 { | 242 { |
222 v8SetReturnValue(callbackInfo, impl.get()); | 243 v8SetReturnValue(callbackInfo, impl.get()); |
223 } | 244 } |
224 | 245 |
225 template<typename CallbackInfo, typename T> | 246 template<typename CallbackInfo, typename T> |
226 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, RawPtr<T> impl) | 247 inline void v8SetReturnValue(const CallbackInfo& callbackInfo, RawPtr<T> impl) |
227 { | 248 { |
228 v8SetReturnValue(callbackInfo, impl.get()); | 249 v8SetReturnValue(callbackInfo, impl.get()); |
229 } | 250 } |
230 | 251 |
231 template<typename CallbackInfo> | 252 template<typename CallbackInfo> |
232 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Scrip
tWrappable* impl) | 253 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Scrip
tWrappable* impl) |
233 { | 254 { |
234 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); | 255 ASSERT(DOMWrapperWorld::current(callbackInfo.GetIsolate()).isMainWorld()); |
235 if (UNLIKELY(!impl)) { | 256 if (UNLIKELY(!impl)) { |
236 v8SetReturnValueNull(callbackInfo); | 257 v8SetReturnValueNull(callbackInfo); |
237 return; | 258 return; |
238 } | 259 } |
239 if (DOMDataStore::setReturnValueForMainWorld(callbackInfo.GetReturnValue(),
impl)) | 260 if (DOMDataStore::setReturnValueForMainWorld(callbackInfo.GetReturnValue(),
impl)) |
240 return; | 261 return; |
241 v8::Handle<v8::Object> wrapper = impl->wrap(callbackInfo.Holder(), callbackI
nfo.GetIsolate()); | 262 v8::Handle<v8::Object> wrapper = impl->wrap(callbackInfo.Holder(), callbackI
nfo.GetIsolate()); |
242 v8SetReturnValue(callbackInfo, wrapper); | 263 v8SetReturnValue(callbackInfo, wrapper); |
243 } | 264 } |
244 | 265 |
245 template<typename CallbackInfo> | 266 template<typename CallbackInfo> |
246 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Node*
impl) | 267 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Node*
impl) |
247 { | 268 { |
248 // Since EventTarget has [Custom=ToV8] and V8EventTarget.h defines its own | 269 // Since EventTarget has a special version of ToV8 and V8EventTarget.h |
249 // v8SetReturnValue family, which are slow, we need to override them with | 270 // defines its own v8SetReturnValue family, which are slow, we need to |
250 // optimized versions for Node and its subclasses. Without this overload, | 271 // override them with optimized versions for Node and its subclasses. |
251 // v8SetReturnValueForMainWorld for Node would be very slow. | 272 // Without this overload, v8SetReturnValueForMainWorld for Node would be |
| 273 // very slow. |
252 // | 274 // |
253 // class hierarchy: | 275 // class hierarchy: |
254 // ScriptWrappable <-- EventTarget <--+-- Node <-- ... | 276 // ScriptWrappable <-- EventTarget <--+-- Node <-- ... |
255 // +-- Window | 277 // +-- Window |
256 // overloads: | 278 // overloads: |
257 // v8SetReturnValueForMainWorld(ScriptWrappable*) | 279 // v8SetReturnValueForMainWorld(ScriptWrappable*) |
258 // Optimized and very fast. | 280 // Optimized and very fast. |
259 // v8SetReturnValueForMainWorld(EventTarget*) | 281 // v8SetReturnValueForMainWorld(EventTarget*) |
260 // Uses custom toV8 function and slow. | 282 // Uses custom toV8 function and slow. |
261 // v8SetReturnValueForMainWorld(Node*) | 283 // v8SetReturnValueForMainWorld(Node*) |
262 // Optimized and very fast. | 284 // Optimized and very fast. |
263 // v8SetReturnValueForMainWorld(Window*) | 285 // v8SetReturnValueForMainWorld(Window*) |
264 // Uses custom toV8 function and slow. | 286 // Uses custom toV8 function and slow. |
265 v8SetReturnValueForMainWorld(callbackInfo, ScriptWrappable::fromNode(impl)); | 287 v8SetReturnValueForMainWorld(callbackInfo, ScriptWrappable::fromNode(impl)); |
266 } | 288 } |
267 | 289 |
| 290 // Special versions for DOMWindow, WorkerGlobalScope and EventTarget |
| 291 |
| 292 template<typename CallbackInfo> |
| 293 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, DOMWi
ndow* impl) |
| 294 { |
| 295 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 296 } |
| 297 |
| 298 template<typename CallbackInfo> |
| 299 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Event
Target* impl) |
| 300 { |
| 301 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 302 } |
| 303 |
| 304 template<typename CallbackInfo> |
| 305 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, Worke
rGlobalScope* impl) |
| 306 { |
| 307 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 308 } |
| 309 |
268 template<typename CallbackInfo, typename T> | 310 template<typename CallbackInfo, typename T> |
269 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, PassR
efPtr<T> impl) | 311 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, PassR
efPtr<T> impl) |
270 { | 312 { |
271 v8SetReturnValueForMainWorld(callbackInfo, impl.get()); | 313 v8SetReturnValueForMainWorld(callbackInfo, impl.get()); |
272 } | 314 } |
273 | 315 |
274 template<typename CallbackInfo, typename T> | 316 template<typename CallbackInfo, typename T> |
275 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, RawPt
r<T> impl) | 317 inline void v8SetReturnValueForMainWorld(const CallbackInfo& callbackInfo, RawPt
r<T> impl) |
276 { | 318 { |
277 v8SetReturnValueForMainWorld(callbackInfo, impl.get()); | 319 v8SetReturnValueForMainWorld(callbackInfo, impl.get()); |
(...skipping 18 matching lines...) Expand all Loading... |
296 if (UNLIKELY(!impl)) { | 338 if (UNLIKELY(!impl)) { |
297 v8SetReturnValueNull(callbackInfo); | 339 v8SetReturnValueNull(callbackInfo); |
298 return; | 340 return; |
299 } | 341 } |
300 if (DOMDataStore::setReturnValueFast(callbackInfo.GetReturnValue(), impl, ca
llbackInfo.Holder(), wrappable)) | 342 if (DOMDataStore::setReturnValueFast(callbackInfo.GetReturnValue(), impl, ca
llbackInfo.Holder(), wrappable)) |
301 return; | 343 return; |
302 v8::Handle<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap(callb
ackInfo.Holder(), callbackInfo.GetIsolate()); | 344 v8::Handle<v8::Object> wrapper = ScriptWrappable::fromNode(impl)->wrap(callb
ackInfo.Holder(), callbackInfo.GetIsolate()); |
303 v8SetReturnValue(callbackInfo, wrapper); | 345 v8SetReturnValue(callbackInfo, wrapper); |
304 } | 346 } |
305 | 347 |
| 348 // Special versions for DOMWindow, WorkerGlobalScope and EventTarget |
| 349 |
| 350 template<typename CallbackInfo> |
| 351 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, DOMWindow* im
pl, const ScriptWrappable*) |
| 352 { |
| 353 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 354 } |
| 355 |
| 356 template<typename CallbackInfo> |
| 357 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, EventTarget*
impl, const ScriptWrappable*) |
| 358 { |
| 359 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 360 } |
| 361 |
| 362 template<typename CallbackInfo> |
| 363 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, WorkerGlobalS
cope* impl, const ScriptWrappable*) |
| 364 { |
| 365 v8SetReturnValue(callbackInfo, toV8(impl, callbackInfo.Holder(), callbackInf
o.GetIsolate())); |
| 366 } |
| 367 |
306 template<typename CallbackInfo, typename T, typename Wrappable> | 368 template<typename CallbackInfo, typename T, typename Wrappable> |
307 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, PassRefPtr<T>
impl, const Wrappable* wrappable) | 369 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, PassRefPtr<T>
impl, const Wrappable* wrappable) |
308 { | 370 { |
309 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); | 371 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); |
310 } | 372 } |
311 | 373 |
312 template<typename CallbackInfo, typename T, typename Wrappable> | 374 template<typename CallbackInfo, typename T, typename Wrappable> |
313 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, RawPtr<T> imp
l, const Wrappable* wrappable) | 375 inline void v8SetReturnValueFast(const CallbackInfo& callbackInfo, RawPtr<T> imp
l, const Wrappable* wrappable) |
314 { | 376 { |
315 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); | 377 v8SetReturnValueFast(callbackInfo, impl.get(), wrappable); |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(v8::Isol
ate*, ExecutionContext*, v8::Handle<v8::Function>); | 1061 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(v8::Isol
ate*, ExecutionContext*, v8::Handle<v8::Function>); |
1000 | 1062 |
1001 // Callback functions used by generated code. | 1063 // Callback functions used by generated code. |
1002 CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName,
const v8::PropertyCallbackInfo<v8::Value>&); | 1064 CORE_EXPORT void v8ConstructorAttributeGetter(v8::Local<v8::Name> propertyName,
const v8::PropertyCallbackInfo<v8::Value>&); |
1003 | 1065 |
1004 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); | 1066 typedef void (*InstallTemplateFunction)(v8::Local<v8::FunctionTemplate>, v8::Iso
late*); |
1005 | 1067 |
1006 } // namespace blink | 1068 } // namespace blink |
1007 | 1069 |
1008 #endif // V8Binding_h | 1070 #endif // V8Binding_h |
OLD | NEW |