Skip to content

Commit bd41a05

Browse files
Tom Atkinsonlpinca
authored andcommitted
[fix] Use Object.assign() for send() options (#968)
This avoids mutating the passed in arguments.
1 parent 7bec220 commit bd41a05

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/WebSocket.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,18 @@ class WebSocket extends EventEmitter {
355355
if (typeof data === 'number') data = data.toString();
356356
else if (!data) data = '';
357357

358-
options = options || {};
359-
if (options.fin !== false) options.fin = true;
360-
if (options.binary === undefined) options.binary = typeof data !== 'string';
361-
if (options.mask === undefined) options.mask = !this._isServer;
362-
if (options.compress === undefined) options.compress = true;
358+
const opts = Object.assign({
359+
fin: true,
360+
binary: typeof data !== 'string',
361+
mask: !this._isServer,
362+
compress: true
363+
}, options);
364+
363365
if (!this.extensions[PerMessageDeflate.extensionName]) {
364-
options.compress = false;
366+
opts.compress = false;
365367
}
366368

367-
this._sender.send(data, options, cb);
369+
this._sender.send(data, opts, cb);
368370
}
369371

370372
/**

0 commit comments

Comments
 (0)