node/test/parallel/test-fs-make-callback.js
Sakthipriyan Vairamani 9359de9dd2 fs: make callback mandatory to all async functions
The "fs" module has two functions called `maybeCallback` and
`makeCallback`, as of now.

The `maybeCallback` creates a default function to report errors, if the
parameter passed is not a function object. Basically, if the callback
is omitted in some cases, this function is used to create a default
callback function.

The `makeCallback`, OTOH, creates a default function only if the
parameter passed is `undefined`, and if it is not a function object it
will throw an `Error`.

This patch removes the `maybeCallback` function and makes the callback
function argument mandatory for all the async functions.

PR-URL: https://github.com/nodejs/node/pull/7168
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
2016-07-22 02:34:01 +05:30

26 lines
599 B
JavaScript

'use strict';
require('../common');
var assert = require('assert');
var fs = require('fs');
function test(cb) {
return function() {
// fs.stat() calls makeCallback() on its second argument
fs.stat(__filename, cb);
};
}
// Verify the case where a callback function is provided
assert.doesNotThrow(test(function() {}));
// Anything else should throw
assert.throws(test(null));
assert.throws(test(true));
assert.throws(test(false));
assert.throws(test(1));
assert.throws(test(0));
assert.throws(test('foo'));
assert.throws(test(/foo/));
assert.throws(test([]));
assert.throws(test({}));