| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 GIN_WRAPPABLE_H_ | 5 #ifndef GIN_WRAPPABLE_H_ |
| 6 #define GIN_WRAPPABLE_H_ | 6 #define GIN_WRAPPABLE_H_ |
| 7 | 7 |
| 8 #include <type_traits> |
| 9 |
| 8 #include "base/template_util.h" | 10 #include "base/template_util.h" |
| 9 #include "gin/converter.h" | 11 #include "gin/converter.h" |
| 10 #include "gin/gin_export.h" | 12 #include "gin/gin_export.h" |
| 11 #include "gin/public/wrapper_info.h" | 13 #include "gin/public/wrapper_info.h" |
| 12 | 14 |
| 13 namespace gin { | 15 namespace gin { |
| 14 | 16 |
| 15 // Wrappable is a base class for C++ objects that have corresponding v8 wrapper | 17 // Wrappable is a base class for C++ objects that have corresponding v8 wrapper |
| 16 // objects. To retain a Wrappable object on the stack, use a gin::Handle. | 18 // objects. To retain a Wrappable object on the stack, use a gin::Handle. |
| 17 // | 19 // |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 protected: | 96 protected: |
| 95 Wrappable() {} | 97 Wrappable() {} |
| 96 virtual ~Wrappable() {} | 98 virtual ~Wrappable() {} |
| 97 | 99 |
| 98 private: | 100 private: |
| 99 DISALLOW_COPY_AND_ASSIGN(Wrappable); | 101 DISALLOW_COPY_AND_ASSIGN(Wrappable); |
| 100 }; | 102 }; |
| 101 | 103 |
| 102 | 104 |
| 103 // This converter handles any subclass of Wrappable. | 105 // This converter handles any subclass of Wrappable. |
| 104 template<typename T> | 106 template <typename T> |
| 105 struct Converter<T*, typename base::enable_if< | 107 struct Converter<T*, |
| 106 base::is_convertible<T*, WrappableBase*>::value>::type> { | 108 typename std::enable_if< |
| 109 base::is_convertible<T*, WrappableBase*>::value>::type> { |
| 107 static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, T* val) { | 110 static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, T* val) { |
| 108 return val->GetWrapper(isolate); | 111 return val->GetWrapper(isolate); |
| 109 } | 112 } |
| 110 | 113 |
| 111 static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val, T** out) { | 114 static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val, T** out) { |
| 112 *out = static_cast<T*>(static_cast<WrappableBase*>( | 115 *out = static_cast<T*>(static_cast<WrappableBase*>( |
| 113 internal::FromV8Impl(isolate, val, &T::kWrapperInfo))); | 116 internal::FromV8Impl(isolate, val, &T::kWrapperInfo))); |
| 114 return *out != NULL; | 117 return *out != NULL; |
| 115 } | 118 } |
| 116 }; | 119 }; |
| 117 | 120 |
| 118 } // namespace gin | 121 } // namespace gin |
| 119 | 122 |
| 120 #endif // GIN_WRAPPABLE_H_ | 123 #endif // GIN_WRAPPABLE_H_ |
| OLD | NEW |