Skip to content

Commit ca4c6d4

Browse files
committed
Fix things that node-usb#48 (NAN) broke
1 parent 957984c commit ca4c6d4

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/device.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Device::~Device(){
2424
}
2525

2626
// Map pinning each libusb_device to a particular V8 instance
27-
std::map<libusb_device*, Handle<Value> > Device::byPtr;
27+
std::map<libusb_device*, _NanWeakCallbackInfo<Value, libusb_device>*> Device::byPtr;
2828

2929
NAN_WEAK_CALLBACK(DeviceWeakCallback) {
3030
Device::unpin(data.GetParameter());
@@ -35,12 +35,12 @@ NAN_WEAK_CALLBACK(DeviceWeakCallback) {
3535
Handle<Value> Device::get(libusb_device* dev){
3636
auto it = byPtr.find(dev);
3737
if (it != byPtr.end()){
38-
return NanNew(it->second);
38+
return NanNew(it->second->persistent);
3939
}else{
4040
Handle<Value> v = pDevice.create(new Device(dev));
41-
NanMakeWeakPersistent(v, dev, DeviceWeakCallback);
42-
byPtr.insert(std::make_pair(dev, v));
43-
return v;
41+
auto p = NanMakeWeakPersistent(v, dev, DeviceWeakCallback);
42+
byPtr.insert(std::make_pair(dev, p));
43+
return v;
4444
}
4545
}
4646

src/node_usb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct Device: public node::ObjectWrap {
3838
static void unpin(libusb_device* device);
3939

4040
protected:
41-
static std::map<libusb_device*, Handle<Value> > byPtr;
41+
static std::map<libusb_device*, _NanWeakCallbackInfo<Value, libusb_device>*> byPtr;
4242
Device(libusb_device* d);
4343
};
4444

@@ -63,14 +63,14 @@ extern Proto<Transfer> pTransfer;
6363

6464
#define CHECK_USB(r) \
6565
if (r < LIBUSB_SUCCESS) { \
66-
NanThrowError(libusbException(r)); \
66+
return NanThrowError(libusbException(r)); \
6767
}
6868

6969
#define CALLBACK_ARG(CALLBACK_ARG_IDX) \
7070
Local<Function> callback; \
7171
if (args.Length() > (CALLBACK_ARG_IDX)) { \
7272
if (!args[CALLBACK_ARG_IDX]->IsFunction()) { \
73-
NanThrowTypeError("Argument " #CALLBACK_ARG_IDX " must be a function"); \
73+
return NanThrowTypeError("Argument " #CALLBACK_ARG_IDX " must be a function"); \
7474
} \
7575
callback = Local<Function>::Cast(args[CALLBACK_ARG_IDX]); \
7676
} \

src/protobuilder.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ using namespace v8;
88
#define V8STR(str) NanNew<String>(str)
99
#define V8SYM(str) NanNew<String>(str)
1010

11-
#define THROW_BAD_ARGS(FAIL_MSG) NanThrowError(FAIL_MSG);
12-
#define THROW_ERROR(FAIL_MSG) NanThrowTypeError(FAIL_MSG);
13-
#define CHECK_N_ARGS(MIN_ARGS) if (args.Length() < MIN_ARGS) THROW_BAD_ARGS("Expected " #MIN_ARGS " arguments")
11+
#define THROW_BAD_ARGS(FAIL_MSG) return NanThrowTypeError(FAIL_MSG);
12+
#define THROW_ERROR(FAIL_MSG) return NanThrowError(FAIL_MSG);
13+
#define CHECK_N_ARGS(MIN_ARGS) if (args.Length() < MIN_ARGS) { THROW_BAD_ARGS("Expected " #MIN_ARGS " arguments") }
1414

1515
const PropertyAttribute CONST_PROP = static_cast<PropertyAttribute>(ReadOnly|DontDelete);
1616

@@ -116,13 +116,13 @@ inline static void setConst(Handle<Object> obj, const char* const name, Handle<V
116116

117117
#define ENTER_CONSTRUCTOR(MIN_ARGS) \
118118
NanScope(); \
119-
if (!args.IsConstructCall()) THROW_ERROR("Must be called with `new`!"); \
119+
if (!args.IsConstructCall()) return NanThrowError("Must be called with `new`!"); \
120120
CHECK_N_ARGS(MIN_ARGS);
121121

122122
#define ENTER_CONSTRUCTOR_POINTER(PROTO, MIN_ARGS) \
123123
ENTER_CONSTRUCTOR(MIN_ARGS) \
124124
if (!args.Length() || !args[0]->IsExternal()){ \
125-
THROW_BAD_ARGS("This type cannot be created directly!"); \
125+
return NanThrowError("This type cannot be created directly!"); \
126126
} \
127127
auto self = (PROTO)._wrap(args.This(), args[0]); \
128128
(void) self

0 commit comments

Comments
 (0)