(text: string)
| 85 | } |
| 86 | |
| 87 | function input(text: string) { |
| 88 | // TODO: send unique ids to the main thread and the service worker, so we |
| 89 | // can have multiple concurrent input requests. |
| 90 | postMessage({ type: 'input', text }); |
| 91 | const request = new XMLHttpRequest(); |
| 92 | request.open('POST', '/python/intercept-input/', false); |
| 93 | request.send(null); |
| 94 | |
| 95 | // We want to raise a KeyboardInterrupt if the user cancels. To do that, |
| 96 | // this function returns a JS object with the 'type' property set to |
| 97 | // 'cancel'. Then the python code can actually raise the exception. |
| 98 | return JSON.parse(request.responseText) as { |
| 99 | type: 'msg' | 'cancel'; |
| 100 | value?: string; |
| 101 | }; |
| 102 | } |
| 103 | |
| 104 | function __interruptExecution() { |
| 105 | postMessage({ type: 'reset' }); |
no test coverage detected