Skip to content

Commit cd3ba75

Browse files
author
harbaum
committed
Attempt to fix scratch3 hat
1 parent 45d666b commit cd3ba75

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

webusb/scratch3/lib.min.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268246,7 +268246,8 @@ function () {
268246268246

268247268247
return new Promise(function (resolve) {
268248268248
// it must never happend that wait4input_resolve is set
268249-
// at this time.
268249+
// at this time as this means that the previous request has
268250+
// not been resolved.
268250268251
if (_this7.expect.wait4input_resolve != undefined) console.log("COLLISION!");
268251268252
_this7.expect.wait4input_resolve = resolve;
268252268253
}).then(function () {
@@ -268410,25 +268411,28 @@ function () {
268410268411
result = JSON.parse(msg);
268411268412

268412268413
if (this.expect !== undefined) {
268413-
this.cancelReplyTimeout(); // check if the result contains the expected keys
268414+
this.cancelReplyTimeout(); // there _must_ be some entries in this.expect
268414268415

268415-
var reply_ok = true;
268416-
var keys = Object.keys(this.expect.entries);
268416+
if (this.expect.entries === undefined) console.log("No entries???");else {
268417+
// check if the result contains the expected keys
268418+
var reply_ok = true;
268419+
var keys = Object.keys(this.expect.entries);
268417268420

268418-
for (var i = 0; i < keys.length; i++) {
268419-
if (result[keys[i]].toLowerCase() !== this.expect.entries[keys[i]].toLowerCase()) {
268420-
console.log("Missing expected reply parameter:", keys[i], ":", this.expect.entries["expect"][keys[i]], "-", msg);
268421-
reply_ok = false;
268421+
for (var i = 0; i < keys.length; i++) {
268422+
if (result[keys[i]].toLowerCase() !== this.expect.entries[keys[i]].toLowerCase()) {
268423+
console.log("Missing expected reply parameter:", keys[i], ":", this.expect.entries["expect"][keys[i]], "-", msg);
268424+
reply_ok = false;
268425+
}
268422268426
}
268423-
}
268424268427

268425-
if (result[this.expect.value] === undefined) reply_ok = false;
268428+
if (result[this.expect.value] === undefined) reply_ok = false;
268426268429

268427-
if (reply_ok) {
268428-
this.expect.resolve(result[this.expect.value]);
268429-
if (this.expect.wait4input_resolve !== undefined) this.expect.wait4input_resolve();
268430-
this.expect = undefined;
268431-
} else console.log("reply expect failed");
268430+
if (reply_ok) {
268431+
this.expect.resolve(result[this.expect.value]);
268432+
if (this.expect.wait4input_resolve !== undefined) this.expect.wait4input_resolve();
268433+
this.expect = undefined;
268434+
} else console.log("reply expect failed");
268435+
}
268432268436
}
268433268437
}
268434268438
}, {
@@ -268835,7 +268839,9 @@ function () {
268835268839
value: function hatHandler() {
268836268840
var _this14 = this;
268837268841

268838-
// decrease current timeout counter
268842+
// decrease current timeout counter. This is used since we are
268843+
// not notified when a hat is being removed. This counter running
268844+
// down means that the hat has probably been deleted fromt he workspace.
268839268845
this.hat.input[this.hat.next] = this.hat.input[this.hat.next] - 1;
268840268846

268841268847
if (!this.hat.input[this.hat.next]) {

0 commit comments

Comments
 (0)