From 704774d6d11df8c4cf1789ea43cffbed3e5e6b33 Mon Sep 17 00:00:00 2001 From: Evelyn Eastmond Date: Thu, 6 Jun 2019 16:41:05 -0400 Subject: [PATCH] Fixing debug statements and also adding a safety check for timeoutIDs. --- src/extensions/scratch3_boost/index.js | 2 +- src/extensions/scratch3_ev3/index.js | 8 +++++--- src/extensions/scratch3_gdx_for/index.js | 7 +++++-- src/extensions/scratch3_microbit/index.js | 5 ++++- src/io/ble.js | 5 +++-- src/io/bt.js | 5 +++-- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 217f3d8d1..53619656b 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -840,7 +840,7 @@ class Boost { */ reset () { console.log('BOOST RESET CALLED'); - + this._ports = []; this._motors = []; this._sensors = { diff --git a/src/extensions/scratch3_ev3/index.js b/src/extensions/scratch3_ev3/index.js index eb8636aa5..b77da5914 100644 --- a/src/extensions/scratch3_ev3/index.js +++ b/src/extensions/scratch3_ev3/index.js @@ -614,7 +614,7 @@ class EV3 { */ reset() { console.log('EV3 RESET CALLED'); - + this._sensorPorts = []; this._motorPorts = []; this._sensors = { @@ -624,8 +624,10 @@ class EV3 { }; this._motors = [null, null, null, null]; - window.clearInterval(this._pollingIntervalID); - this._pollingIntervalID = null; + if (this._pollingIntervalID) { + window.clearInterval(this._pollingIntervalID); + this._pollingIntervalID = null; + } } /** diff --git a/src/extensions/scratch3_gdx_for/index.js b/src/extensions/scratch3_gdx_for/index.js index e019b00b8..6410afd14 100644 --- a/src/extensions/scratch3_gdx_for/index.js +++ b/src/extensions/scratch3_gdx_for/index.js @@ -224,7 +224,7 @@ class GdxFor { */ reset () { console.log('GDXFOR RESET CALLED'); - + this._sensors = { force: 0, accelerationX: 0, @@ -235,7 +235,10 @@ class GdxFor { spinSpeedZ: 0 }; - window.clearInterval(this._timeoutID); + if (this._timeoutID) { + window.clearInterval(this._timeoutID); + this._timeoutID = null; + } } /** diff --git a/src/extensions/scratch3_microbit/index.js b/src/extensions/scratch3_microbit/index.js index 8074e5bf9..3a1ad2b67 100644 --- a/src/extensions/scratch3_microbit/index.js +++ b/src/extensions/scratch3_microbit/index.js @@ -254,7 +254,10 @@ class MicroBit { reset() { console.log('MICROBIT RESET CALLED'); - window.clearTimeout(this._timeoutID); + if (this._timeoutID) { + window.clearTimeout(this._timeoutID); + this._timeoutID = null; + } } /** diff --git a/src/io/ble.js b/src/io/ble.js index 9816b4b95..2a31b1f62 100644 --- a/src/io/ble.js +++ b/src/io/ble.js @@ -203,8 +203,9 @@ class BLE extends JSONRPC { * Disconnect the socket, and if the extension using this socket has a * reset callback, call it. Finally, emit an error to the runtime. */ - handleDisconnectError (/* e */) { - // log.error(`BLE error: ${JSON.stringify(e)}`); + handleDisconnectError (e) { + console.error(`BLE error: ${JSON.stringify(e)}`); + console.error(e); console.log('BLE HANDLEDISCONNECTERROR CALLED'); if (!this._connected) return; diff --git a/src/io/bt.js b/src/io/bt.js index 8727c2279..6dadbd681 100644 --- a/src/io/bt.js +++ b/src/io/bt.js @@ -149,8 +149,9 @@ class BT extends JSONRPC { * Disconnect the socket, and if the extension using this socket has a * reset callback, call it. Finally, emit an error to the runtime. */ - handleDisconnectError (/* e */) { - // log.error(`BT error: ${JSON.stringify(e)}`); + handleDisconnectError (e) { + console.error(`BT error: ${JSON.stringify(e)}`); + console.error(e); console.log('BT HANDLEDISCONNECTERROR CALLED'); if (!this._connected) return;