dateId(id, 'id'); if (typeof id === 'number') id |= 0; // Result is 0 on success, 1 if credential is unknown. const result = method(id); if (result === 1) { throw new ERR_UNKNOWN_CREDENTIAL(type, id); } }; } function validateId(id, name) { if (typeof id === 'number') { validateUint32(id, name); } else if (typeof id !== 'string') { throw new ERR_INVALID_ARG_TYPE(name, ['number', 'string'], id); } } return { initgroups, setgroups, setegid: wrapIdSetter('Group', _setegid), seteuid: wrapIdSetter('User', _seteuid), setgid: wrapIdSetter('Group', _setgid), setuid: wrapIdSetter('User', _setuid) }; } // Cache the working directory to prevent lots of lookups. If the working // directory is changed by `chdir`, it'll be updated. let cachedCwd = ''; function wrappedChdir(directory) { validateString(directory, 'directory'); rawMethods.chdir(directory); // Mark cache that it requires an update. cachedCwd = ''; } function wrappedUmask(mask) { if (mask !== undefined) { mask = parseFileMode(mask, 'mask'); } return rawMethods.umask(mask); } function wrappedCwd() { if (cachedCwd === '') cachedCwd = rawMethods.cwd(); return cachedCwd; }