| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "core/dom/NotShared.h" | 50 #include "core/dom/NotShared.h" |
| 51 #include "platform/heap/Handle.h" | 51 #include "platform/heap/Handle.h" |
| 52 #include "platform/wtf/text/AtomicString.h" | 52 #include "platform/wtf/text/AtomicString.h" |
| 53 #include "platform/wtf/text/StringView.h" | 53 #include "platform/wtf/text/StringView.h" |
| 54 #include "v8/include/v8.h" | 54 #include "v8/include/v8.h" |
| 55 | 55 |
| 56 namespace blink { | 56 namespace blink { |
| 57 | 57 |
| 58 class DOMWindow; | 58 class DOMWindow; |
| 59 class EventListener; | 59 class EventListener; |
| 60 class EventTarget; | |
| 61 class ExceptionState; | 60 class ExceptionState; |
| 62 class ExecutionContext; | 61 class ExecutionContext; |
| 63 class FlexibleArrayBufferView; | 62 class FlexibleArrayBufferView; |
| 64 class Frame; | 63 class Frame; |
| 65 class LocalDOMWindow; | 64 class LocalDOMWindow; |
| 66 class LocalFrame; | 65 class LocalFrame; |
| 67 class NodeFilter; | 66 class NodeFilter; |
| 68 class XPathNSResolver; | 67 class XPathNSResolver; |
| 69 | 68 |
| 70 template <typename T> | 69 template <typename T> |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 inline void V8SetReturnValue(const CallbackInfo& callback_info, | 187 inline void V8SetReturnValue(const CallbackInfo& callback_info, |
| 189 ScriptWrappable* impl) { | 188 ScriptWrappable* impl) { |
| 190 V8SetReturnValue(callback_info, impl, callback_info.Holder()); | 189 V8SetReturnValue(callback_info, impl, callback_info.Holder()); |
| 191 } | 190 } |
| 192 | 191 |
| 193 template <typename CallbackInfo> | 192 template <typename CallbackInfo> |
| 194 inline void V8SetReturnValue(const CallbackInfo& callback_info, Node* impl) { | 193 inline void V8SetReturnValue(const CallbackInfo& callback_info, Node* impl) { |
| 195 V8SetReturnValue(callback_info, ScriptWrappable::FromNode(impl)); | 194 V8SetReturnValue(callback_info, ScriptWrappable::FromNode(impl)); |
| 196 } | 195 } |
| 197 | 196 |
| 198 // Special versions for DOMWindow and EventTarget | |
| 199 | |
| 200 template <typename CallbackInfo> | |
| 201 inline void V8SetReturnValue(const CallbackInfo& callback_info, | |
| 202 DOMWindow* impl) { | |
| 203 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), | |
| 204 callback_info.GetIsolate())); | |
| 205 } | |
| 206 | |
| 207 template <typename CallbackInfo> | |
| 208 inline void V8SetReturnValue(const CallbackInfo& callback_info, | |
| 209 EventTarget* impl) { | |
| 210 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), | |
| 211 callback_info.GetIsolate())); | |
| 212 } | |
| 213 | |
| 214 template <typename CallbackInfo, typename T> | 197 template <typename CallbackInfo, typename T> |
| 215 inline void V8SetReturnValue(const CallbackInfo& callback_info, | 198 inline void V8SetReturnValue(const CallbackInfo& callback_info, |
| 216 PassRefPtr<T> impl) { | 199 PassRefPtr<T> impl) { |
| 217 V8SetReturnValue(callback_info, impl.Get()); | 200 V8SetReturnValue(callback_info, impl.Get()); |
| 218 } | 201 } |
| 219 | 202 |
| 220 template <typename CallbackInfo, typename T> | 203 template <typename CallbackInfo, typename T> |
| 221 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, | 204 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, |
| 222 NotShared<T> notShared) { | 205 NotShared<T> notShared) { |
| 223 V8SetReturnValue(callbackInfo, notShared.View()); | 206 V8SetReturnValue(callbackInfo, notShared.View()); |
| 224 } | 207 } |
| 225 | 208 |
| 226 template <typename CallbackInfo> | 209 template <typename CallbackInfo> |
| 227 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, | 210 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, |
| 228 ScriptWrappable* impl) { | 211 ScriptWrappable* impl) { |
| 229 DCHECK(DOMWrapperWorld::Current(callback_info.GetIsolate()).IsMainWorld()); | 212 DCHECK(DOMWrapperWorld::Current(callback_info.GetIsolate()).IsMainWorld()); |
| 230 if (UNLIKELY(!impl)) { | 213 if (UNLIKELY(!impl)) { |
| 231 V8SetReturnValueNull(callback_info); | 214 V8SetReturnValueNull(callback_info); |
| 232 return; | 215 return; |
| 233 } | 216 } |
| 234 if (DOMDataStore::SetReturnValueForMainWorld(callback_info.GetReturnValue(), | 217 if (DOMDataStore::SetReturnValueForMainWorld(callback_info.GetReturnValue(), |
| 235 impl)) | 218 impl)) |
| 236 return; | 219 return; |
| 237 v8::Local<v8::Object> wrapper = | 220 v8::Local<v8::Object> wrapper = |
| 238 impl->Wrap(callback_info.GetIsolate(), callback_info.Holder()); | 221 impl->Wrap(callback_info.GetIsolate(), callback_info.Holder()); |
| 239 V8SetReturnValue(callback_info, wrapper); | 222 V8SetReturnValue(callback_info, wrapper); |
| 240 } | 223 } |
| 241 | 224 |
| 242 template <typename CallbackInfo> | |
| 243 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, | |
| 244 Node* impl) { | |
| 245 // Since EventTarget has a special version of ToV8 and V8EventTarget.h | |
| 246 // defines its own v8SetReturnValue family, which are slow, we need to | |
| 247 // override them with optimized versions for Node and its subclasses. | |
| 248 // Without this overload, v8SetReturnValueForMainWorld for Node would be | |
| 249 // very slow. | |
| 250 // | |
| 251 // class hierarchy: | |
| 252 // ScriptWrappable <-- EventTarget <--+-- Node <-- ... | |
| 253 // +-- Window | |
| 254 // overloads: | |
| 255 // v8SetReturnValueForMainWorld(ScriptWrappable*) | |
| 256 // Optimized and very fast. | |
| 257 // v8SetReturnValueForMainWorld(EventTarget*) | |
| 258 // Uses custom toV8 function and slow. | |
| 259 // v8SetReturnValueForMainWorld(Node*) | |
| 260 // Optimized and very fast. | |
| 261 // v8SetReturnValueForMainWorld(Window*) | |
| 262 // Uses custom toV8 function and slow. | |
| 263 V8SetReturnValueForMainWorld(callback_info, ScriptWrappable::FromNode(impl)); | |
| 264 } | |
| 265 | |
| 266 // Special versions for DOMWindow and EventTarget | |
| 267 | |
| 268 template <typename CallbackInfo> | |
| 269 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, | |
| 270 DOMWindow* impl) { | |
| 271 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), | |
| 272 callback_info.GetIsolate())); | |
| 273 } | |
| 274 | |
| 275 template <typename CallbackInfo> | |
| 276 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, | |
| 277 EventTarget* impl) { | |
| 278 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), | |
| 279 callback_info.GetIsolate())); | |
| 280 } | |
| 281 | |
| 282 template <typename CallbackInfo, typename T> | 225 template <typename CallbackInfo, typename T> |
| 283 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, | 226 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, |
| 284 PassRefPtr<T> impl) { | 227 PassRefPtr<T> impl) { |
| 285 V8SetReturnValueForMainWorld(callback_info, impl.Get()); | 228 V8SetReturnValueForMainWorld(callback_info, impl.Get()); |
| 286 } | 229 } |
| 287 | 230 |
| 288 template <typename CallbackInfo> | 231 template <typename CallbackInfo> |
| 289 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, | 232 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, |
| 290 ScriptWrappable* impl, | 233 ScriptWrappable* impl, |
| 291 const ScriptWrappable* wrappable) { | 234 const ScriptWrappable* wrappable) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 302 } | 245 } |
| 303 | 246 |
| 304 template <typename CallbackInfo> | 247 template <typename CallbackInfo> |
| 305 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, | 248 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, |
| 306 Node* impl, | 249 Node* impl, |
| 307 const ScriptWrappable* wrappable) { | 250 const ScriptWrappable* wrappable) { |
| 308 V8SetReturnValueFast(callback_info, ScriptWrappable::FromNode(impl), | 251 V8SetReturnValueFast(callback_info, ScriptWrappable::FromNode(impl), |
| 309 wrappable); | 252 wrappable); |
| 310 } | 253 } |
| 311 | 254 |
| 312 // Special versions for DOMWindow and EventTarget | |
| 313 | |
| 314 template <typename CallbackInfo> | |
| 315 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, | |
| 316 DOMWindow* impl, | |
| 317 const ScriptWrappable*) { | |
| 318 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), | |
| 319 callback_info.GetIsolate())); | |
| 320 } | |
| 321 | |
| 322 template <typename CallbackInfo> | |
| 323 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, | |
| 324 EventTarget* impl, | |
| 325 const ScriptWrappable*) { | |
| 326 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), | |
| 327 callback_info.GetIsolate())); | |
| 328 } | |
| 329 | |
| 330 template <typename CallbackInfo, typename T, typename Wrappable> | 255 template <typename CallbackInfo, typename T, typename Wrappable> |
| 331 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, | 256 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, |
| 332 PassRefPtr<T> impl, | 257 PassRefPtr<T> impl, |
| 333 const Wrappable* wrappable) { | 258 const Wrappable* wrappable) { |
| 334 V8SetReturnValueFast(callback_info, impl.Get(), wrappable); | 259 V8SetReturnValueFast(callback_info, impl.Get(), wrappable); |
| 335 } | 260 } |
| 336 | 261 |
| 337 template <typename CallbackInfo, typename T> | 262 template <typename CallbackInfo, typename T> |
| 338 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, | 263 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, |
| 339 const v8::Local<T> handle, | 264 const v8::Local<T> handle, |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1192 exception_state.ThrowTypeError( | 1117 exception_state.ThrowTypeError( |
| 1193 "The provided ArrayBufferView value must not be shared."); | 1118 "The provided ArrayBufferView value must not be shared."); |
| 1194 return NotSharedType(); | 1119 return NotSharedType(); |
| 1195 } | 1120 } |
| 1196 return NotSharedType(dom_typed_array); | 1121 return NotSharedType(dom_typed_array); |
| 1197 } | 1122 } |
| 1198 | 1123 |
| 1199 } // namespace blink | 1124 } // namespace blink |
| 1200 | 1125 |
| 1201 #endif // V8Binding_h | 1126 #endif // V8Binding_h |
| OLD | NEW |