summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/deno.ts2
-rw-r--r--cli/js/dispatch.ts1
-rw-r--r--cli/js/lib.deno.ns.d.ts6
-rw-r--r--cli/js/os.ts8
-rw-r--r--cli/js/os_test.ts17
5 files changed, 33 insertions, 1 deletions
diff --git a/cli/js/deno.ts b/cli/js/deno.ts
index d20c64281..c1b074f3d 100644
--- a/cli/js/deno.ts
+++ b/cli/js/deno.ts
@@ -85,7 +85,7 @@ export {
ShutdownMode,
shutdown
} from "./net.ts";
-export { dir, env, exit, isTTY, execPath, hostname } from "./os.ts";
+export { dir, env, exit, isTTY, execPath, hostname, loadavg } from "./os.ts";
export {
permissions,
PermissionName,
diff --git a/cli/js/dispatch.ts b/cli/js/dispatch.ts
index 3d2138953..93f6dc055 100644
--- a/cli/js/dispatch.ts
+++ b/cli/js/dispatch.ts
@@ -80,6 +80,7 @@ export let OP_TRANSPILE: number;
export let OP_SIGNAL_BIND: number;
export let OP_SIGNAL_UNBIND: number;
export let OP_SIGNAL_POLL: number;
+export let OP_LOADAVG: number;
const PLUGIN_ASYNC_HANDLER_MAP: Map<number, AsyncHandler> = new Map();
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 39303677a..d1770a15a 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -40,6 +40,12 @@ declare namespace Deno {
stderr: boolean;
};
+ /** Get the loadavg. Requires the `--allow-env` flag.
+ *
+ * console.log(Deno.loadavg());
+ */
+ export function loadavg(): number[];
+
/** Get the hostname. Requires the `--allow-env` flag.
*
* console.log(Deno.hostname());
diff --git a/cli/js/os.ts b/cli/js/os.ts
index 275dbdf1d..d3c0d1b72 100644
--- a/cli/js/os.ts
+++ b/cli/js/os.ts
@@ -11,6 +11,14 @@ import * as util from "./util.ts";
export function isTTY(): { stdin: boolean; stdout: boolean; stderr: boolean } {
return sendSync(dispatch.OP_IS_TTY);
}
+/** Get the loadavg.
+ * Requires the `--allow-env` flag.
+ *
+ * console.log(Deno.loadavg());
+ */
+export function loadavg(): number[] {
+ return sendSync(dispatch.OP_LOADAVG);
+}
/** Get the hostname.
* Requires the `--allow-env` flag.
diff --git a/cli/js/os_test.ts b/cli/js/os_test.ts
index fa4bf636b..325cbdaa6 100644
--- a/cli/js/os_test.ts
+++ b/cli/js/os_test.ts
@@ -283,6 +283,23 @@ testPerm({ env: false }, function execPathPerm(): void {
assert(caughtError);
});
+testPerm({ env: true }, function loadavgSuccess(): void {
+ const load = Deno.loadavg();
+ assertEquals(load.length, 3);
+});
+
+testPerm({ env: false }, function loadavgPerm(): void {
+ let caughtError = false;
+ try {
+ Deno.loadavg();
+ } catch (err) {
+ caughtError = true;
+ assert(err instanceof Deno.Err.PermissionDenied);
+ assertEquals(err.name, "PermissionDenied");
+ }
+ assert(caughtError);
+});
+
testPerm({ env: true }, function hostnameDir(): void {
assertNotEquals(Deno.hostname(), "");
});