summaryrefslogtreecommitdiff
path: root/test/parallel/test-fs-mkdtemp.js
diff options
context:
space:
mode:
authorSakthipriyan Vairamani <thechargingvolcano@gmail.com>2016-05-30 23:15:01 +0530
committerSakthipriyan Vairamani <thechargingvolcano@gmail.com>2016-06-04 16:31:18 +0530
commitc4fadbc15de5f7dbbe607e29bf90cbbd8b5fa6f5 (patch)
tree3b7c87a01022685a6f8e967ee22fce5e819f99a6 /test/parallel/test-fs-mkdtemp.js
parent1a21524b6908892e2d0a79cbb4241aee78530c09 (diff)
downloadandroid-node-v8-c4fadbc15de5f7dbbe607e29bf90cbbd8b5fa6f5.tar.gz
android-node-v8-c4fadbc15de5f7dbbe607e29bf90cbbd8b5fa6f5.tar.bz2
android-node-v8-c4fadbc15de5f7dbbe607e29bf90cbbd8b5fa6f5.zip
fs: execute mkdtemp's callback with no context
All the callback functions in `fs` module are supposed to be executed with no context (`this` value should not be a valid object). But `mkdtemp`'s callback will have the `FSReqWrap` object as the context. Sample code to reproduce the problem 'use strict'; const fs = require('fs'); fs.mkdtemp('/tmp/abcd', null, function() { console.log(this); }); This would print FSReqWrap { oncomplete: [Function] } But that should have printed `null` and this patch fixes that. PR-URL: https://github.com/nodejs/node/pull/7068 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-fs-mkdtemp.js')
-rw-r--r--test/parallel/test-fs-mkdtemp.js21
1 files changed, 14 insertions, 7 deletions
diff --git a/test/parallel/test-fs-mkdtemp.js b/test/parallel/test-fs-mkdtemp.js
index d3def97fef..dd4ab75c22 100644
--- a/test/parallel/test-fs-mkdtemp.js
+++ b/test/parallel/test-fs-mkdtemp.js
@@ -18,12 +18,19 @@ assert.equal(Buffer.byteLength(path.basename(utf8)),
Buffer.byteLength('\u0222abc.XXXXXX'));
assert(common.fileExists(utf8));
-fs.mkdtemp(
- path.join(common.tmpDir, 'bar.'),
- common.mustCall(function(err, folder) {
- assert.ifError(err);
- assert(common.fileExists(folder));
- })
-);
+function handler(err, folder) {
+ assert.ifError(err);
+ assert(common.fileExists(folder));
+ assert.strictEqual(this, null);
+}
+fs.mkdtemp(path.join(common.tmpDir, 'bar.'), common.mustCall(handler));
+
+// Same test as above, but making sure that passing an options object doesn't
+// affect the way the callback function is handled.
+fs.mkdtemp(path.join(common.tmpDir, 'bar.'), {}, common.mustCall(handler));
+
+// Making sure that not passing a callback doesn't crash, as a default function
+// is passed internally.
assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));
+assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-'), {}));