diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-12-13 19:45:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-13 19:45:53 +0100 |
commit | 2e74f164b6dcf0ecbf8dd38fba9fae550d784bd0 (patch) | |
tree | 61abe8e09d5331ace5d9de529f0e2737a8e05dbb /cli/rt/40_process.js | |
parent | 84ef9bd21fb48fb6b5fbc8dafc3de9f361bade3b (diff) |
refactor: deno_runtime crate (#8640)
This commit moves Deno JS runtime, ops, permissions and
inspector implementation to new "deno_runtime" crate located
in "runtime/" directory.
Details in "runtime/README.md".
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'cli/rt/40_process.js')
-rw-r--r-- | cli/rt/40_process.js | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/cli/rt/40_process.js b/cli/rt/40_process.js deleted file mode 100644 index b46a1aead..000000000 --- a/cli/rt/40_process.js +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -((window) => { - const core = window.Deno.core; - const { File } = window.__bootstrap.files; - const { readAll } = window.__bootstrap.buffer; - const { assert, pathFromURL } = window.__bootstrap.util; - - function opKill(pid, signo) { - core.jsonOpSync("op_kill", { pid, signo }); - } - - function opRunStatus(rid) { - return core.jsonOpAsync("op_run_status", { rid }); - } - - function opRun(request) { - assert(request.cmd.length > 0); - return core.jsonOpSync("op_run", request); - } - - async function runStatus(rid) { - const res = await opRunStatus(rid); - - if (res.gotSignal) { - const signal = res.exitSignal; - return { success: false, code: 128 + signal, signal }; - } else if (res.exitCode != 0) { - return { success: false, code: res.exitCode }; - } else { - return { success: true, code: 0 }; - } - } - - class Process { - constructor(res) { - this.rid = res.rid; - this.pid = res.pid; - - if (res.stdinRid && res.stdinRid > 0) { - this.stdin = new File(res.stdinRid); - } - - if (res.stdoutRid && res.stdoutRid > 0) { - this.stdout = new File(res.stdoutRid); - } - - if (res.stderrRid && res.stderrRid > 0) { - this.stderr = new File(res.stderrRid); - } - } - - status() { - return runStatus(this.rid); - } - - async output() { - if (!this.stdout) { - throw new TypeError("stdout was not piped"); - } - try { - return await readAll(this.stdout); - } finally { - this.stdout.close(); - } - } - - async stderrOutput() { - if (!this.stderr) { - throw new TypeError("stderr was not piped"); - } - try { - return await readAll(this.stderr); - } finally { - this.stderr.close(); - } - } - - close() { - core.close(this.rid); - } - - kill(signo) { - opKill(this.pid, signo); - } - } - - function isRid(arg) { - return !isNaN(arg); - } - - function run({ - cmd, - cwd = undefined, - env = {}, - stdout = "inherit", - stderr = "inherit", - stdin = "inherit", - }) { - if (cmd[0] != null) { - cmd[0] = pathFromURL(cmd[0]); - } - const res = opRun({ - cmd: cmd.map(String), - cwd, - env: Object.entries(env), - stdin: isRid(stdin) ? "" : stdin, - stdout: isRid(stdout) ? "" : stdout, - stderr: isRid(stderr) ? "" : stderr, - stdinRid: isRid(stdin) ? stdin : 0, - stdoutRid: isRid(stdout) ? stdout : 0, - stderrRid: isRid(stderr) ? stderr : 0, - }); - return new Process(res); - } - - window.__bootstrap.process = { - run, - Process, - kill: opKill, - }; -})(this); |