({ currentTarget, script }, onBeforeRun = "")
| 42 | }; |
| 43 | |
| 44 | async function execute({ currentTarget, script }, onBeforeRun = "") { |
| 45 | const { env, pySrc, outDiv } = this; |
| 46 | const hasRunButton = !!currentTarget; |
| 47 | |
| 48 | if (hasRunButton) { |
| 49 | currentTarget.classList.add("running"); |
| 50 | currentTarget.innerHTML = STOP_BUTTON; |
| 51 | outDiv.innerHTML = ""; |
| 52 | } |
| 53 | |
| 54 | if (!envs.has(env)) { |
| 55 | const srcLink = URL.createObjectURL(new Blob([""])); |
| 56 | const details = { |
| 57 | type: this.interpreter, |
| 58 | serviceWorker: this.serviceWorker, |
| 59 | }; |
| 60 | const { config } = this; |
| 61 | if (config) { |
| 62 | // verify that config can be parsed and used |
| 63 | try { |
| 64 | details.configURL = relative_url(config); |
| 65 | if (config.endsWith(".toml")) { |
| 66 | const [{ parse }, toml] = await Promise.all([ |
| 67 | import( |
| 68 | /* webpackIgnore: true */ "../3rd-party/toml.js" |
| 69 | ), |
| 70 | fetch(config).then((r) => r.ok && r.text()), |
| 71 | ]); |
| 72 | details.config = parse(validate(config, toml)); |
| 73 | } else if (config.endsWith(".json")) { |
| 74 | const json = await fetch(config).then( |
| 75 | (r) => r.ok && r.json(), |
| 76 | ); |
| 77 | details.config = validate(config, json); |
| 78 | } else { |
| 79 | details.configURL = relative_url("./config.txt"); |
| 80 | details.config = JSON.parse(config); |
| 81 | } |
| 82 | details.version = offline_interpreter(details.config); |
| 83 | } catch (error) { |
| 84 | notify(error); |
| 85 | return; |
| 86 | } |
| 87 | } else { |
| 88 | details.config = {}; |
| 89 | } |
| 90 | |
| 91 | const xworker = XWorker.call(new Hook(null, hooks), srcLink, details); |
| 92 | |
| 93 | // expose xworker like in terminal or other workers to allow |
| 94 | // creation and destruction of editors on the fly |
| 95 | if (hasRunButton) { |
| 96 | for (const type of TYPES.keys()) { |
| 97 | script = getRelatedScript(currentTarget, type); |
| 98 | if (script) break; |
| 99 | } |
| 100 | } |
| 101 |
no test coverage detected