summaryrefslogtreecommitdiff
path: root/lib/internal/util.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2018-09-10 09:57:15 -0400
committerDaniel Bevenius <daniel.bevenius@gmail.com>2018-09-13 08:13:17 -0400
commit466cda05484c612769effb8c61a9a8ea8379bef2 (patch)
tree347144c8ea62cdd85a3c7cd750b3234929003202 /lib/internal/util.js
parenta93f0352126ebc5917c4913d19b3ce5cd420f930 (diff)
downloadandroid-node-v8-466cda05484c612769effb8c61a9a8ea8379bef2.tar.gz
android-node-v8-466cda05484c612769effb8c61a9a8ea8379bef2.tar.bz2
android-node-v8-466cda05484c612769effb8c61a9a8ea8379bef2.zip
fs: ensure readdir() callback is only called once
This commit ensures that the readdir() callback can only be called once when the withFileTypes parameter is supplied. PR-URL: https://github.com/nodejs/node/pull/22793 Fixes: https://github.com/nodejs/node/issues/22778 Reviewed-By: Bryan English <bryan@bryanenglish.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Diffstat (limited to 'lib/internal/util.js')
-rw-r--r--lib/internal/util.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/internal/util.js b/lib/internal/util.js
index 43b9974068..5cb1b281ba 100644
--- a/lib/internal/util.js
+++ b/lib/internal/util.js
@@ -365,6 +365,15 @@ function isInsideNodeModules() {
return false;
}
+function once(callback) {
+ let called = false;
+ return function(...args) {
+ if (called) return;
+ called = true;
+ callback(...args);
+ };
+}
+
module.exports = {
assertCrypto,
cachedResult,
@@ -381,6 +390,7 @@ module.exports = {
join,
normalizeEncoding,
objectToString,
+ once,
promisify,
spliceOne,
removeColors,