Fix references to window

This commit is contained in:
Tim Mickel 2016-06-21 14:29:40 -04:00
parent 28432b6f01
commit 652cc8a31c
2 changed files with 22 additions and 9 deletions
src/engine

View file

@ -210,10 +210,6 @@ Runtime.prototype.stopAll = function () {
// Actually remove the thread.
this._removeThread(poppedThread);
}
// @todo call stop function in all extensions/packages/WeDo stub
if (window.native) {
window.native.motorStop();
}
};
/**
@ -243,12 +239,29 @@ Runtime.prototype.glowBlock = function (blockId, isGlowing) {
}
};
/**
* setInterval implementation that works in a WebWorker or not.
* @param {?Function} fcn Function to call.
* @param {number} interval Interval at which to call it.
* @return {number} Value returned by setInterval.
*/
Runtime.prototype._setInterval = function(fcn, interval) {
var setInterval = null;
if (typeof window !== 'undefined' && window.setInterval) {
setInterval = window.setInterval;
} else if (typeof self !== 'undefined' && self.setInterval) {
setInterval = self.setInterval;
} else {
return;
}
return setInterval(fcn, interval);
};
/**
* Set up timers to repeatedly step in a browser
*/
Runtime.prototype.start = function () {
if (!window.setInterval) return;
window.setInterval(function() {
this._setInterval(function() {
this._step();
}.bind(this), Runtime.THREAD_STEP_INTERVAL);
};