From b16e6220a2483098b1d2d4564d3d09f08756fae3 Mon Sep 17 00:00:00 2001 From: restlessronin <88921269+restlessronin@users.noreply.github.com> Date: Wed, 7 Feb 2024 12:08:40 +0530 Subject: [PATCH] fix: enable "--allow-sys=cpus" for "deno run" (#22260) Fixes #22221 with the suggested fix, and added "cpus" to the existing tests. --- cli/tests/unit/permissions_test.ts | 2 ++ cli/tsc/dts/lib.deno.ns.d.ts | 3 ++- runtime/permissions/mod.rs | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/tests/unit/permissions_test.ts b/cli/tests/unit/permissions_test.ts index 0710228a4b..4dab0696a5 100644 --- a/cli/tests/unit/permissions_test.ts +++ b/cli/tests/unit/permissions_test.ts @@ -41,6 +41,7 @@ Deno.test(async function permissionSysValidKind() { await Deno.permissions.query({ name: "sys", kind: "hostname" }); await Deno.permissions.query({ name: "sys", kind: "uid" }); await Deno.permissions.query({ name: "sys", kind: "gid" }); + await Deno.permissions.query({ name: "sys", kind: "cpus" }); }); Deno.test(function permissionSysValidKindSync() { @@ -51,6 +52,7 @@ Deno.test(function permissionSysValidKindSync() { Deno.permissions.querySync({ name: "sys", kind: "hostname" }); Deno.permissions.querySync({ name: "sys", kind: "uid" }); Deno.permissions.querySync({ name: "sys", kind: "gid" }); + Deno.permissions.querySync({ name: "sys", kind: "cpus" }); }); Deno.test(async function permissionSysInvalidKind() { diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 8401d23029..f855a0c0e9 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -4936,7 +4936,8 @@ declare namespace Deno { | "osRelease" | "osUptime" | "uid" - | "gid"; + | "gid" + | "cpus"; } /** The permission descriptor for the `allow-ffi` and `deny-ffi` permissions, which controls diff --git a/runtime/permissions/mod.rs b/runtime/permissions/mod.rs index 89adab3610..bdefe4f12a 100644 --- a/runtime/permissions/mod.rs +++ b/runtime/permissions/mod.rs @@ -688,7 +688,7 @@ impl Descriptor for SysDescriptor { pub fn parse_sys_kind(kind: &str) -> Result<&str, AnyError> { match kind { "hostname" | "osRelease" | "osUptime" | "loadavg" | "networkInterfaces" - | "systemMemoryInfo" | "uid" | "gid" => Ok(kind), + | "systemMemoryInfo" | "uid" | "gid" | "cpus" => Ok(kind), _ => Err(type_error(format!("unknown system info kind \"{kind}\""))), } }