summaryrefslogtreecommitdiff
path: root/lib/internal/process/main_thread_only.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/internal/process/main_thread_only.js')
-rw-r--r--lib/internal/process/main_thread_only.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/internal/process/main_thread_only.js b/lib/internal/process/main_thread_only.js
index 358e2b37b0..0cb3edbf9a 100644
--- a/lib/internal/process/main_thread_only.js
+++ b/lib/internal/process/main_thread_only.js
@@ -20,9 +20,15 @@ const { signals } = internalBinding('constants').os;
// The execution of this function itself should not cause any side effects.
function wrapProcessMethods(binding) {
+ // Cache the working directory to prevent lots of lookups. If the working
+ // directory is changed by `chdir`, it'll be updated.
+ let cachedCwd = '';
+
function chdir(directory) {
validateString(directory, 'directory');
- return binding.chdir(directory);
+ binding.chdir(directory);
+ // Mark cache that it requires an update.
+ cachedCwd = '';
}
function umask(mask) {
@@ -32,9 +38,16 @@ function wrapProcessMethods(binding) {
return binding.umask(mask);
}
+ function cwd() {
+ if (cachedCwd === '')
+ cachedCwd = binding.cwd();
+ return cachedCwd;
+ }
+
return {
chdir,
- umask
+ umask,
+ cwd
};
}