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 "gin/converter.h" | 8 #include "gin/converter.h" |
9 #include "gin/public/wrapper_info.h" | 9 #include "gin/public/wrapper_info.h" |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, | 71 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, |
72 Wrappable** out); | 72 Wrappable** out); |
73 }; | 73 }; |
74 | 74 |
75 template<typename T> | 75 template<typename T> |
76 struct WrappableConverter { | 76 struct WrappableConverter { |
77 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, T* val) { | 77 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, T* val) { |
78 return Converter<Wrappable*>::ToV8(isolate, val); | 78 return Converter<Wrappable*>::ToV8(isolate, val); |
79 } | 79 } |
80 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, T** out) { | 80 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, T** out) { |
81 Wrappable* wrappable = 0; | 81 Wrappable* wrappable = NULL; |
82 if (!Converter<Wrappable*>::FromV8(isolate, val, &wrappable) | 82 if (!Converter<Wrappable*>::FromV8(isolate, val, &wrappable) |
83 || wrappable->GetWrapperInfo() != &T::kWrapperInfo) | 83 || wrappable->GetWrapperInfo() != &T::kWrapperInfo) |
84 return false; | 84 return false; |
85 // Currently we require that you unwrap to the exact runtime type of the | 85 // Currently we require that you unwrap to the exact runtime type of the |
86 // wrapped object. | 86 // wrapped object. |
87 // TODO(abarth): Support unwrapping to a base class. | 87 // TODO(abarth): Support unwrapping to a base class. |
88 *out = static_cast<T*>(wrappable); | 88 *out = static_cast<T*>(wrappable); |
89 return true; | 89 return true; |
90 } | 90 } |
91 }; | 91 }; |
92 | 92 |
93 } // namespace gin | 93 } // namespace gin |
94 | 94 |
95 #endif // GIN_WRAPPABLE_H_ | 95 #endif // GIN_WRAPPABLE_H_ |
OLD | NEW |