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

Add check for array parameter to Q.all() #667

Open
wants to merge 7 commits into
base: v1
Choose a base branch
from

Conversation

vingiarrusso
Copy link

Addresses #656.

This pull request adds a check to the Q.all() function to make sure it is being passed an array or array-like object.

@@ -1502,6 +1506,10 @@ Promise.prototype.keys = function () {
Q.all = all;
function all(promises) {
return when(promises, function (promises) {
if (!isArray(arguments[0]) || arguments.length !== 1) {
throw Error("All must be passed an array of promises.");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind replacing All with all() to make the error message more clear?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeError is appropriate here.

@arikon
Copy link

arikon commented Mar 22, 2015

@domenic 👍

@@ -1502,6 +1502,10 @@ Promise.prototype.keys = function () {
Q.all = all;
function all(promises) {
return when(promises, function (promises) {
if (typeof arguments[0].length === "undefined") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this as opposed to Array.isArray(promises)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Array.isArray, if all() gets passed the arguments object it would be rejected.

@benjamingr
Copy link
Collaborator

What about iterables?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants