summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/src/Ice/browser/TimerUtil.js39
1 files changed, 21 insertions, 18 deletions
diff --git a/js/src/Ice/browser/TimerUtil.js b/js/src/Ice/browser/TimerUtil.js
index ae15429c771..d194b112a9a 100644
--- a/js/src/Ice/browser/TimerUtil.js
+++ b/js/src/Ice/browser/TimerUtil.js
@@ -16,18 +16,29 @@
var Ice = require("../Ice/ModuleRegistry").Ice;
-if(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
+//
+// Create a timer object that uses the default browser methods. Note that we also
+// have to use apply with null as the first argument to workaround an issue where
+// IE doesn't like these functions to be called with an unknown object (it reports
+// an "Invalid calling object" error).
+//
+function createTimerObject()
+{
+ var Timer = {};
+ Timer.setTimeout = function () { setTimeout.apply(null, arguments); }
+ Timer.clearTimeout = function () { clearTimeout.apply(null, arguments); };
+ Timer.setInterval = function () { setInterval.apply(null, arguments); };
+ Timer.clearInterval = function () { clearInterval.apply(null, arguments); };
+ Timer.setImmediate = function () { setImmediate.apply(null, arguments); }
+ return Timer;
+}
+
+if(typeof WorkerGlobalScope !== 'undefined' && this instanceof WorkerGlobalScope)
{
//
// If running in a worker we don't need to create a separate worker for the timers
//
- var Timer = {};
- Timer.setTimeout = setTimeout;
- Timer.clearTimeout = clearTimeout;
- Timer.setInterval = setInterval;
- Timer.clearInterval = clearInterval;
- Timer.setImmediate = setImmediate;
- Ice.Timer = Timer;
+ Ice.Timer = createTimerObject();
}
else
{
@@ -188,17 +199,9 @@ else
//
// Fallback on setInterval/setTimeout if the worker creating failed. Some IE10 and IE11 don't
- // support creating workers from blob URLs for instance. Note that we also have to use apply
- // with null as the first argument to workaround an issue where IE doesn't like these functions
- // to be called with an unknown object (it reports an "Invalid calling object" error).
+ // support creating workers from blob URLs for instance.
//
- var Timer = {};
- Timer.setTimeout = function () { setTimeout.apply(null, arguments); }
- Timer.clearTimeout = function () { clearTimeout.apply(null, arguments); };
- Timer.setInterval = function () { setInterval.apply(null, arguments); };
- Timer.clearInterval = function () { clearInterval.apply(null, arguments); };
- Timer.setImmediate = function () { setImmediate.apply(null, arguments); }
- Ice.Timer = Timer;
+ Ice.Timer = createTimerObject();
}
}
}