Skip to content

Commit

Permalink
[fix] Fix the enumerability of some properties
Browse files Browse the repository at this point in the history
Make the `CONNECTING`, `OPEN`, `CLOSING`, `CLOSED`, `binaryType`,
`bufferedAmount`, `extensions`, `onclose`, `onerror`, `onmessage`,
`onopen`, `protocol`, `readyState`, and `url` properties enumerable.
  • Loading branch information
lpinca committed Nov 7, 2020
1 parent eabed8f commit 2069e68
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/websocket.js
Expand Up @@ -74,19 +74,6 @@ class WebSocket extends EventEmitter {
}
}

get CONNECTING() {
return WebSocket.CONNECTING;
}
get CLOSING() {
return WebSocket.CLOSING;
}
get CLOSED() {
return WebSocket.CLOSED;
}
get OPEN() {
return WebSocket.OPEN;
}

/**
* This deviates from the WHATWG interface since ws doesn't support the
* required default "blob" type (instead we define a custom "nodebuffer"
Expand Down Expand Up @@ -394,10 +381,21 @@ class WebSocket extends EventEmitter {
}

readyStates.forEach((readyState, i) => {
Object.defineProperty(WebSocket, readyState, {
enumerable: true,
value: i
});
const descriptor = { enumerable: true, value: i };

Object.defineProperty(WebSocket.prototype, readyState, descriptor);
Object.defineProperty(WebSocket, readyState, descriptor);
});

[
'binaryType',
'bufferedAmount',
'extensions',
'protocol',
'readyState',
'url'
].forEach((property) => {
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
});

//
Expand All @@ -406,6 +404,8 @@ readyStates.forEach((readyState, i) => {
//
['open', 'error', 'close', 'message'].forEach((method) => {
Object.defineProperty(WebSocket.prototype, `on${method}`, {
configurable: true,
enumerable: true,
/**
* Return the listener of the event.
*
Expand Down

0 comments on commit 2069e68

Please sign in to comment.