Skip to content

Commit 01ea299

Browse files
committed
Removed NAN_MODULE_INIT and added NAN_MODULE
1 parent 522aa35 commit 01ea299

36 files changed

+129
-85
lines changed

nan.h

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,59 @@ 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_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+
}
141188
#else
142-
typedef v8::Local<v8::Object> ADDON_REGISTER_FUNCTION_ARGS_TYPE;
189+
# define NAN_MODULE NODE_MODULE
143190
#endif
144191

145-
#define NAN_MODULE_INIT(name) \
146-
void name(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target)
147-
148192
//=== CallbackInfo =============================================================
149193

150194
#include "nan_callbacks.h" // NOLINT(build/include)
@@ -2171,7 +2215,7 @@ inline void SetCallAsFunctionHandler(
21712215

21722216
inline
21732217
void
2174-
Export(ADDON_REGISTER_FUNCTION_ARGS_TYPE target, const char *name,
2218+
Export(v8::Local<v8::Object> target, const char *name,
21752219
FunctionCallback f) {
21762220
Set(target, New<v8::String>(name).ToLocalChecked(),
21772221
GetFunction(New<v8::FunctionTemplate>(f)).ToLocalChecked());

test/cpp/accessors.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace Nan; // NOLINT(build/namespaces)
1313

1414
class SetterGetter : public ObjectWrap {
1515
public:
16-
static NAN_MODULE_INIT(Init);
16+
static void Init(v8::Local<v8::Object> target);
1717
static v8::Local<v8::Value> NewInstance ();
1818
static NAN_METHOD(New);
1919
static NAN_METHOD(Log);
@@ -41,7 +41,7 @@ SetterGetter::SetterGetter() {
4141
prop2[0] = '\0';
4242
}
4343

44-
NAN_MODULE_INIT(SetterGetter::Init) {
44+
void SetterGetter::Init(v8::Local<v8::Object> target) {
4545
v8::Local<v8::FunctionTemplate> tpl =
4646
Nan::New<v8::FunctionTemplate>(SetterGetter::New);
4747
settergetter_constructor.Reset(tpl);
@@ -162,4 +162,4 @@ NAN_METHOD(SetterGetter::Log) {
162162
info.GetReturnValue().Set(Nan::New(settergetter->log).ToLocalChecked());
163163
}
164164

165-
NODE_MODULE(accessors, SetterGetter::Init)
165+
NAN_MODULE(accessors, SetterGetter::Init)

test/cpp/accessors2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace Nan; // NOLINT(build/namespaces)
1313

1414
class SetterGetter : public ObjectWrap {
1515
public:
16-
static NAN_MODULE_INIT(Init);
16+
static void Init(v8::Local<v8::Object> target);
1717
static v8::Local<v8::Value> NewInstance ();
1818
static NAN_METHOD(New);
1919
static NAN_METHOD(Log);
@@ -41,7 +41,7 @@ SetterGetter::SetterGetter() {
4141
prop2[0] = '\0';
4242
}
4343

44-
NAN_MODULE_INIT(SetterGetter::Init) {
44+
void SetterGetter::Init(v8::Local<v8::Object> target) {
4545
v8::Local<v8::FunctionTemplate> tpl =
4646
Nan::New<v8::FunctionTemplate>(SetterGetter::New);
4747
settergetter_constructor.Reset(tpl);
@@ -160,4 +160,4 @@ NAN_METHOD(SetterGetter::Log) {
160160
info.GetReturnValue().Set(Nan::New(settergetter->log).ToLocalChecked());
161161
}
162162

163-
NODE_MODULE(accessors2, SetterGetter::Init)
163+
NAN_MODULE(accessors2, SetterGetter::Init)

test/cpp/asyncprogressworker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ NAN_METHOD(DoProgress) {
5757
, To<uint32_t>(info[1]).FromJust()));
5858
}
5959

60-
NAN_MODULE_INIT(Init) {
60+
void Init(v8::Local<v8::Object> target) {
6161
Set(target
6262
, New<v8::String>("a").ToLocalChecked()
6363
, New<v8::FunctionTemplate>(DoProgress)->GetFunction());
6464
}
6565

66-
NODE_MODULE(asyncprogressworker, Init)
66+
NAN_MODULE(asyncprogressworker, Init)

test/cpp/asyncworker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ NAN_METHOD(DoSleep) {
3434
new SleepWorker(callback, To<uint32_t>(info[0]).FromJust()));
3535
}
3636

37-
NAN_MODULE_INIT(Init) {
37+
void Init(v8::Local<v8::Object> target) {
3838
Set(target
3939
, New<v8::String>("a").ToLocalChecked()
4040
, New<v8::FunctionTemplate>(DoSleep)->GetFunction());
4141
}
4242

43-
NODE_MODULE(asyncworker, Init)
43+
NAN_MODULE(asyncworker, Init)

test/cpp/asyncworkererror.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ NAN_METHOD(Work) {
2626
info.GetReturnValue().SetUndefined();
2727
}
2828

29-
NAN_MODULE_INIT(Init) {
29+
void Init(v8::Local<v8::Object> target) {
3030
Set(target
3131
, New("a").ToLocalChecked()
3232
, New<v8::FunctionTemplate>(Work)->GetFunction());
3333
}
3434

35-
NODE_MODULE(asyncworkererror, Init)
35+
NAN_MODULE(asyncworkererror, Init)

test/cpp/buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ NAN_METHOD(Copy) {
5050
}
5151

5252

53-
NAN_MODULE_INIT(Init) {
53+
void Init(v8::Local<v8::Object> target) {
5454
for (unsigned char i = 0; i < DATA_SIZE; i++) {
5555
data[i] = 'a' + i;
5656
}
@@ -72,4 +72,4 @@ NAN_MODULE_INIT(Init) {
7272
);
7373
}
7474

75-
NODE_MODULE(buffer, Init)
75+
NAN_MODULE(buffer, Init)

test/cpp/bufferworkerpersistent.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ NAN_METHOD(DoSleep) {
6060
, bufferHandle));
6161
}
6262

63-
NAN_MODULE_INIT(Init) {
63+
void Init(v8::Local<v8::Object> target) {
6464
Set(target
6565
, New<v8::String>("a").ToLocalChecked()
6666
, New<v8::FunctionTemplate>(DoSleep)->GetFunction());
6767
}
6868

69-
NODE_MODULE(bufferworkerpersistent, Init)
69+
NAN_MODULE(bufferworkerpersistent, Init)

test/cpp/converters.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ NAN_METHOD(Int32Value) {
6868
info.GetReturnValue().Set(New(To<int32_t>(info[0]).FromJust()));
6969
}
7070

71-
NAN_MODULE_INIT(Init) {
71+
void Init(v8::Local<v8::Object> target) {
7272
Set(target
7373
, New<v8::String>("toBoolean").ToLocalChecked()
7474
, New<v8::FunctionTemplate>(ToBoolean)->GetFunction()
@@ -127,4 +127,4 @@ NAN_MODULE_INIT(Init) {
127127
);
128128
}
129129

130-
NODE_MODULE(converters, Init)
130+
NAN_MODULE(converters, Init)

test/cpp/error.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ X(TypeError)
4848
, Nan::New<v8::FunctionTemplate>(NAME)->GetFunction());
4949

5050

51-
NAN_MODULE_INIT(Init) {
51+
void Init(v8::Local<v8::Object> target) {
5252
EXPORT_ERROR_FUNCTIONS(Error)
5353
EXPORT_ERROR_FUNCTIONS(RangeError)
5454
EXPORT_ERROR_FUNCTIONS(ReferenceError)
@@ -59,4 +59,4 @@ NAN_MODULE_INIT(Init) {
5959
#undef EXPORT_ERROR_FUNCTIONS
6060
#undef X
6161

62-
NODE_MODULE(error, Init)
62+
NAN_MODULE(error, Init)

0 commit comments

Comments
 (0)