Skip to content

Commit

Permalink
fix(ext/node): export geteuid from node:process (#23840)
Browse files Browse the repository at this point in the history
Fixes #23827
  • Loading branch information
littledivy committed May 16, 2024
1 parent f6c6e76 commit a31b813
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ext/node/polyfills/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ export function kill(pid: number, sig: string | number = "SIGTERM") {
return true;
}

let getgid, getuid, geteuid;

if (!isWindows) {
getgid = () => Deno.gid();
getuid = () => Deno.uid();
geteuid = () => op_geteuid();
}

export { geteuid, getgid, getuid };

// deno-lint-ignore no-explicit-any
function uncaughtExceptionHandler(err: any, origin: string) {
// The origin parameter can be 'unhandledRejection' or 'uncaughtException'
Expand Down Expand Up @@ -638,19 +648,13 @@ class Process extends EventEmitter {
}

/** This method is removed on Windows */
getgid?(): number {
return Deno.gid()!;
}
getgid = getgid;

/** This method is removed on Windows */
getuid?(): number {
return Deno.uid()!;
}
getuid = getuid;

/** This method is removed on Windows */
geteuid?(): number {
return op_geteuid();
}
geteuid = geteuid;

// TODO(kt3k): Implement this when we added -e option to node compat mode
_eval: string | undefined = undefined;
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import process, {
argv,
argv0 as importedArgv0,
env,
geteuid,
pid as importedPid,
platform as importedPlatform,
} from "node:process";
Expand Down Expand Up @@ -879,6 +880,7 @@ Deno.test("process.geteuid", () => {
if (Deno.build.os === "windows") {
assertEquals(process.geteuid, undefined);
} else {
assert(geteuid);
assert(typeof process.geteuid?.() === "number");
}
});
Expand Down

0 comments on commit a31b813

Please sign in to comment.