chore(unstable): rename Deno.getUid() and Deno.getGid() (#16432)

This commit renames `Deno.getUid()` to `Deno.uid()` and renames
`Deno.getGid()` to `Deno.gid()`.
This commit is contained in:
Colin Ihrig 2022-10-26 16:37:48 -04:00 committed by GitHub
parent f4f1f4f0b6
commit 37340e2386
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 38 additions and 38 deletions

View file

@ -3762,8 +3762,8 @@ declare namespace Deno {
| "systemMemoryInfo"
| "networkInterfaces"
| "osRelease"
| "getUid"
| "getGid";
| "uid"
| "gid";
}
/** The permission descriptor for the `allow-ffi` permissions, which controls

View file

@ -359,7 +359,7 @@ declare namespace Deno {
* on Windows.
*
* ```ts
* console.log(Deno.getUid());
* console.log(Deno.uid());
* ```
*
* Requires `allow-sys` permission.
@ -367,7 +367,7 @@ declare namespace Deno {
* @tags allow-sys
* @category Runtime Environment
*/
export function getUid(): number | null;
export function uid(): number | null;
/** **UNSTABLE**: New API, yet to be vetted.
*
@ -375,7 +375,7 @@ declare namespace Deno {
* Windows.
*
* ```ts
* console.log(Deno.getGid());
* console.log(Deno.gid());
* ```
*
* Requires `allow-sys` permission.
@ -383,7 +383,7 @@ declare namespace Deno {
* @tags allow-sys
* @category Runtime Environment
*/
export function getGid(): number | null;
export function gid(): number | null;
/** **UNSTABLE**: New API, yet to be vetted.
*

View file

@ -241,21 +241,21 @@ Deno.test(
},
);
Deno.test({ permissions: { sys: ["getUid"] } }, function getUid() {
Deno.test({ permissions: { sys: ["uid"] } }, function getUid() {
if (Deno.build.os === "windows") {
assertEquals(Deno.getUid(), null);
assertEquals(Deno.uid(), null);
} else {
const uid = Deno.getUid();
const uid = Deno.uid();
assert(typeof uid === "number");
assert(uid > 0);
}
});
Deno.test({ permissions: { sys: ["getGid"] } }, function getGid() {
Deno.test({ permissions: { sys: ["gid"] } }, function getGid() {
if (Deno.build.os === "windows") {
assertEquals(Deno.getGid(), null);
assertEquals(Deno.gid(), null);
} else {
const gid = Deno.getGid();
const gid = Deno.gid();
assert(typeof gid === "number");
assert(gid > 0);
}

View file

@ -25,8 +25,8 @@ Deno.test(async function permissionSysValidKind() {
await Deno.permissions.query({ name: "sys", kind: "networkInterfaces" });
await Deno.permissions.query({ name: "sys", kind: "systemMemoryInfo" });
await Deno.permissions.query({ name: "sys", kind: "hostname" });
await Deno.permissions.query({ name: "sys", kind: "getUid" });
await Deno.permissions.query({ name: "sys", kind: "getGid" });
await Deno.permissions.query({ name: "sys", kind: "uid" });
await Deno.permissions.query({ name: "sys", kind: "gid" });
});
Deno.test(async function permissionSysInvalidKind() {

View file

@ -33,12 +33,12 @@
return ops.op_network_interfaces();
}
function getGid() {
return ops.op_getgid();
function gid() {
return ops.op_gid();
}
function getUid() {
return ops.op_getuid();
function uid() {
return ops.op_uid();
}
// This is an internal only method used by the test harness to override the
@ -101,13 +101,13 @@
env,
execPath,
exit,
getGid,
getUid,
gid,
hostname,
loadavg,
networkInterfaces,
osRelease,
setExitHandler,
systemMemoryInfo,
uid,
};
})(this);

View file

@ -128,8 +128,8 @@
osRelease: __bootstrap.os.osRelease,
systemMemoryInfo: __bootstrap.os.systemMemoryInfo,
networkInterfaces: __bootstrap.os.networkInterfaces,
getGid: __bootstrap.os.getGid,
getUid: __bootstrap.os.getUid,
gid: __bootstrap.os.gid,
uid: __bootstrap.os.uid,
listenDatagram: __bootstrap.net.listenDatagram,
umask: __bootstrap.fs.umask,
HttpClient: __bootstrap.fetch.HttpClient,

View file

@ -20,8 +20,7 @@ fn init_ops(builder: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
op_exit::decl(),
op_delete_env::decl(),
op_get_env::decl(),
op_getgid::decl(),
op_getuid::decl(),
op_gid::decl(),
op_hostname::decl(),
op_loadavg::decl(),
op_network_interfaces::decl(),
@ -29,6 +28,7 @@ fn init_ops(builder: &mut ExtensionBuilder) -> &mut ExtensionBuilder {
op_set_env::decl(),
op_set_exit_code::decl(),
op_system_memory_info::decl(),
op_uid::decl(),
])
}
@ -284,12 +284,12 @@ 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");
fn op_gid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
super::check_unstable(state, "Deno.gid");
state
.borrow_mut::<Permissions>()
.sys
.check("getGid", Some("Deno.getGid()"))?;
.check("gid", Some("Deno.gid()"))?;
// TODO(bartlomieju):
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
@ -299,23 +299,23 @@ fn op_getgid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
#[cfg(windows)]
#[op]
fn op_getgid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
super::check_unstable(state, "Deno.getGid");
fn op_gid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
super::check_unstable(state, "Deno.gid");
state
.borrow_mut::<Permissions>()
.sys
.check("getGid", Some("Deno.getGid()"))?;
.check("gid", Some("Deno.gid()"))?;
Ok(None)
}
#[cfg(not(windows))]
#[op]
fn op_getuid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
super::check_unstable(state, "Deno.getUid");
fn op_uid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
super::check_unstable(state, "Deno.uid");
state
.borrow_mut::<Permissions>()
.sys
.check("getUid", Some("Deno.getUid()"))?;
.check("uid", Some("Deno.uid()"))?;
// TODO(bartlomieju):
#[allow(clippy::undocumented_unsafe_blocks)]
unsafe {
@ -325,11 +325,11 @@ fn op_getuid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
#[cfg(windows)]
#[op]
fn op_getuid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
super::check_unstable(state, "Deno.getUid");
fn op_uid(state: &mut OpState) -> Result<Option<u32>, AnyError> {
super::check_unstable(state, "Deno.uid");
state
.borrow_mut::<Permissions>()
.sys
.check("getUid", Some("Deno.getUid()"))?;
.check("uid", Some("Deno.uid()"))?;
Ok(None)
}

View file

@ -308,7 +308,7 @@ pub struct SysDescriptor(pub String);
pub fn parse_sys_kind(kind: &str) -> Result<&str, AnyError> {
match kind {
"hostname" | "osRelease" | "loadavg" | "networkInterfaces"
| "systemMemoryInfo" | "getUid" | "getGid" => Ok(kind),
| "systemMemoryInfo" | "uid" | "gid" => Ok(kind),
_ => Err(type_error(format!("unknown system info kind \"{}\"", kind))),
}
}

@ -1 +1 @@
Subproject commit f2c97ea9c382fb3e225929c7650934417e2fc8c9
Subproject commit e26ced48ce65f1ab0e3bd2fc6e393b9ad526c6fe