gh-127146: Emscripten: Make os.umask() actually work (#136706)

Provide a stub implementation of umask that is enough to get some tests passing.
More work is needed upstream in Emscripten to make all umask tests to pass.
This commit is contained in:
Hood Chatham 2025-07-16 15:33:15 +02:00 committed by GitHub
parent 8e2f4b4483
commit 12e52cad71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 5 deletions

View file

@ -7,7 +7,7 @@
// defined with weak linkage so we can override it.
EM_JS(int, __syscall_getuid32_js, (void), {
// If we're in node and we can, report the native uid
if (typeof process !== "undefined" && typeof process.getuid === "function") {
if (ENVIRONMENT_IS_NODE) {
return process.getuid();
}
// Fall back to the stub case of returning 0.
@ -17,3 +17,23 @@ EM_JS(int, __syscall_getuid32_js, (void), {
int __syscall_getuid32(void) {
return __syscall_getuid32_js();
}
EM_JS(int, __syscall_umask_js, (int mask), {
// If we're in node and we can, call native process.umask()
if (ENVIRONMENT_IS_NODE) {
try {
return process.umask(mask);
} catch(e) {
// oops...
// NodeJS docs: "In Worker threads, process.umask(mask) will throw an exception."
// umask docs: "This system call always succeeds"
return 0;
}
}
// Fall back to the stub case of returning 0.
return 0;
})
int __syscall_umask(int mask) {
return __syscall_umask_js(mask);
}