summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/os.ts26
-rw-r--r--js/os_test.ts12
-rwxr-xr-xjs/unit_test_runner.ts2
3 files changed, 29 insertions, 11 deletions
diff --git a/js/os.ts b/js/os.ts
index 551cb1ea6..11407cfb0 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -13,16 +13,10 @@ export let pid: number;
/** Reflects the NO_COLOR environment variable: https://no-color.org/ */
export let noColor: boolean;
-/** Path to the current deno process's executable file.
- * Requires the `--allow-env` flag, otherwise it'll be set to an empty `string`.
- */
-export let execPath: string;
-
-function setGlobals(pid_: number, noColor_: boolean, execPath_: string): void {
+function setGlobals(pid_: number, noColor_: boolean): void {
assert(!pid);
pid = pid_;
noColor = noColor_;
- execPath = execPath_;
}
/** Check if running in terminal.
@@ -127,7 +121,7 @@ export function start(
util.setLogDebug(startResMsg.debugFlag(), source);
- setGlobals(startResMsg.pid(), startResMsg.noColor(), startResMsg.execPath()!);
+ setGlobals(startResMsg.pid(), startResMsg.noColor());
if (preserveDenoNamespace) {
util.immutableDefine(window, "Deno", window.Deno);
@@ -164,3 +158,19 @@ export function homeDir(): string {
return path;
}
+
+export function execPath(): string {
+ const builder = flatbuffers.createBuilder();
+ const inner = msg.ExecPath.createExecPath(builder);
+ const baseRes = sendSync(builder, msg.Any.ExecPath, inner)!;
+ assert(msg.Any.ExecPathRes === baseRes.innerType());
+ const res = new msg.ExecPathRes();
+ assert(baseRes.inner(res) != null);
+ const path = res.path();
+
+ if (!path) {
+ throw new Error("Could not get home directory.");
+ }
+
+ return path;
+}
diff --git a/js/os_test.ts b/js/os_test.ts
index b2f511b5e..28c8b6a0b 100644
--- a/js/os_test.ts
+++ b/js/os_test.ts
@@ -56,9 +56,17 @@ testPerm({ env: false }, function homeDirPerm(): void {
});
testPerm({ env: true }, function execPath(): void {
- assertNotEquals(Deno.execPath, "");
+ assertNotEquals(Deno.execPath(), "");
});
testPerm({ env: false }, function execPathPerm(): void {
- assertEquals(Deno.execPath, "");
+ let caughtError = false;
+ try {
+ Deno.execPath();
+ } catch (err) {
+ caughtError = true;
+ assertEquals(err.kind, Deno.ErrorKind.PermissionDenied);
+ assertEquals(err.name, "PermissionDenied");
+ }
+ assert(caughtError);
});
diff --git a/js/unit_test_runner.ts b/js/unit_test_runner.ts
index 55ccd14bf..24dae7706 100755
--- a/js/unit_test_runner.ts
+++ b/js/unit_test_runner.ts
@@ -53,7 +53,7 @@ async function main(): Promise<void> {
const cliPerms = permsToCliFlags(perms);
// run subsequent tests using same deno executable
const args = [
- Deno.execPath,
+ Deno.execPath(),
"run",
"--no-prompt",
...cliPerms,