mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 05:53:11 +00:00

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>
26 lines
599 B
JavaScript
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({}));
|