OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ToV8_h | 5 #ifndef ToV8_h |
6 #define ToV8_h | 6 #define ToV8_h |
7 | 7 |
8 // ToV8() provides C++ -> V8 conversion. Note that ToV8() can return an empty | 8 // ToV8() provides C++ -> V8 conversion. Note that ToV8() can return an empty |
9 // handle. Call sites must check IsEmpty() before using return value. | 9 // handle. Call sites must check IsEmpty() before using return value. |
10 | 10 |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "bindings/core/v8/DOMDataStore.h" | 13 #include "platform/bindings/DOMDataStore.h" |
14 #include "bindings/core/v8/IDLDictionaryBase.h" | 14 #include "platform/bindings/ScriptState.h" |
15 #include "bindings/core/v8/ScriptState.h" | 15 #include "platform/bindings/ScriptWrappable.h" |
16 #include "bindings/core/v8/ScriptValue.h" | 16 #include "platform/bindings/V8Binding.h" |
17 #include "bindings/core/v8/ScriptWrappable.h" | |
18 #include "bindings/core/v8/V8Binding.h" | |
19 #include "core/CoreExport.h" | |
20 #include "core/dom/ArrayBufferViewHelpers.h" | |
21 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
22 #include "platform/wtf/Forward.h" | 18 #include "platform/wtf/Forward.h" |
23 #include "v8/include/v8.h" | 19 #include "v8/include/v8.h" |
24 | 20 |
25 namespace blink { | 21 namespace blink { |
26 | 22 |
27 // ScriptWrappable | 23 // ScriptWrappable |
28 | 24 |
29 inline v8::Local<v8::Value> ToV8(ScriptWrappable* impl, | 25 inline v8::Local<v8::Value> ToV8(ScriptWrappable* impl, |
30 v8::Local<v8::Object> creation_context, | 26 v8::Local<v8::Object> creation_context, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 struct ToV8UndefinedGenerator { | 153 struct ToV8UndefinedGenerator { |
158 DISALLOW_NEW(); | 154 DISALLOW_NEW(); |
159 }; // Used only for having toV8 return v8::Undefined. | 155 }; // Used only for having toV8 return v8::Undefined. |
160 | 156 |
161 inline v8::Local<v8::Value> ToV8(const ToV8UndefinedGenerator& value, | 157 inline v8::Local<v8::Value> ToV8(const ToV8UndefinedGenerator& value, |
162 v8::Local<v8::Object> creation_context, | 158 v8::Local<v8::Object> creation_context, |
163 v8::Isolate* isolate) { | 159 v8::Isolate* isolate) { |
164 return v8::Undefined(isolate); | 160 return v8::Undefined(isolate); |
165 } | 161 } |
166 | 162 |
167 // ScriptValue | |
168 | |
169 inline v8::Local<v8::Value> ToV8(const ScriptValue& value, | |
170 v8::Local<v8::Object> creation_context, | |
171 v8::Isolate* isolate) { | |
172 if (value.IsEmpty()) | |
173 return v8::Undefined(isolate); | |
174 return value.V8Value(); | |
175 } | |
176 | |
177 // Dictionary | |
178 | |
179 inline v8::Local<v8::Value> ToV8(const IDLDictionaryBase& value, | |
180 v8::Local<v8::Object> creation_context, | |
181 v8::Isolate* isolate) { | |
182 return value.ToV8Impl(creation_context, isolate); | |
183 } | |
184 | |
185 // Array | 163 // Array |
186 | 164 |
187 // Declare the function here but define it later so it can call the ToV8() | 165 // Declare the function here but define it later so it can call the ToV8() |
188 // overloads below. | 166 // overloads below. |
189 template <typename Sequence> | 167 template <typename Sequence> |
190 inline v8::Local<v8::Value> ToV8SequenceInternal( | 168 inline v8::Local<v8::Value> ToV8SequenceInternal( |
191 const Sequence&, | 169 const Sequence&, |
192 v8::Local<v8::Object> creation_context, | 170 v8::Local<v8::Object> creation_context, |
193 v8::Isolate*); | 171 v8::Isolate*); |
194 | 172 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // because of "unresolved external symbol". | 266 // because of "unresolved external symbol". |
289 // Without ToV8(void*, ...), call to toV8 with T* will match with | 267 // Without ToV8(void*, ...), call to toV8 with T* will match with |
290 // ToV8(bool, ...) if T is not a subclass of ScriptWrappable or if T is | 268 // ToV8(bool, ...) if T is not a subclass of ScriptWrappable or if T is |
291 // declared but not defined (so it's not clear that T is a subclass of | 269 // declared but not defined (so it's not clear that T is a subclass of |
292 // ScriptWrappable). | 270 // ScriptWrappable). |
293 // This hack helps detect such unwanted implicit conversions from T* to bool. | 271 // This hack helps detect such unwanted implicit conversions from T* to bool. |
294 v8::Local<v8::Value> ToV8(void* value, | 272 v8::Local<v8::Value> ToV8(void* value, |
295 v8::Local<v8::Object> creation_context, | 273 v8::Local<v8::Object> creation_context, |
296 v8::Isolate*) = delete; | 274 v8::Isolate*) = delete; |
297 | 275 |
298 // Cannot define in ScriptValue because of the circular dependency between toV8 | |
299 // and ScriptValue | |
300 template <typename T> | |
301 inline ScriptValue ScriptValue::From(ScriptState* script_state, T&& value) { | |
302 return ScriptValue(script_state, ToV8(std::forward<T>(value), script_state)); | |
303 } | |
304 | |
305 } // namespace blink | 276 } // namespace blink |
306 | 277 |
307 #endif // ToV8ForPlatform_h | 278 #endif // ToV8ForPlatform_h |
OLD | NEW |