OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2017 Google Inc. All rights reserved. | 2 * Copyright (C) 2017 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 22 matching lines...) Expand all Loading... |
33 #define V8BindingForCore_h | 33 #define V8BindingForCore_h |
34 | 34 |
35 #include "bindings/core/v8/DOMDataStore.h" | 35 #include "bindings/core/v8/DOMDataStore.h" |
36 #include "bindings/core/v8/DOMWrapperWorld.h" | 36 #include "bindings/core/v8/DOMWrapperWorld.h" |
37 #include "bindings/core/v8/ExceptionMessages.h" | 37 #include "bindings/core/v8/ExceptionMessages.h" |
38 #include "bindings/core/v8/ExceptionState.h" | 38 #include "bindings/core/v8/ExceptionState.h" |
39 #include "bindings/core/v8/NativeValueTraits.h" | 39 #include "bindings/core/v8/NativeValueTraits.h" |
40 #include "bindings/core/v8/ScriptState.h" | 40 #include "bindings/core/v8/ScriptState.h" |
41 #include "bindings/core/v8/ScriptValue.h" | 41 #include "bindings/core/v8/ScriptValue.h" |
42 #include "bindings/core/v8/ScriptWrappable.h" | 42 #include "bindings/core/v8/ScriptWrappable.h" |
| 43 #include "bindings/core/v8/ToV8ForCore.h" |
43 #include "bindings/core/v8/V8Binding.h" | 44 #include "bindings/core/v8/V8Binding.h" |
44 #include "bindings/core/v8/V8BindingMacros.h" | 45 #include "bindings/core/v8/V8BindingMacros.h" |
45 #include "bindings/core/v8/V8PerIsolateData.h" | 46 #include "bindings/core/v8/V8PerIsolateData.h" |
46 #include "bindings/core/v8/V8ScriptRunner.h" | 47 #include "bindings/core/v8/V8ScriptRunner.h" |
47 #include "bindings/core/v8/V8StringResource.h" | 48 #include "bindings/core/v8/V8StringResource.h" |
48 #include "bindings/core/v8/V8ThrowException.h" | 49 #include "bindings/core/v8/V8ThrowException.h" |
49 #include "bindings/core/v8/V8ValueCache.h" | 50 #include "bindings/core/v8/V8ValueCache.h" |
50 #include "core/CoreExport.h" | 51 #include "core/CoreExport.h" |
51 #include "core/dom/ArrayBufferViewHelpers.h" | 52 #include "core/dom/ArrayBufferViewHelpers.h" |
| 53 #include "core/dom/Node.h" |
52 #include "platform/heap/Handle.h" | 54 #include "platform/heap/Handle.h" |
53 #include "platform/wtf/text/AtomicString.h" | 55 #include "platform/wtf/text/AtomicString.h" |
54 #include "platform/wtf/text/StringView.h" | 56 #include "platform/wtf/text/StringView.h" |
55 #include "v8/include/v8.h" | 57 #include "v8/include/v8.h" |
56 | 58 |
57 namespace blink { | 59 namespace blink { |
58 | 60 |
59 // This file contains core-specific bindings utility functions. For functions | 61 // This file contains core-specific bindings utility functions. For functions |
60 // that are core independent, see bindings/core/v8/V8Binding.h. When adding a | 62 // that are core independent, see bindings/core/v8/V8Binding.h. When adding a |
61 // new utility function, consider adding it to V8Binding.h instead unless it has | 63 // new utility function, consider adding it to V8Binding.h instead unless it has |
62 // dependencies to core/. | 64 // dependencies to core/. |
63 | 65 |
64 class DOMWindow; | 66 class DOMWindow; |
65 class EventListener; | 67 class EventListener; |
| 68 class EventTarget; |
66 class ExceptionState; | 69 class ExceptionState; |
67 class ExecutionContext; | 70 class ExecutionContext; |
68 class FlexibleArrayBufferView; | 71 class FlexibleArrayBufferView; |
69 class Frame; | 72 class Frame; |
70 class LocalDOMWindow; | 73 class LocalDOMWindow; |
71 class LocalFrame; | 74 class LocalFrame; |
72 class NodeFilter; | 75 class NodeFilter; |
73 class XPathNSResolver; | 76 class XPathNSResolver; |
74 | 77 |
| 78 template <typename CallbackInfo> |
| 79 inline void V8SetReturnValue(const CallbackInfo& callback_info, |
| 80 DOMWindow* impl) { |
| 81 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), |
| 82 callback_info.GetIsolate())); |
| 83 } |
| 84 |
| 85 template <typename CallbackInfo> |
| 86 inline void V8SetReturnValue(const CallbackInfo& callback_info, |
| 87 EventTarget* impl) { |
| 88 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), |
| 89 callback_info.GetIsolate())); |
| 90 } |
| 91 |
| 92 template <typename CallbackInfo> |
| 93 inline void V8SetReturnValue(const CallbackInfo& callback_info, Node* impl) { |
| 94 V8SetReturnValue(callback_info, static_cast<ScriptWrappable*>(impl)); |
| 95 } |
| 96 |
| 97 template <typename CallbackInfo> |
| 98 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, |
| 99 DOMWindow* impl) { |
| 100 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), |
| 101 callback_info.GetIsolate())); |
| 102 } |
| 103 |
| 104 template <typename CallbackInfo> |
| 105 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, |
| 106 EventTarget* impl) { |
| 107 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), |
| 108 callback_info.GetIsolate())); |
| 109 } |
| 110 |
| 111 template <typename CallbackInfo> |
| 112 inline void V8SetReturnValueForMainWorld(const CallbackInfo& callback_info, |
| 113 Node* impl) { |
| 114 // Since EventTarget has a special version of ToV8 and V8EventTarget.h |
| 115 // defines its own v8SetReturnValue family, which are slow, we need to |
| 116 // override them with optimized versions for Node and its subclasses. |
| 117 // Without this overload, V8SetReturnValueForMainWorld for Node would be |
| 118 // very slow. |
| 119 // |
| 120 // class hierarchy: |
| 121 // ScriptWrappable <-- EventTarget <--+-- Node <-- ... |
| 122 // +-- Window |
| 123 // overloads: |
| 124 // V8SetReturnValueForMainWorld(ScriptWrappable*) |
| 125 // Optimized and very fast. |
| 126 // V8SetReturnValueForMainWorld(EventTarget*) |
| 127 // Uses custom ToV8 function and slow. |
| 128 // V8SetReturnValueForMainWorld(Node*) |
| 129 // Optimized and very fast. |
| 130 // V8SetReturnValueForMainWorld(Window*) |
| 131 // Uses custom ToV8 function and slow. |
| 132 V8SetReturnValueForMainWorld(callback_info, |
| 133 static_cast<ScriptWrappable*>(impl)); |
| 134 } |
| 135 |
| 136 template <typename CallbackInfo> |
| 137 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, |
| 138 DOMWindow* impl, |
| 139 const ScriptWrappable*) { |
| 140 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), |
| 141 callback_info.GetIsolate())); |
| 142 } |
| 143 |
| 144 template <typename CallbackInfo> |
| 145 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, |
| 146 EventTarget* impl, |
| 147 const ScriptWrappable*) { |
| 148 V8SetReturnValue(callback_info, ToV8(impl, callback_info.Holder(), |
| 149 callback_info.GetIsolate())); |
| 150 } |
| 151 |
| 152 template <typename CallbackInfo> |
| 153 inline void V8SetReturnValueFast(const CallbackInfo& callback_info, |
| 154 Node* impl, |
| 155 const ScriptWrappable* wrappable) { |
| 156 V8SetReturnValueFast(callback_info, static_cast<ScriptWrappable*>(impl), |
| 157 wrappable); |
| 158 } |
| 159 |
75 template <typename CallbackInfo, typename T> | 160 template <typename CallbackInfo, typename T> |
76 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, | 161 inline void V8SetReturnValue(const CallbackInfo& callbackInfo, |
77 NotShared<T> notShared) { | 162 NotShared<T> notShared) { |
78 V8SetReturnValue(callbackInfo, notShared.View()); | 163 V8SetReturnValue(callbackInfo, notShared.View()); |
79 } | 164 } |
80 | 165 |
81 template <typename CallbackInfo, typename T> | 166 template <typename CallbackInfo, typename T> |
82 inline void V8SetReturnValueFast(const CallbackInfo& callbackInfo, | 167 inline void V8SetReturnValueFast(const CallbackInfo& callbackInfo, |
83 NotShared<T> notShared, | 168 NotShared<T> notShared, |
84 const ScriptWrappable* wrappable) { | 169 const ScriptWrappable* wrappable) { |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 ExceptionState& exception_state) { | 614 ExceptionState& exception_state) { |
530 using DOMTypedArray = typename MaybeSharedType::TypedArrayType; | 615 using DOMTypedArray = typename MaybeSharedType::TypedArrayType; |
531 DOMTypedArray* dom_typed_array = | 616 DOMTypedArray* dom_typed_array = |
532 V8TypeOf<DOMTypedArray>::Type::toImplWithTypeCheck(isolate, value); | 617 V8TypeOf<DOMTypedArray>::Type::toImplWithTypeCheck(isolate, value); |
533 return MaybeSharedType(dom_typed_array); | 618 return MaybeSharedType(dom_typed_array); |
534 } | 619 } |
535 | 620 |
536 } // namespace blink | 621 } // namespace blink |
537 | 622 |
538 #endif // V8BindingForCore_h | 623 #endif // V8BindingForCore_h |
OLD | NEW |