Jelajahi Sumber

Fix a bug that did not cancel pending input requests when the processor had its mode set as ABORT

Lucas de Souza 4 tahun lalu
induk
melakukan
0e8cfa7562
5 mengubah file dengan 28 tambahan dan 3 penghapusan
  1. 13 0
      js/io/domConsole.js
  2. 6 3
      js/io/domInput.js
  3. 4 0
      js/io/input.js
  4. 4 0
      js/processor/lib/io.js
  5. 1 0
      js/visualUI/functions.js

+ 13 - 0
js/io/domConsole.js

@@ -371,4 +371,17 @@ export class DOMConsole {
   scheduleNotify () {
     this.idleInterval = window.setInterval(this.notifyIdle.bind(this), Config.idle_input_interval);
   }
+
+  cancelPendingInputRequests () {
+    this.inputListeners.forEach(resolve => resolve(''));
+    this.inputListeners.splice(0, this.inputListeners.length);
+    if(this.idleInterval != null) {
+      clearInterval(this.idleInterval);
+      this.idleInterval = null;
+    }
+    this.input.value = '';
+    this.inputSpan.innerHTML = '';
+    this.hideInput();
+    this.anyKey = false;
+  }
 }

+ 6 - 3
js/io/domInput.js

@@ -33,9 +33,12 @@ export class DOMInput extends Input{
   }
 
   notifyInput (text) {
-    this.listeners.forEach(resolve => {
-      resolve(text);
-    })
+    this.listeners.forEach(resolve => resolve(text));
+    this.listeners.splice(0, this.listeners.length);
+  }
+
+  cancelPendingInputRequests () {
+    this.listeners.forEach(resolve => resolve(''));
     this.listeners.splice(0, this.listeners.length);
   }
 

+ 4 - 0
js/io/input.js

@@ -3,4 +3,8 @@ export class Input {
   requestInput (callback) {
     throw new Error("Must be implemented");
   }
+
+  cancelPendingInputRequests () {
+    throw new Error("Must be implemented");
+  }
 }

+ 4 - 0
js/processor/lib/io.js

@@ -45,6 +45,10 @@ export function createInputFun () {
           return Promise.reject(new Error("!!!!Critical error: Unknown type in readFunction!!!!"));
         }
       } catch (_) {
+        if(this.mode == Modes.ABORT) {
+          store.mode = Modes.RETURN;
+          return Promise.resolve(store);
+        }
         const stringInfo = typeToConvert.stringInfo()[0]
         const realObject = store.getStoreObject("p1");
         if (realObject.getReferenceDimension() > 0) {

+ 1 - 0
js/visualUI/functions.js

@@ -1477,6 +1477,7 @@ function showStopButton () {
 
 function stopExecution () {
   domConsole.clearPendingWrites();
+  domConsole.cancelPendingInputRequests();
   if(!isRunning) {
     return;
   }