mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
feat(unstable): add Deno.getGid (#14528)
This commit is contained in:
parent
d9ed5e905c
commit
c41544ac7b
5 changed files with 45 additions and 0 deletions
12
cli/dts/lib.deno.unstable.d.ts
vendored
12
cli/dts/lib.deno.unstable.d.ts
vendored
|
@ -317,6 +317,18 @@ declare namespace Deno {
|
|||
*/
|
||||
export function getUid(): number | null;
|
||||
|
||||
/** **Unstable** new API. yet to be vetted.
|
||||
*
|
||||
* Returns the group id of the process on POSIX platforms. Returns null on windows.
|
||||
*
|
||||
* ```ts
|
||||
* console.log(Deno.getGid());
|
||||
* ```
|
||||
*
|
||||
* Requires `allow-env` permission.
|
||||
*/
|
||||
export function getGid(): number | null;
|
||||
|
||||
/** All possible types for interfacing with foreign functions */
|
||||
export type NativeType =
|
||||
| "void"
|
||||
|
|
|
@ -204,3 +204,13 @@ Deno.test({ permissions: { env: true } }, function getUid() {
|
|||
assert(uid > 0);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test({ permissions: { env: true } }, function getGid() {
|
||||
if (Deno.build.os === "windows") {
|
||||
assertEquals(Deno.getGid(), null);
|
||||
} else {
|
||||
const gid = Deno.getGid();
|
||||
assert(typeof gid === "number");
|
||||
assert(gid > 0);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
return core.opSync("op_network_interfaces");
|
||||
}
|
||||
|
||||
function getGid() {
|
||||
return core.opSync("op_getgid");
|
||||
}
|
||||
|
||||
function getUid() {
|
||||
return core.opSync("op_getuid");
|
||||
}
|
||||
|
@ -94,6 +98,7 @@
|
|||
env,
|
||||
execPath,
|
||||
exit,
|
||||
getGid,
|
||||
getUid,
|
||||
hostname,
|
||||
loadavg,
|
||||
|
|
|
@ -124,6 +124,7 @@
|
|||
osRelease: __bootstrap.os.osRelease,
|
||||
systemMemoryInfo: __bootstrap.os.systemMemoryInfo,
|
||||
networkInterfaces: __bootstrap.os.networkInterfaces,
|
||||
getGid: __bootstrap.os.getGid,
|
||||
getUid: __bootstrap.os.getUid,
|
||||
sleepSync: __bootstrap.timers.sleepSync,
|
||||
listen: __bootstrap.netUnstable.listen,
|
||||
|
|
|
@ -22,6 +22,7 @@ pub fn init(maybe_exit_code: Option<Arc<AtomicI32>>) -> Extension {
|
|||
op_exit::decl(),
|
||||
op_delete_env::decl(),
|
||||
op_get_env::decl(),
|
||||
op_getgid::decl(),
|
||||
op_getuid::decl(),
|
||||
op_hostname::decl(),
|
||||
op_loadavg::decl(),
|
||||
|
@ -225,6 +226,22 @@ fn op_system_memory_info(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[op]
|
||||
fn op_getgid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
|
||||
super::check_unstable(state, "Deno.getGid");
|
||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||
unsafe { Ok(Some(libc::getgid())) }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[op]
|
||||
fn op_getgid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
|
||||
super::check_unstable(state, "Deno.getGid");
|
||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[op]
|
||||
fn op_getuid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
|
||||
|
|
Loading…
Reference in a new issue