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 "bindings/core/v8/DOMDataStore.h" | 11 #include "bindings/core/v8/DOMDataStore.h" |
12 #include "bindings/core/v8/IDLDictionaryBase.h" | 12 #include "bindings/core/v8/IDLDictionaryBase.h" |
13 #include "bindings/core/v8/ScriptState.h" | 13 #include "bindings/core/v8/ScriptState.h" |
14 #include "bindings/core/v8/ScriptValue.h" | 14 #include "bindings/core/v8/ScriptValue.h" |
15 #include "bindings/core/v8/ScriptWrappable.h" | 15 #include "bindings/core/v8/ScriptWrappable.h" |
16 #include "bindings/core/v8/V8Binding.h" | 16 #include "bindings/core/v8/V8Binding.h" |
17 #include "core/CoreExport.h" | 17 #include "core/CoreExport.h" |
18 #include "platform/heap/Handle.h" | 18 #include "platform/heap/Handle.h" |
19 #include "wtf/Forward.h" | 19 #include "wtf/Forward.h" |
20 #include <utility> | 20 #include <utility> |
21 #include <v8.h> | 21 #include <v8.h> |
22 | 22 |
23 namespace blink { | 23 namespace blink { |
24 | 24 |
25 class DOMWindow; | |
26 class Dictionary; | 25 class Dictionary; |
27 class EventTarget; | |
28 | 26 |
29 // ScriptWrappable | 27 // ScriptWrappable |
30 | 28 |
31 inline v8::Local<v8::Value> ToV8(ScriptWrappable* impl, | 29 inline v8::Local<v8::Value> ToV8(ScriptWrappable* impl, |
32 v8::Local<v8::Object> creationContext, | 30 v8::Local<v8::Object> creationContext, |
33 v8::Isolate* isolate) { | 31 v8::Isolate* isolate) { |
34 if (UNLIKELY(!impl)) | 32 if (UNLIKELY(!impl)) |
35 return v8::Null(isolate); | 33 return v8::Null(isolate); |
36 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); | 34 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); |
37 if (!wrapper.IsEmpty()) | 35 if (!wrapper.IsEmpty()) |
(...skipping 11 matching lines...) Expand all Loading... |
49 return v8::Null(isolate); | 47 return v8::Null(isolate); |
50 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); | 48 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); |
51 if (!wrapper.IsEmpty()) | 49 if (!wrapper.IsEmpty()) |
52 return wrapper; | 50 return wrapper; |
53 | 51 |
54 wrapper = ScriptWrappable::fromNode(impl)->wrap(isolate, creationContext); | 52 wrapper = ScriptWrappable::fromNode(impl)->wrap(isolate, creationContext); |
55 DCHECK(!wrapper.IsEmpty()); | 53 DCHECK(!wrapper.IsEmpty()); |
56 return wrapper; | 54 return wrapper; |
57 } | 55 } |
58 | 56 |
59 // Special versions for DOMWindow and EventTarget | |
60 | |
61 CORE_EXPORT v8::Local<v8::Value> ToV8(DOMWindow*, | |
62 v8::Local<v8::Object> creationContext, | |
63 v8::Isolate*); | |
64 CORE_EXPORT v8::Local<v8::Value> ToV8(EventTarget*, | |
65 v8::Local<v8::Object> creationContext, | |
66 v8::Isolate*); | |
67 | |
68 // Primitives | 57 // Primitives |
69 | 58 |
70 inline v8::Local<v8::Value> ToV8(const String& value, | 59 inline v8::Local<v8::Value> ToV8(const String& value, |
71 v8::Local<v8::Object> creationContext, | 60 v8::Local<v8::Object> creationContext, |
72 v8::Isolate* isolate) { | 61 v8::Isolate* isolate) { |
73 return v8String(isolate, value); | 62 return v8String(isolate, value); |
74 } | 63 } |
75 | 64 |
76 inline v8::Local<v8::Value> ToV8(const char* value, | 65 inline v8::Local<v8::Value> ToV8(const char* value, |
77 v8::Local<v8::Object> creationContext, | 66 v8::Local<v8::Object> creationContext, |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // Cannot define in ScriptValue because of the circular dependency between toV8 | 296 // Cannot define in ScriptValue because of the circular dependency between toV8 |
308 // and ScriptValue | 297 // and ScriptValue |
309 template <typename T> | 298 template <typename T> |
310 inline ScriptValue ScriptValue::from(ScriptState* scriptState, T&& value) { | 299 inline ScriptValue ScriptValue::from(ScriptState* scriptState, T&& value) { |
311 return ScriptValue(scriptState, ToV8(std::forward<T>(value), scriptState)); | 300 return ScriptValue(scriptState, ToV8(std::forward<T>(value), scriptState)); |
312 } | 301 } |
313 | 302 |
314 } // namespace blink | 303 } // namespace blink |
315 | 304 |
316 #endif // ToV8_h | 305 #endif // ToV8_h |
OLD | NEW |