diff options
author | Jose <jose@zeroc.com> | 2018-03-27 14:59:44 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2018-03-27 14:59:44 +0200 |
commit | 50c89b62292e9af17c0e55430805ea1dba1b2b97 (patch) | |
tree | e03433b24f57e9effca21c1bfdf0690f5cb841ae | |
parent | JavaScript ESLINT prefer arrow callbacks (diff) | |
download | ice-50c89b62292e9af17c0e55430805ea1dba1b2b97.tar.bz2 ice-50c89b62292e9af17c0e55430805ea1dba1b2b97.tar.xz ice-50c89b62292e9af17c0e55430805ea1dba1b2b97.zip |
JavaScript ESLINT no var usage, prefer let and const
https://eslint.org/docs/rules/no-var
-rw-r--r-- | js/src/Ice/Buffer.js | 37 | ||||
-rw-r--r-- | js/src/Ice/StringUtil.js | 4 | ||||
-rw-r--r-- | js/src/Ice/browser/ModuleRegistry.js | 8 | ||||
-rw-r--r-- | js/src/Ice/browser/TimerUtil.js | 8 | ||||
-rw-r--r-- | js/src/Ice/browser/WSTransceiver.js | 55 |
5 files changed, 53 insertions, 59 deletions
diff --git a/js/src/Ice/Buffer.js b/js/src/Ice/Buffer.js index 03166d0e60a..7af36f0e6ef 100644 --- a/js/src/Ice/Buffer.js +++ b/js/src/Ice/Buffer.js @@ -71,7 +71,7 @@ class Buffer // expand(n) { - var sz = this.capacity === 0 ? n : this._position + n; + const sz = this.capacity === 0 ? n : this._position + n; if(sz > this._limit) { this.resize(sz); @@ -106,15 +106,14 @@ class Buffer { if(n > this.capacity) { - var capacity = Math.max(n, 2 * this.capacity); - capacity = Math.max(1024, capacity); + const capacity = Math.max(1024, Math.max(n, 2 * this.capacity)); if(!this.b) { this.b = new ArrayBuffer(capacity); } else { - var b = new Uint8Array(capacity); + const b = new Uint8Array(capacity); b.set(new Uint8Array(this.b)); this.b = b.buffer; } @@ -125,10 +124,6 @@ class Buffer this.b = this.b.slice(0, this.capacity); this.v = new DataView(this.b); } - else - { - return; - } } put(v) @@ -234,7 +229,7 @@ class Buffer // // Encode the string as utf8 // - var encoded = unescape(encodeURIComponent(v)); + const encoded = unescape(encodeURIComponent(v)); stream.writeSize(encoded.length); stream.expand(encoded.length); @@ -247,7 +242,7 @@ class Buffer { throw new Error(bufferOverflowExceptionMsg); } - for(var i = 0; i < sz; ++i) + for(let i = 0; i < sz; ++i) { this.v.setUint8(this._position, v.charCodeAt(i)); this._position++; @@ -260,7 +255,7 @@ class Buffer { throw new Error(bufferUnderflowExceptionMsg); } - var v = this.v.getUint8(this._position); + const v = this.v.getUint8(this._position); this._position++; return v; } @@ -280,7 +275,7 @@ class Buffer { throw new Error(bufferUnderflowExceptionMsg); } - var buffer = this.b.slice(this._position, this._position + length); + const buffer = this.b.slice(this._position, this._position + length); this._position += length; return new Uint8Array(buffer); } @@ -301,7 +296,7 @@ class Buffer { throw new Error(bufferUnderflowExceptionMsg); } - var v = this.v.getInt16(this._position, true); + const v = this.v.getInt16(this._position, true); this._position += 2; return v; } @@ -312,7 +307,7 @@ class Buffer { throw new Error(bufferUnderflowExceptionMsg); } - var v = this.v.getInt32(this._position, true); + const v = this.v.getInt32(this._position, true); this._position += 4; return v; } @@ -323,7 +318,7 @@ class Buffer { throw new Error(bufferUnderflowExceptionMsg); } - var v = this.v.getFloat32(this._position, true); + const v = this.v.getFloat32(this._position, true); this._position += 4; return v; } @@ -334,7 +329,7 @@ class Buffer { throw new Error(bufferUnderflowExceptionMsg); } - var v = this.v.getFloat64(this._position, true); + const v = this.v.getFloat64(this._position, true); this._position += 8; return v; } @@ -360,16 +355,14 @@ class Buffer throw new Error(bufferUnderflowExceptionMsg); } - var data = new DataView(this.b, this._position, length); - var s = ""; - - for(var i = 0; i < length; ++i) + const data = new DataView(this.b, this._position, length); + let s = ""; + for(let i = 0; i < length; ++i) { s += String.fromCharCode(data.getUint8(i)); } this._position += length; - s = decodeURIComponent(escape(s)); - return s; + return decodeURIComponent(escape(s)); } get position() diff --git a/js/src/Ice/StringUtil.js b/js/src/Ice/StringUtil.js index 2d7ae9ac64f..b9edaacd970 100644 --- a/js/src/Ice/StringUtil.js +++ b/js/src/Ice/StringUtil.js @@ -70,7 +70,7 @@ Ice.StringUtil = class if(toStringMode === Ice.ToStringMode.Compat) { // Encode UTF-8 bytes - var bytes = unescape(encodeURIComponent(s)); + const bytes = unescape(encodeURIComponent(s)); for(let i = 0; i < bytes.length; ++i) { const c = bytes.charCodeAt(i); @@ -340,7 +340,7 @@ function encodeChar(c, sb, special, toStringMode) } default: { - var s = String.fromCharCode(c); + const s = String.fromCharCode(c); if(special !== null && special.indexOf(s) !== -1) { diff --git a/js/src/Ice/browser/ModuleRegistry.js b/js/src/Ice/browser/ModuleRegistry.js index 87bdca8454f..514e6115d57 100644 --- a/js/src/Ice/browser/ModuleRegistry.js +++ b/js/src/Ice/browser/ModuleRegistry.js @@ -21,7 +21,7 @@ class _ModuleRegistry { static module(name) { - var m = root[name]; + let m = root[name]; if(m === undefined) { m = {}; @@ -41,10 +41,10 @@ class _ModuleRegistry { return undefined; } - var components = scoped.split("."); - var T = root; + const components = scoped.split("."); + let T = root; - for(var i = 0, length = components.length; i < length; ++i) + for(let i = 0, length = components.length; i < length; ++i) { T = T[components[i]]; if(T === undefined) diff --git a/js/src/Ice/browser/TimerUtil.js b/js/src/Ice/browser/TimerUtil.js index f34b1c35010..90317ec92d5 100644 --- a/js/src/Ice/browser/TimerUtil.js +++ b/js/src/Ice/browser/TimerUtil.js @@ -195,7 +195,7 @@ if(typeof(WorkerGlobalScope) !== 'undefined' && this instanceof WorkerGlobalScop } else if(worker === undefined) { - var url; + let url; try { url = URL.createObjectURL(new Blob([workerCode()], {type : 'text/javascript'})); @@ -205,8 +205,10 @@ else if(worker === undefined) } catch(ex) { - URL.revokeObjectURL(url); - + if(url !== undefined) + { + URL.revokeObjectURL(url); + } // // Fallback on setInterval/setTimeout if the worker creating failed. Some IE10 and IE11 don't // support creating workers from blob URLs for instance. diff --git a/js/src/Ice/browser/WSTransceiver.js b/js/src/Ice/browser/WSTransceiver.js index b80c16318e2..5ecee521186 100644 --- a/js/src/Ice/browser/WSTransceiver.js +++ b/js/src/Ice/browser/WSTransceiver.js @@ -51,7 +51,7 @@ class WSTransceiver writeReadyTimeout() { - var t = Math.round(this._writeReadyTimeout); + const t = Math.round(this._writeReadyTimeout); this._writeReadyTimeout += (this._writeReadyTimeout >= 5 ? 5 : 0.2); return Math.min(t, 25); } @@ -183,26 +183,27 @@ class WSTransceiver } Debug.assert(this._fd); - var transceiver = this; - var cb = function() - { - if(transceiver._fd) - { - if(transceiver._fd.bufferedAmount + packetSize <= transceiver._maxSendPacketSize) - { - transceiver._bytesWrittenCallback(0, 0); - } - else - { - Timer.setTimeout(cb, transceiver.writeReadyTimeout()); - } - } - }; + const cb = () => + { + if(this._fd) + { + const packetSize = this._maxSendPacketSize > 0 && byteBuffer.remaining > this._maxSendPacketSize ? + this._maxSendPacketSize : byteBuffer.remaining; + if(this._fd.bufferedAmount + packetSize <= this._maxSendPacketSize) + { + this._bytesWrittenCallback(0, 0); + } + else + { + Timer.setTimeout(cb, this.writeReadyTimeout()); + } + } + }; while(true) { - var packetSize = (this._maxSendPacketSize > 0 && byteBuffer.remaining > this._maxSendPacketSize) ? - this._maxSendPacketSize : byteBuffer.remaining; + const packetSize = this._maxSendPacketSize > 0 && byteBuffer.remaining > this._maxSendPacketSize ? + this._maxSendPacketSize : byteBuffer.remaining; if(byteBuffer.remaining === 0) { break; @@ -214,9 +215,9 @@ class WSTransceiver return false; } this._writeReadyTimeout = 0; - var slice = byteBuffer.b.slice(byteBuffer.position, byteBuffer.position + packetSize); + const slice = byteBuffer.b.slice(byteBuffer.position, byteBuffer.position + packetSize); this._fd.send(slice); - byteBuffer.position = byteBuffer.position + packetSize; + byteBuffer.position += packetSize; // // TODO: WORKAROUND for Safari issue. The websocket accepts all the @@ -246,7 +247,7 @@ class WSTransceiver return false; // No data available. } - var avail = this._readBuffers[0].byteLength - this._readPosition; + let avail = this._readBuffers[0].byteLength - this._readPosition; Debug.assert(avail > 0); while(byteBuffer.remaining > 0) @@ -257,7 +258,7 @@ class WSTransceiver } new Uint8Array(byteBuffer.b).set(new Uint8Array(this._readBuffers[0], this._readPosition, avail), - byteBuffer.position); + byteBuffer.position); byteBuffer.position += avail; this._readPosition += avail; @@ -292,8 +293,8 @@ class WSTransceiver getInfo() { Debug.assert(this._fd !== null); - var info = new Ice.WSConnectionInfo(); - var tcpinfo = new Ice.TCPConnectionInfo(); + const info = new Ice.WSConnectionInfo(); + const tcpinfo = new Ice.TCPConnectionInfo(); tcpinfo.localAddress = ""; tcpinfo.localPort = -1; tcpinfo.remoteAddress = this._addr.host; @@ -369,9 +370,8 @@ class WSTransceiver static createOutgoing(instance, secure, addr, resource) { - var transceiver = new WSTransceiver(instance); - - var url = secure ? "wss" : "ws"; + const transceiver = new WSTransceiver(instance); + let url = secure ? "wss" : "ws"; url += "://" + addr.host; if(addr.port !== 80) { @@ -385,7 +385,6 @@ class WSTransceiver transceiver._state = StateNeedConnect; transceiver._secure = secure; transceiver._exception = null; - return transceiver; } } |