Reviewers: rossberg,

Description:
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

Please review this at https://codereview.chromium.org/182613003/

SVN Base: git://github.com/v8/v8.git@master

Affected files (+10, -2 lines):
  M src/promise.js
  M test/mjsunit/harmony/promises.js


Index: src/promise.js
diff --git a/src/promise.js b/src/promise.js
index 82aa99027a1305ac8bf6b95672cccd89504173cd..297bf1e720fcb9fdeb89be63e1376dc89d1b0d35 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]).chain(
Index: test/mjsunit/harmony/promises.js
diff --git a/test/mjsunit/harmony/promises.js b/test/mjsunit/harmony/promises.js index 38ccd7fb2bdc27a645efa5e25c1c03b0daaa2446..70573613d579143682f98d46b99dca6bd353f6a9 100644
--- a/test/mjsunit/harmony/promises.js
+++ b/test/mjsunit/harmony/promises.js
@@ -561,7 +561,7 @@ function assertAsyncDone(iteration) {
 (function() {
   Promise.all({get length() { throw 666 }}).chain(
     assertUnreachable,
-    function(r) { assertAsync(r === 666, "all/no-array") }
+    function(r) { assertAsync(r instanceof TypeError, "all/no-array") }
   )
   assertAsyncRan()
 })();
@@ -660,7 +660,7 @@ function assertAsyncDone(iteration) {
 (function() {
   Promise.race({get length() { throw 666 }}).chain(
     assertUnreachable,
-    function(r) { assertAsync(r === 666, "one/no-array") }
+    function(r) { assertAsync(r instanceof TypeError, "one/no-array") }
   )
   assertAsyncRan()
 })();


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to