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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "gin/converter.h" | 9 #include "gin/converter.h" |
10 #include "gin/public/wrapper_info.h" | 10 #include "gin/public/wrapper_info.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, | 75 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, |
76 Wrappable** out); | 76 Wrappable** out); |
77 }; | 77 }; |
78 | 78 |
79 template<typename T> | 79 template<typename T> |
80 struct WrappableConverter { | 80 struct WrappableConverter { |
81 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, T* val) { | 81 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, T* val) { |
82 return Converter<Wrappable*>::ToV8(isolate, val); | 82 return Converter<Wrappable*>::ToV8(isolate, val); |
83 } | 83 } |
84 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, T** out) { | 84 static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, T** out) { |
85 Wrappable* wrappable = 0; | 85 Wrappable* wrappable = NULL; |
Aaron Boodman
2013/12/04 07:05:29
We use NULL, not zero in Chrome code
abarth-chromium
2013/12/04 16:27:55
Yep!
| |
86 if (!Converter<Wrappable*>::FromV8(isolate, val, &wrappable) | 86 if (!Converter<Wrappable*>::FromV8(isolate, val, &wrappable) |
87 || wrappable->GetWrapperInfo() != &T::kWrapperInfo) | 87 || wrappable->GetWrapperInfo() != &T::kWrapperInfo) |
88 return false; | 88 return false; |
89 // Currently we require that you unwrap to the exact runtime type of the | 89 // Currently we require that you unwrap to the exact runtime type of the |
90 // wrapped object. | 90 // wrapped object. |
91 // TODO(abarth): Support unwrapping to a base class. | 91 // TODO(abarth): Support unwrapping to a base class. |
92 *out = static_cast<T*>(wrappable); | 92 *out = static_cast<T*>(wrappable); |
93 return true; | 93 return true; |
94 } | 94 } |
95 }; | 95 }; |
96 | 96 |
97 } // namespace gin | 97 } // namespace gin |
98 | 98 |
99 #endif // GIN_WRAPPABLE_H_ | 99 #endif // GIN_WRAPPABLE_H_ |
OLD | NEW |