diff options
author | Jose <jose@zeroc.com> | 2018-11-06 22:07:44 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2018-11-06 22:07:44 +0100 |
commit | f4a2c8793385f59857fcd78ff9fd1dc5c5da6cb9 (patch) | |
tree | b5a2f7164d21751f3e5ff65d0d5b48f63b45782e /js/src | |
parent | Remove unused IceSSL Util class (diff) | |
download | ice-f4a2c8793385f59857fcd78ff9fd1dc5c5da6cb9.tar.bz2 ice-f4a2c8793385f59857fcd78ff9fd1dc5c5da6cb9.tar.xz ice-f4a2c8793385f59857fcd78ff9fd1dc5c5da6cb9.zip |
Fix for NodeJs deprecation warnings
Close #282
Diffstat (limited to 'js/src')
-rw-r--r-- | js/src/Ice/TcpTransceiver.js | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/js/src/Ice/TcpTransceiver.js b/js/src/Ice/TcpTransceiver.js index 9ce88207d89..0967cbe3a1e 100644 --- a/js/src/Ice/TcpTransceiver.js +++ b/js/src/Ice/TcpTransceiver.js @@ -29,6 +29,28 @@ const StateProxyConnectRequest = 2; const StateProxyConnectRequestPending = 3; const StateConnected = 4; +// +// XXX: We can directly use Buffer.from once we drop +// support for Node 4.x +// +// +if(Buffer.from) +{ + function createBuffer(data) + { + return Buffer.from(data); + } +} +else +{ + /* eslint-disable no-buffer-constructor */ + function createBuffer(data) + { + return new Buffer(data); + } + /* eslint-enable no-buffer-constructor */ +} + class TcpTransceiver { constructor(instance) @@ -188,20 +210,13 @@ class TcpTransceiver const slice = byteBuffer.b.slice(byteBuffer.position, byteBuffer.position + packetSize); let sync = true; - // - // XXX: diasble for compatibility with Node 4.x replace by - // Buffer.from when we drop support to Node 4.x - // - - /* eslint-disable no-buffer-constructor */ - sync = this._fd.write(new Buffer(slice), null, () => + sync = this._fd.write(createBuffer(slice), null, () => { if(!sync) { this._bytesWrittenCallback(); } }); - /* eslint-enable no-buffer-constructor */ byteBuffer.position += packetSize; if(!sync) @@ -245,15 +260,8 @@ class TcpTransceiver avail = byteBuffer.remaining; } - // - // XXX: diasble for compatibility with Node 4.x replace by - // Buffer.from when we drop support to Node 4.x - // - - /* eslint-disable no-buffer-constructor */ - this._readBuffers[0].copy(new Buffer(byteBuffer.b), byteBuffer.position, this._readPosition, + this._readBuffers[0].copy(createBuffer(byteBuffer.b), byteBuffer.position, this._readPosition, this._readPosition + avail); - /* eslint-enable no-buffer-constructor */ byteBuffer.position += avail; this._readPosition += avail; |