diff options
author | Benoit Foucher <benoit@zeroc.com> | 2018-03-26 10:40:36 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2018-03-26 10:40:36 +0200 |
commit | cb6203b1a3b1bed3a538e6a881d16e66cca2e0e8 (patch) | |
tree | 60ecc3ab03877d9cd9438da6135908c134d15147 /js/src/Ice/browser/TimerUtil.js | |
parent | Revert "Added temporary tracing to JS/timeout test" (diff) | |
download | ice-cb6203b1a3b1bed3a538e6a881d16e66cca2e0e8.tar.bz2 ice-cb6203b1a3b1bed3a538e6a881d16e66cca2e0e8.tar.xz ice-cb6203b1a3b1bed3a538e6a881d16e66cca2e0e8.zip |
Fixed issue where the timer wasn't using a WebWorker for browsers (ICE-8754)
Diffstat (limited to 'js/src/Ice/browser/TimerUtil.js')
-rw-r--r-- | js/src/Ice/browser/TimerUtil.js | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/js/src/Ice/browser/TimerUtil.js b/js/src/Ice/browser/TimerUtil.js index bf1061ea3f2..ace32433ab4 100644 --- a/js/src/Ice/browser/TimerUtil.js +++ b/js/src/Ice/browser/TimerUtil.js @@ -74,10 +74,9 @@ const _SetTimeoutType = 0, _ClearTimeoutType = 3, _ClearIntervalType = 4; -var worker; - -var _nextId = 0; +let worker; +let _nextId = 0; var nextId = function() { if(_nextId == MAX_SAFE_INTEGER) @@ -91,7 +90,7 @@ class Timer { static setTimeout(cb, ms) { - var id = nextId(); + const id = nextId(); _timers.set(id, cb); worker.postMessage({type: _SetTimeoutType, id: id, ms: ms}); return id; @@ -105,7 +104,7 @@ class Timer static setInterval(cb, ms) { - var id = nextId(); + const id = nextId(); _timers.set(id, cb); worker.postMessage({type: _SetIntervalType, id: id, ms: ms}); return id; @@ -119,7 +118,7 @@ class Timer static setImmediate(cb) { - var id = nextId(); + const id = nextId(); _timers.set(id, cb); worker.postMessage({type: _SetImmediateType, id: id}); return id; @@ -127,24 +126,19 @@ class Timer static onmessage(e) { - var cb; - if(e.data.type === _SetIntervalType) - { - cb = _timers.get(e.data.id); - } - else - { - cb = _timers.delete(e.data.id); - } - + const cb = _timers.get(e.data.id); if(cb !== undefined) { cb.call(); + if(e.data.type !== _SetIntervalType) + { + _timers.delete(e.data.id); + } } } } -var workerCode = function() +const workerCode = function() { return "(" + function() @@ -152,13 +146,13 @@ var workerCode = function() // // jshint worker: true // - var _wSetTimeoutType = 0, + const _wSetTimeoutType = 0, _wSetIntervalType = 1, _wSetImmediateType = 2, _wClearTimeoutType = 3, _wClearIntervalType = 4; - var timers = {}; + const timers = {}; self.onmessage = e => { @@ -192,7 +186,7 @@ var workerCode = function() }.toString() + "());"; }; -if(self == this) +if(typeof(WorkerGlobalScope) !== 'undefined' && this instanceof WorkerGlobalScope) { // // If we are running in a worker don't spawn a separate worker for the timer |