diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2023-10-05 23:57:20 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-05 18:27:20 +0000 |
commit | ab3c9d41e483e5a7e6a326c66af7052a51301f91 (patch) | |
tree | 8424ae7eb557d22a23a8af22a627382fff949b4f | |
parent | 176bf9ba5ffe1c925e7d6a395d0e946880afdcda (diff) |
fix(ext/node): implement uv.errname (#20785)
Fixes https://github.com/denoland/deno/issues/20617
-rw-r--r-- | cli/tests/unit_node/process_test.ts | 13 | ||||
-rw-r--r-- | ext/node/polyfills/internal_binding/uv.ts | 8 |
2 files changed, 21 insertions, 0 deletions
diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index bcb7a9767..78c5fcc97 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -786,3 +786,16 @@ Deno.test({ worker.terminate(); }, }); + +Deno.test({ + name: "process.binding('uv').errname", + ignore: Deno.build.os === "windows", + fn() { + // @ts-ignore: untyped internal binding, not actually supposed to be + // used by userland modules in Node.js + const uv = process.binding("uv"); + assert(uv.errname); + assert(typeof uv.errname === "function"); + assertEquals(uv.errname(-1), "EPERM"); + }, +}); diff --git a/ext/node/polyfills/internal_binding/uv.ts b/ext/node/polyfills/internal_binding/uv.ts index c08d44565..3cb145d28 100644 --- a/ext/node/polyfills/internal_binding/uv.ts +++ b/ext/node/polyfills/internal_binding/uv.ts @@ -531,3 +531,11 @@ export const UV_EINVAL = codeMap.get("EINVAL")!; export const UV_ENOENT = codeMap.get("ENOENT"); export const UV_ENOTSOCK = codeMap.get("ENOTSOCK")!; export const UV_UNKNOWN = codeMap.get("UNKNOWN")!; + +export function errname(errno: number): string { + const err = errorMap.get(errno); + if (err) { + return err[0]; + } + return `UNKNOWN (${errno})`; +} |