@@ -136,15 +136,77 @@ namespace Nan {
136136
137137// === RegistrationFunction =====================================================
138138
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_10_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+ Nan::imp::addon_reg_func<regfunc>, \
156+ NODE_STRINGIFY (modname) \
157+ }; \
158+ }
159+
160+ #elif NODE_MODULE_VERSION < NODE_0_12_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::HandleScope scope;
165+ F (v8::Local<v8::Object>::New (target));
166+ }
167+ }
168+
169+ # define NAN_MODULE (modname, regfunc ) \
170+ extern " C" { \
171+ NODE_MODULE_EXPORT node::node_module_struct modname ## _module = \
172+ { \
173+ NODE_STANDARD_MODULE_STUFF, \
174+ (node::addon_register_func) Nan::imp::addon_reg_func<regfunc>, \
175+ NODE_STRINGIFY (modname) \
176+ }; \
177+ }
178+ #elif NODE_MODULE_VERSION < IOJS_3_0_MODULE_VERSION
179+ namespace imp {
180+ template <addon_reg_func_t F>
181+ static inline void addon_reg_func (v8::Handle<v8::Object> target) {
182+ v8::Isolate *isolate = v8::Isolate::GetCurrent ();
183+ v8::HandleScope scope (isolate);
184+ F (v8::Local<v8::Object>::New (isolate, target));
185+ }
186+ }
187+
188+ # define NAN_MODULE (modname, regfunc ) \
189+ extern " C" { \
190+ static node::node_module _module = \
191+ { \
192+ NODE_MODULE_VERSION, \
193+ 0 , \
194+ NULL , \
195+ __FILE__, \
196+ (node::addon_register_func) (Nan::imp::addon_reg_func<regfunc>), \
197+ NULL , \
198+ NODE_STRINGIFY (modname), \
199+ NULL , \
200+ NULL \
201+ }; \
202+ NODE_C_CTOR (_register_ ## modname) { \
203+ node_module_register (&_module); \
204+ } \
205+ }
141206#else
142- typedef v8::Local<v8::Object> ADDON_REGISTER_FUNCTION_ARGS_TYPE;
207+ # define NAN_MODULE NODE_MODULE
143208#endif
144209
145- #define NAN_MODULE_INIT (name ) \
146- void name (Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target)
147-
148210// === CallbackInfo =============================================================
149211
150212#include " nan_callbacks.h" // NOLINT(build/include)
@@ -2171,7 +2233,7 @@ inline void SetCallAsFunctionHandler(
21712233
21722234inline
21732235void
2174- Export (ADDON_REGISTER_FUNCTION_ARGS_TYPE target, const char *name,
2236+ Export (v8::Local<v8::Object> target, const char *name,
21752237 FunctionCallback f) {
21762238 Set (target, New<v8::String>(name).ToLocalChecked (),
21772239 GetFunction (New<v8::FunctionTemplate>(f)).ToLocalChecked ());
0 commit comments