| 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/ScriptValue.h" | 12 #include "bindings/core/v8/ScriptValue.h" |
| 13 #include "bindings/core/v8/ScriptWrappable.h" | 13 #include "bindings/core/v8/ScriptWrappable.h" |
| 14 #include "bindings/core/v8/V8Binding.h" | 14 #include "bindings/core/v8/V8Binding.h" |
| 15 #include "core/CoreExport.h" | 15 #include "core/CoreExport.h" |
| 16 #include "platform/heap/Handle.h" | 16 #include "platform/heap/Handle.h" |
| 17 #include "wtf/Forward.h" | 17 #include "wtf/Forward.h" |
| 18 #include <v8.h> | 18 #include <v8.h> |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 class DOMWindow; | 22 class DOMWindow; |
| 23 class Dictionary; | 23 class Dictionary; |
| 24 class EventTarget; | 24 class EventTarget; |
| 25 class WorkerGlobalScope; | 25 class WorkerOrWorkletGlobalScope; |
| 26 | 26 |
| 27 // ScriptWrappable | 27 // ScriptWrappable |
| 28 | 28 |
| 29 inline v8::Local<v8::Value> toV8(ScriptWrappable* impl, v8::Local<v8::Object> cr
eationContext, v8::Isolate* isolate) | 29 inline v8::Local<v8::Value> toV8(ScriptWrappable* impl, v8::Local<v8::Object> cr
eationContext, v8::Isolate* isolate) |
| 30 { | 30 { |
| 31 if (UNLIKELY(!impl)) | 31 if (UNLIKELY(!impl)) |
| 32 return v8::Null(isolate); | 32 return v8::Null(isolate); |
| 33 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); | 33 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); |
| 34 if (!wrapper.IsEmpty()) | 34 if (!wrapper.IsEmpty()) |
| 35 return wrapper; | 35 return wrapper; |
| 36 | 36 |
| 37 return impl->wrap(isolate, creationContext); | 37 return impl->wrap(isolate, creationContext); |
| 38 } | 38 } |
| 39 | 39 |
| 40 inline v8::Local<v8::Value> toV8(Node* impl, v8::Local<v8::Object> creationConte
xt, v8::Isolate* isolate) | 40 inline v8::Local<v8::Value> toV8(Node* impl, v8::Local<v8::Object> creationConte
xt, v8::Isolate* isolate) |
| 41 { | 41 { |
| 42 if (UNLIKELY(!impl)) | 42 if (UNLIKELY(!impl)) |
| 43 return v8::Null(isolate); | 43 return v8::Null(isolate); |
| 44 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); | 44 v8::Local<v8::Value> wrapper = DOMDataStore::getWrapper(impl, isolate); |
| 45 if (!wrapper.IsEmpty()) | 45 if (!wrapper.IsEmpty()) |
| 46 return wrapper; | 46 return wrapper; |
| 47 | 47 |
| 48 return ScriptWrappable::fromNode(impl)->wrap(isolate, creationContext); | 48 return ScriptWrappable::fromNode(impl)->wrap(isolate, creationContext); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Special versions for DOMWindow, WorkerGlobalScope and EventTarget | 51 // Special versions for DOMWindow, WorkerOrWorkletGlobalScope and EventTarget |
| 52 | 52 |
| 53 CORE_EXPORT v8::Local<v8::Value> toV8(DOMWindow*, v8::Local<v8::Object> creation
Context, v8::Isolate*); | 53 CORE_EXPORT v8::Local<v8::Value> toV8(DOMWindow*, v8::Local<v8::Object> creation
Context, v8::Isolate*); |
| 54 CORE_EXPORT v8::Local<v8::Value> toV8(EventTarget*, v8::Local<v8::Object> creati
onContext, v8::Isolate*); | 54 CORE_EXPORT v8::Local<v8::Value> toV8(EventTarget*, v8::Local<v8::Object> creati
onContext, v8::Isolate*); |
| 55 v8::Local<v8::Value> toV8(WorkerGlobalScope*, v8::Local<v8::Object> creationCont
ext, v8::Isolate*); | 55 v8::Local<v8::Value> toV8(WorkerOrWorkletGlobalScope*, v8::Local<v8::Object> cre
ationContext, v8::Isolate*); |
| 56 | 56 |
| 57 // PassRefPtr, RawPtr and RefPtr | 57 // PassRefPtr, RawPtr and RefPtr |
| 58 | 58 |
| 59 template<typename T> | 59 template<typename T> |
| 60 inline v8::Local<v8::Value> toV8(PassRefPtr<T> impl, v8::Local<v8::Object> creat
ionContext, v8::Isolate* isolate) | 60 inline v8::Local<v8::Value> toV8(PassRefPtr<T> impl, v8::Local<v8::Object> creat
ionContext, v8::Isolate* isolate) |
| 61 { | 61 { |
| 62 return toV8(impl.get(), creationContext, isolate); | 62 return toV8(impl.get(), creationContext, isolate); |
| 63 } | 63 } |
| 64 | 64 |
| 65 template<typename T> | 65 template<typename T> |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // Without toV8(void*, ...), call to toV8 with T* will match with | 247 // 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 | 248 // 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 | 249 // declared but not defined (so it's not clear that T is a subclass of |
| 250 // ScriptWrappable). | 250 // ScriptWrappable). |
| 251 // This hack helps detect such unwanted implicit conversions from T* to bool. | 251 // 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; | 252 v8::Local<v8::Value> toV8(void* value, v8::Local<v8::Object> creationContext, v8
::Isolate*) = delete; |
| 253 | 253 |
| 254 } // namespace blink | 254 } // namespace blink |
| 255 | 255 |
| 256 #endif // ToV8_h | 256 #endif // ToV8_h |
| OLD | NEW |