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_OBJECT_TEMPLATE_BUILDER_H_ | 5 #ifndef GIN_OBJECT_TEMPLATE_BUILDER_H_ |
6 #define GIN_OBJECT_TEMPLATE_BUILDER_H_ | 6 #define GIN_OBJECT_TEMPLATE_BUILDER_H_ |
7 | 7 |
| 8 #include <type_traits> |
| 9 |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/callback.h" | 11 #include "base/callback.h" |
10 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
11 #include "base/template_util.h" | 13 #include "base/template_util.h" |
12 #include "gin/converter.h" | 14 #include "gin/converter.h" |
13 #include "gin/function_template.h" | 15 #include "gin/function_template.h" |
14 #include "gin/gin_export.h" | 16 #include "gin/gin_export.h" |
15 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
16 | 18 |
17 namespace gin { | 19 namespace gin { |
(...skipping 27 matching lines...) Expand all Loading... |
45 v8::Local<v8::ObjectTemplate> tmpl, | 47 v8::Local<v8::ObjectTemplate> tmpl, |
46 const base::Callback<T>& callback) { | 48 const base::Callback<T>& callback) { |
47 CreateFunctionHandler(isolate, tmpl, callback); | 49 CreateFunctionHandler(isolate, tmpl, callback); |
48 } | 50 } |
49 }; | 51 }; |
50 | 52 |
51 // Specialization for member function pointers. We need to handle this case | 53 // Specialization for member function pointers. We need to handle this case |
52 // specially because the first parameter for callbacks to MFP should typically | 54 // specially because the first parameter for callbacks to MFP should typically |
53 // come from the the JavaScript "this" object the function was called on, not | 55 // come from the the JavaScript "this" object the function was called on, not |
54 // from the first normal parameter. | 56 // from the first normal parameter. |
55 template<typename T> | 57 template <typename T> |
56 struct CallbackTraits<T, typename base::enable_if< | 58 struct CallbackTraits< |
57 base::is_member_function_pointer<T>::value>::type> { | 59 T, |
| 60 typename std::enable_if<base::is_member_function_pointer<T>::value>::type> { |
58 static v8::Local<v8::FunctionTemplate> CreateTemplate(v8::Isolate* isolate, | 61 static v8::Local<v8::FunctionTemplate> CreateTemplate(v8::Isolate* isolate, |
59 T callback) { | 62 T callback) { |
60 return CreateFunctionTemplate(isolate, base::Bind(callback), | 63 return CreateFunctionTemplate(isolate, base::Bind(callback), |
61 HolderIsFirstArgument); | 64 HolderIsFirstArgument); |
62 } | 65 } |
63 static void SetAsFunctionHandler(v8::Isolate* isolate, | 66 static void SetAsFunctionHandler(v8::Isolate* isolate, |
64 v8::Local<v8::ObjectTemplate> tmpl, | 67 v8::Local<v8::ObjectTemplate> tmpl, |
65 T callback) { | 68 T callback) { |
66 CreateFunctionHandler( | 69 CreateFunctionHandler( |
67 isolate, tmpl, base::Bind(callback), HolderIsFirstArgument); | 70 isolate, tmpl, base::Bind(callback), HolderIsFirstArgument); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 141 |
139 v8::Isolate* isolate_; | 142 v8::Isolate* isolate_; |
140 | 143 |
141 // ObjectTemplateBuilder should only be used on the stack. | 144 // ObjectTemplateBuilder should only be used on the stack. |
142 v8::Local<v8::ObjectTemplate> template_; | 145 v8::Local<v8::ObjectTemplate> template_; |
143 }; | 146 }; |
144 | 147 |
145 } // namespace gin | 148 } // namespace gin |
146 | 149 |
147 #endif // GIN_OBJECT_TEMPLATE_BUILDER_H_ | 150 #endif // GIN_OBJECT_TEMPLATE_BUILDER_H_ |
OLD | NEW |