@@ -136,15 +136,59 @@ namespace Nan {
136
136
137
137
// === RegistrationFunction =====================================================
138
138
139
- #if NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
140
- typedef v8::Handle<v8::Object> ADDON_REGISTER_FUNCTION_ARGS_TYPE;
139
+ typedef void (*addon_reg_func_t )(v8::Local<v8::Object> target);
140
+
141
+ #if NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION
142
+ namespace imp {
143
+ template <addon_reg_func_t F>
144
+ static inline void addon_reg_func (v8::Handle<v8::Object> target) {
145
+ v8::HandleScope scope;
146
+ F (v8::Local<v8::Object>::New (target));
147
+ }
148
+ }
149
+
150
+ # define NAN_MODULE (modname, regfunc ) \
151
+ extern " C" { \
152
+ NODE_MODULE_EXPORT node::node_module_struct modname ## _module = \
153
+ { \
154
+ NODE_STANDARD_MODULE_STUFF, \
155
+ (node::addon_register_func) Nan::imp::addon_reg_func<regfunc>, \
156
+ NODE_STRINGIFY (modname) \
157
+ }; \
158
+ }
159
+
160
+ #elif NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
161
+ namespace imp {
162
+ template <addon_reg_func_t F>
163
+ static inline void addon_reg_func (v8::Handle<v8::Object> target) {
164
+ v8::Isolate *isolate = v8::Isolate::GetCurrent ();
165
+ v8::HandleScope scope (isolate);
166
+ F (v8::Local<v8::Object>::New (isolate, target));
167
+ }
168
+ }
169
+
170
+ # define NAN_MODULE (modname, regfunc ) \
171
+ extern " C" { \
172
+ static node::node_module _module = \
173
+ { \
174
+ NODE_MODULE_VERSION, \
175
+ 0 , \
176
+ NULL , \
177
+ __FILE__, \
178
+ (node::addon_register_func) (Nan::imp::addon_reg_func<regfunc>), \
179
+ NULL , \
180
+ NODE_STRINGIFY (modname), \
181
+ NULL , \
182
+ NULL \
183
+ }; \
184
+ NODE_C_CTOR (_register_ ## modname) { \
185
+ node_module_register (&_module); \
186
+ } \
187
+ }
141
188
#else
142
- typedef v8::Local<v8::Object> ADDON_REGISTER_FUNCTION_ARGS_TYPE;
189
+ # define NAN_MODULE NODE_MODULE
143
190
#endif
144
191
145
- #define NAN_MODULE_INIT (name ) \
146
- void name (Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target)
147
-
148
192
// === CallbackInfo =============================================================
149
193
150
194
#include " nan_callbacks.h" // NOLINT(build/include)
@@ -2171,7 +2215,7 @@ inline void SetCallAsFunctionHandler(
2171
2215
2172
2216
inline
2173
2217
void
2174
- Export (ADDON_REGISTER_FUNCTION_ARGS_TYPE target, const char *name,
2218
+ Export (v8::Local<v8::Object> target, const char *name,
2175
2219
FunctionCallback f) {
2176
2220
Set (target, New<v8::String>(name).ToLocalChecked (),
2177
2221
GetFunction (New<v8::FunctionTemplate>(f)).ToLocalChecked ());
0 commit comments