Skip to content

Commit

Permalink
Safe check for undefined interfaceNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
thegecko committed Jul 5, 2019
1 parent 72ee8c3 commit 7246206
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/transport/usb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export class USB implements Transport {
*/
public read(): Promise<DataView> {
return new Promise((resolve, reject) => {
if (!this.interfaceNumber) return reject("No device opened");
if (this.interfaceNumber === undefined) return reject("No device opened");

// Use endpoint if it exists
if (this.endpointIn) {
Expand Down Expand Up @@ -225,7 +225,7 @@ export class USB implements Transport {
const buffer = this.bufferSourceToBuffer(extended);

return new Promise((resolve, reject) => {
if (!this.interfaceNumber) return reject("No device opened");
if (this.interfaceNumber === undefined) return reject("No device opened");

// Use endpoint if it exists
if (this.endpointOut) {
Expand Down
4 changes: 2 additions & 2 deletions src/transport/webusb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class WebUSB implements Transport {
* @returns Promise of DataView
*/
public read(): Promise<DataView> {
if (!this.interfaceNumber) return Promise.reject("No device opened");
if (this.interfaceNumber === undefined) return Promise.reject("No device opened");

// Use endpoint if it exists
if (this.endpointIn) {
Expand Down Expand Up @@ -171,7 +171,7 @@ export class WebUSB implements Transport {
* @returns Promise
*/
public write(data: BufferSource): Promise<void> {
if (!this.interfaceNumber) return Promise.reject("No device opened");
if (this.interfaceNumber === undefined) return Promise.reject("No device opened");

const buffer = this.extendBuffer(data, this.packetSize);

Expand Down

0 comments on commit 7246206

Please sign in to comment.