summaryrefslogtreecommitdiff
path: root/cli/js2/30_os.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-07-19 19:49:44 +0200
committerGitHub <noreply@github.com>2020-07-19 19:49:44 +0200
commitfa61956f03491101b6ef64423ea2f1f73af26a73 (patch)
treec3800702071ca78aa4dd71bdd0a59a9bbe460bdd /cli/js2/30_os.js
parent53adde866dd399aa2509d14508642fce37afb8f5 (diff)
Port internal TS code to JS (#6793)
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Diffstat (limited to 'cli/js2/30_os.js')
-rw-r--r--cli/js2/30_os.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/cli/js2/30_os.js b/cli/js2/30_os.js
new file mode 100644
index 000000000..743ecd585
--- /dev/null
+++ b/cli/js2/30_os.js
@@ -0,0 +1,56 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+
+((window) => {
+ const sendSync = window.__bootstrap.dispatchJson.sendSync;
+
+ function loadavg() {
+ return sendSync("op_loadavg");
+ }
+
+ function hostname() {
+ return sendSync("op_hostname");
+ }
+
+ function osRelease() {
+ return sendSync("op_os_release");
+ }
+
+ function exit(code = 0) {
+ sendSync("op_exit", { code });
+ throw new Error("Code not reachable");
+ }
+
+ function setEnv(key, value) {
+ sendSync("op_set_env", { key, value });
+ }
+
+ function getEnv(key) {
+ return sendSync("op_get_env", { key })[0];
+ }
+
+ function deleteEnv(key) {
+ sendSync("op_delete_env", { key });
+ }
+
+ const env = {
+ get: getEnv,
+ toObject() {
+ return sendSync("op_env");
+ },
+ set: setEnv,
+ delete: deleteEnv,
+ };
+
+ function execPath() {
+ return sendSync("op_exec_path");
+ }
+
+ window.__bootstrap.os = {
+ env,
+ execPath,
+ exit,
+ osRelease,
+ hostname,
+ loadavg,
+ };
+})(this);