From c068880757b4dc86156f4ea3f6c720e929351a20 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Wed, 18 May 2016 17:22:17 +0530 Subject: [PATCH] fs: mkdtemp shouldn't crash if no callback passed As it is, `fs.mkdtemp` crashes with a C++ assertion if the callback function is not passed. This patch uses `maybeCallback` to create one, if no callback function is passed. PR-URL: https://github.com/nodejs/node/pull/6828 Reviewed-By: Brian White Reviewed-By: James M Snell --- lib/fs.js | 3 ++- test/parallel/test-fs-mkdtemp.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index e441746366e729..31916e5b62c793 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1994,7 +1994,8 @@ SyncWriteStream.prototype.destroy = function() { SyncWriteStream.prototype.destroySoon = SyncWriteStream.prototype.destroy; -fs.mkdtemp = function(prefix, options, callback) { +fs.mkdtemp = function(prefix, options, callback_) { + var callback = maybeCallback(callback_); if (!prefix || typeof prefix !== 'string') throw new TypeError('filename prefix is required'); diff --git a/test/parallel/test-fs-mkdtemp.js b/test/parallel/test-fs-mkdtemp.js index ad8a6cb46e02eb..d3def97fef1588 100644 --- a/test/parallel/test-fs-mkdtemp.js +++ b/test/parallel/test-fs-mkdtemp.js @@ -25,3 +25,5 @@ fs.mkdtemp( assert(common.fileExists(folder)); }) ); + +assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));