@@ -6,14 +6,16 @@ using namespace NodeUsb;
66
77UVQueue<Transfer*> Transfer::completionQueue (Transfer::handleCompletion);
88
9- Transfer::Transfer (Handle<Object> _device, Handle<Function> _callback):
9+ Transfer::Transfer (Handle<Object> _device, Handle<Object> _v8this, Handle< Function> _callback):
1010 v8device(Persistent<Object>::New(_device)),
11+ v8this(Persistent<Object>::New(_v8this)),
1112 v8callback(Persistent<Function>::New(_callback)),
1213 device(ObjectWrap::Unwrap<Device>(_device)){
1314 transfer = libusb_alloc_transfer (0 );
1415}
1516
1617Transfer::~Transfer (){
18+ v8this.Dispose ();
1719 v8device.Dispose ();
1820 v8callback.Dispose ();
1921 free (transfer->buffer );
@@ -31,7 +33,7 @@ Transfer* Transfer::newControlTransfer(Handle<Object> device,
3133 uint16_t wLength,
3234 unsigned timeout,
3335 Handle<Function> callback){
34- Transfer *t = new Transfer (device, callback);
36+ Transfer *t = new Transfer (device, device, callback);
3537
3638 uint8_t *buffer = (uint8_t *) malloc (LIBUSB_CONTROL_SETUP_SIZE+wLength);
3739 libusb_fill_control_setup (buffer, bmRequestType, bRequest, wValue, wIndex, wLength);
@@ -44,12 +46,13 @@ Transfer* Transfer::newControlTransfer(Handle<Object> device,
4446
4547Transfer* Transfer::newTransfer (libusb_transfer_type type,
4648 Handle<Object> device,
49+ Handle<Object> v8endpoint,
4750 uint8_t endpoint,
4851 unsigned char *data,
4952 int length,
5053 unsigned int timeout,
5154 Handle<Function> callback){
52- Transfer *t = new Transfer (device, callback);
55+ Transfer *t = new Transfer (device, v8endpoint, callback);
5356 uint8_t *buffer = (uint8_t *) malloc (length);
5457 if (data) memcpy (buffer, data, length);
5558 t->direction = data?LIBUSB_ENDPOINT_OUT:LIBUSB_ENDPOINT_IN;
@@ -80,7 +83,7 @@ void Transfer::handleCompletion(Transfer* t){
8083 }
8184 }
8285
83- doTransferCallback (t->v8callback , Context::GetCurrent ()-> Global () , t->transfer ->status , buffer, length);
86+ doTransferCallback (t->v8callback , t-> v8this , t->transfer ->status , buffer, length);
8487
8588 uv_unref (uv_default_loop ());
8689 delete t;
0 commit comments