Commit 710ee827 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Promise.all and Promise.race should reject non-array parameter.

Promise.all and Promise.race should reject the returned Promise if an
invalid parameter is given.
Since they don't support iterable now, they should reject the Promise
if a non-array parameter is given.

BUG=347453
LOG=Y
R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/182613003

Patch from Yutaka Hirano <yhirano@chromium.org>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19754 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8bd37cb7
......@@ -248,6 +248,10 @@ function PromiseCast(x) {
function PromiseAll(values) {
var deferred = %_CallFunction(this, PromiseDeferred);
var resolutions = [];
if (!%_IsArray(values)) {
deferred.reject(MakeTypeError('invalid_argument'));
return deferred.promise;
}
try {
var count = values.length;
if (count === 0) {
......@@ -271,6 +275,10 @@ function PromiseAll(values) {
function PromiseOne(values) {
var deferred = %_CallFunction(this, PromiseDeferred);
if (!%_IsArray(values)) {
deferred.reject(MakeTypeError('invalid_argument'));
return deferred.promise;
}
try {
for (var i = 0; i < values.length; ++i) {
this.cast(values[i]).then(
......
......@@ -559,9 +559,9 @@ function assertAsyncDone(iteration) {
})();
(function() {
Promise.all({get length() { throw 666 }}).chain(
Promise.all({}).chain(
assertUnreachable,
function(r) { assertAsync(r === 666, "all/no-array") }
function(r) { assertAsync(r instanceof TypeError, "all/no-array") }
)
assertAsyncRan()
})();
......@@ -658,9 +658,9 @@ function assertAsyncDone(iteration) {
})();
(function() {
Promise.race({get length() { throw 666 }}).chain(
Promise.race({}).chain(
assertUnreachable,
function(r) { assertAsync(r === 666, "one/no-array") }
function(r) { assertAsync(r instanceof TypeError, "one/no-array") }
)
assertAsyncRan()
})();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment