-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: v1
Are you sure you want to change the base?
Conversation
…must take an array, we need to make sure that it isnt passed the arguments object directly
@@ -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."); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeError is appropriate here.
@domenic 👍 |
… array_slice from promised()
@@ -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") { |
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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.
What about iterables? |
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.