Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing callback type in denodeify(), nbind() and nfcall() #735

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions q.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ if (typeof ReturnValue !== "undefined") {
};
}

// Validate callback
function checkCallbackForWrap(callback) {
if (typeof callback !== "function") {
throw new Error("Q can't wrap an undefined function");
}
}

// long stack traces

var STACK_JUMP_SEPARATOR = "From previous event:";
Expand Down Expand Up @@ -1896,6 +1903,8 @@ Promise.prototype.nfapply = function (args) {
*
*/
Q.nfcall = function (callback /*...args*/) {
checkCallbackForWrap(callback);

var args = array_slice(arguments, 1);
return Q(callback).nfapply(args);
};
Expand All @@ -1918,9 +1927,8 @@ Promise.prototype.nfcall = function (/*...args*/) {
*/
Q.nfbind =
Q.denodeify = function (callback /*...args*/) {
if (callback === undefined) {
throw new Error("Q can't wrap an undefined function");
}
checkCallbackForWrap(callback);

var baseArgs = array_slice(arguments, 1);
return function () {
var nodeArgs = baseArgs.concat(array_slice(arguments));
Expand All @@ -1939,6 +1947,8 @@ Promise.prototype.denodeify = function (/*...args*/) {
};

Q.nbind = function (callback, thisp /*...args*/) {
checkCallbackForWrap(callback);

var baseArgs = array_slice(arguments, 2);
return function () {
var nodeArgs = baseArgs.concat(array_slice(arguments));
Expand Down