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/ScriptState.h" | |
12 #include "bindings/core/v8/ScriptValue.h" | 13 #include "bindings/core/v8/ScriptValue.h" |
13 #include "bindings/core/v8/ScriptWrappable.h" | 14 #include "bindings/core/v8/ScriptWrappable.h" |
14 #include "bindings/core/v8/V8Binding.h" | 15 #include "bindings/core/v8/V8Binding.h" |
15 #include "core/CoreExport.h" | 16 #include "core/CoreExport.h" |
16 #include "platform/heap/Handle.h" | 17 #include "platform/heap/Handle.h" |
17 #include "wtf/Forward.h" | 18 #include "wtf/Forward.h" |
18 #include <v8.h> | 19 #include <v8.h> |
19 | 20 |
20 namespace blink { | 21 namespace blink { |
21 | 22 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 for (unsigned i = 0; i < value.size(); ++i) { | 235 for (unsigned i = 0; i < value.size(); ++i) { |
235 v8::Local<v8::Value> v8Value = toV8(value[i].second, creationContext, is olate); | 236 v8::Local<v8::Value> v8Value = toV8(value[i].second, creationContext, is olate); |
236 if (v8Value.IsEmpty()) | 237 if (v8Value.IsEmpty()) |
237 v8Value = v8::Undefined(isolate); | 238 v8Value = v8::Undefined(isolate); |
238 if (!v8CallBoolean(object->Set(isolate->GetCurrentContext(), v8String(is olate, value[i].first), v8Value))) | 239 if (!v8CallBoolean(object->Set(isolate->GetCurrentContext(), v8String(is olate, value[i].first), v8Value))) |
239 return v8::Local<v8::Value>(); | 240 return v8::Local<v8::Value>(); |
240 } | 241 } |
241 return object; | 242 return object; |
242 } | 243 } |
243 | 244 |
245 // In all cases allow script state instead of creation context + isolate. | |
246 // Only use if your function does not otherwise need the global, as | |
247 // v8::Context::Global() is not simply a getter. | |
haraken
2016/01/16 03:51:22
What do you mean by "v8::Context::Global() is not
| |
248 template<typename T> | |
249 inline v8::Local<v8::Value> toV8(T value, ScriptState* scriptState) | |
yhirano
2016/01/17 23:51:38
Is "T&&" better for avoiding copy?
| |
250 { | |
251 return toV8(value, scriptState->context()->Global(), scriptState->isolate()) ; | |
252 } | |
253 | |
244 // Only declare toV8(void*,...) for checking function overload mismatch. | 254 // Only declare toV8(void*,...) for checking function overload mismatch. |
245 // This toV8(void*,...) should be never used. So we will find mismatch | 255 // This toV8(void*,...) should be never used. So we will find mismatch |
246 // because of "unresolved external symbol". | 256 // because of "unresolved external symbol". |
247 // Without toV8(void*, ...), call to toV8 with T* will match with | 257 // Without toV8(void*, ...), call to toV8 with T* will match with |
248 // toV8(bool, ...) if T is not a subclass of ScriptWrappable or if T is | 258 // toV8(bool, ...) if T is not a subclass of ScriptWrappable or if T is |
249 // declared but not defined (so it's not clear that T is a subclass of | 259 // declared but not defined (so it's not clear that T is a subclass of |
250 // ScriptWrappable). | 260 // ScriptWrappable). |
251 // This hack helps detect such unwanted implicit conversions from T* to bool. | 261 // This hack helps detect such unwanted implicit conversions from T* to bool. |
252 v8::Local<v8::Value> toV8(void* value, v8::Local<v8::Object> creationContext, v8 ::Isolate*) = delete; | 262 v8::Local<v8::Value> toV8(void* value, v8::Local<v8::Object> creationContext, v8 ::Isolate*) = delete; |
253 | 263 |
254 } // namespace blink | 264 } // namespace blink |
255 | 265 |
256 #endif // ToV8_h | 266 #endif // ToV8_h |
OLD | NEW |