diff options
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/deno.ts | 11 | ||||
-rw-r--r-- | cli/js/dispatch.ts | 1 | ||||
-rw-r--r-- | cli/js/lib.deno.ns.d.ts | 6 | ||||
-rw-r--r-- | cli/js/os.ts | 9 | ||||
-rw-r--r-- | cli/js/os_test.ts | 16 |
5 files changed, 42 insertions, 1 deletions
diff --git a/cli/js/deno.ts b/cli/js/deno.ts index c1b074f3d..887f60826 100644 --- a/cli/js/deno.ts +++ b/cli/js/deno.ts @@ -85,7 +85,16 @@ export { ShutdownMode, shutdown } from "./net.ts"; -export { dir, env, exit, isTTY, execPath, hostname, loadavg } from "./os.ts"; +export { + dir, + env, + exit, + isTTY, + execPath, + hostname, + loadavg, + osRelease +} from "./os.ts"; export { permissions, PermissionName, diff --git a/cli/js/dispatch.ts b/cli/js/dispatch.ts index 93f6dc055..fc1c69a62 100644 --- a/cli/js/dispatch.ts +++ b/cli/js/dispatch.ts @@ -81,6 +81,7 @@ export let OP_SIGNAL_BIND: number; export let OP_SIGNAL_UNBIND: number; export let OP_SIGNAL_POLL: number; export let OP_LOADAVG: number; +export let OP_OS_RELEASE: 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 d1770a15a..0c9430869 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -52,6 +52,12 @@ declare namespace Deno { */ export function hostname(): string; + /** Get the OS release. Requires the `--allow-env` flag. + * + * console.log(Deno.osRelease()); + */ + export function osRelease(): string; + /** Exit the Deno process with optional exit code. */ export function exit(code?: number): never; diff --git a/cli/js/os.ts b/cli/js/os.ts index d3c0d1b72..7953c2cef 100644 --- a/cli/js/os.ts +++ b/cli/js/os.ts @@ -29,6 +29,15 @@ export function hostname(): string { return sendSync(dispatch.OP_HOSTNAME); } +/** Get OS release. + * Requires the `--allow-env` flag. + * + * console.log(Deno.osRelease()); + */ +export function osRelease(): string { + return sendSync(dispatch.OP_OS_RELEASE); +} + /** Exit the Deno process with optional exit code. */ export function exit(code = 0): never { sendSync(dispatch.OP_EXIT, { code }); diff --git a/cli/js/os_test.ts b/cli/js/os_test.ts index 325cbdaa6..905a4efaf 100644 --- a/cli/js/os_test.ts +++ b/cli/js/os_test.ts @@ -315,3 +315,19 @@ testPerm({ env: false }, function hostnamePerm(): void { } assert(caughtError); }); + +testPerm({ env: true }, function releaseDir(): void { + assertNotEquals(Deno.osRelease(), ""); +}); + +testPerm({ env: false }, function releasePerm(): void { + let caughtError = false; + try { + Deno.osRelease(); + } catch (err) { + caughtError = true; + assert(err instanceof Deno.Err.PermissionDenied); + assertEquals(err.name, "PermissionDenied"); + } + assert(caughtError); +}); |