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 "bindings/core/v8/DOMDataStore.h" |
14 #include "bindings/core/v8/IDLDictionaryBase.h" | 14 #include "bindings/core/v8/IDLDictionaryBase.h" |
15 #include "bindings/core/v8/ScriptState.h" | 15 #include "bindings/core/v8/ScriptState.h" |
16 #include "bindings/core/v8/ScriptValue.h" | 16 #include "bindings/core/v8/ScriptValue.h" |
17 #include "bindings/core/v8/ScriptWrappable.h" | 17 #include "bindings/core/v8/ScriptWrappable.h" |
18 #include "bindings/core/v8/V8Binding.h" | 18 #include "bindings/core/v8/V8Binding.h" |
19 #include "core/CoreExport.h" | 19 #include "core/CoreExport.h" |
20 #include "core/dom/NotShared.h" | |
21 #include "platform/heap/Handle.h" | 20 #include "platform/heap/Handle.h" |
22 #include "platform/wtf/Forward.h" | 21 #include "platform/wtf/Forward.h" |
23 #include "v8/include/v8.h" | 22 #include "v8/include/v8.h" |
24 | 23 |
25 namespace blink { | 24 namespace blink { |
26 | 25 |
27 class DOMWindow; | 26 class DOMWindow; |
28 class Dictionary; | 27 class Dictionary; |
29 class EventTarget; | 28 class EventTarget; |
30 | 29 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 if (v8_value.IsEmpty()) | 268 if (v8_value.IsEmpty()) |
270 v8_value = v8::Undefined(isolate); | 269 v8_value = v8::Undefined(isolate); |
271 if (!V8CallBoolean(object->CreateDataProperty( | 270 if (!V8CallBoolean(object->CreateDataProperty( |
272 isolate->GetCurrentContext(), V8String(isolate, value[i].first), | 271 isolate->GetCurrentContext(), V8String(isolate, value[i].first), |
273 v8_value))) | 272 v8_value))) |
274 return v8::Local<v8::Value>(); | 273 return v8::Local<v8::Value>(); |
275 } | 274 } |
276 return object; | 275 return object; |
277 } | 276 } |
278 | 277 |
279 template <typename T> | |
280 inline v8::Local<v8::Value> ToV8(NotShared<T> value, | |
281 v8::Local<v8::Object> creation_context, | |
282 v8::Isolate* isolate) { | |
283 return ToV8(value.View(), creation_context, isolate); | |
284 } | |
285 | |
286 template <typename Sequence> | 278 template <typename Sequence> |
287 inline v8::Local<v8::Value> ToV8SequenceInternal( | 279 inline v8::Local<v8::Value> ToV8SequenceInternal( |
288 const Sequence& sequence, | 280 const Sequence& sequence, |
289 v8::Local<v8::Object> creation_context, | 281 v8::Local<v8::Object> creation_context, |
290 v8::Isolate* isolate) { | 282 v8::Isolate* isolate) { |
291 v8::Local<v8::Array> array; | 283 v8::Local<v8::Array> array; |
292 { | 284 { |
293 v8::Context::Scope context_scope(creation_context->CreationContext()); | 285 v8::Context::Scope context_scope(creation_context->CreationContext()); |
294 array = v8::Array::New(isolate, sequence.size()); | 286 array = v8::Array::New(isolate, sequence.size()); |
295 } | 287 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // Cannot define in ScriptValue because of the circular dependency between toV8 | 323 // Cannot define in ScriptValue because of the circular dependency between toV8 |
332 // and ScriptValue | 324 // and ScriptValue |
333 template <typename T> | 325 template <typename T> |
334 inline ScriptValue ScriptValue::From(ScriptState* script_state, T&& value) { | 326 inline ScriptValue ScriptValue::From(ScriptState* script_state, T&& value) { |
335 return ScriptValue(script_state, ToV8(std::forward<T>(value), script_state)); | 327 return ScriptValue(script_state, ToV8(std::forward<T>(value), script_state)); |
336 } | 328 } |
337 | 329 |
338 } // namespace blink | 330 } // namespace blink |
339 | 331 |
340 #endif // ToV8_h | 332 #endif // ToV8_h |
OLD | NEW |