From 710ee827b55c5b19418d296417f043037e3c687a Mon Sep 17 00:00:00 2001 From: "rossberg@chromium.org" Date: Mon, 10 Mar 2014 12:01:06 +0000 Subject: [PATCH] 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 . git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19754 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/promise.js | 8 ++++++++ test/mjsunit/harmony/promises.js | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/promise.js b/src/promise.js index 1f6c351..2c36d4d 100644 --- a/src/promise.js +++ b/src/promise.js @@ -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( diff --git a/test/mjsunit/harmony/promises.js b/test/mjsunit/harmony/promises.js index 38ccd7f..b513793 100644 --- a/test/mjsunit/harmony/promises.js +++ b/test/mjsunit/harmony/promises.js @@ -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() })(); -- 2.7.4