mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 23:23:46 +00:00

If an asynchronous function is passed no callback function, there is no way to return the result. This patch throws an error if the callback passed is not valid or none passed at all. PR-URL: https://github.com/nodejs/node/pull/12562 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
26 lines
675 B
JavaScript
26 lines
675 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const cbTypeError = common.expectsError({code: 'ERR_INVALID_CALLBACK'});
|
|
const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}];
|
|
|
|
const { sep } = require('path');
|
|
|
|
common.refreshTmpDir();
|
|
|
|
function testMakeCallback(cb) {
|
|
return function() {
|
|
// fs.mkdtemp() calls makeCallback() on its third argument
|
|
fs.mkdtemp(`${common.tmpDir}${sep}`, {}, cb);
|
|
};
|
|
}
|
|
|
|
function invalidCallbackThrowsTests() {
|
|
callbackThrowValues.forEach((value) => {
|
|
assert.throws(testMakeCallback(value), cbTypeError);
|
|
});
|
|
}
|
|
|
|
invalidCallbackThrowsTests();
|