[ES6] Promise.{all,race} no longer use @@species
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jul 2016 07:26:34 +0000 (07:26 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Jul 2016 07:26:34 +0000 (07:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159615

Reviewed by Keith Miller.

As per the latest ES draft, Promise.{all,race} no longer use @@species.
So, this patch drops FIXMEs.

* builtins/PromiseConstructor.js:
(all):
(race):
* tests/stress/ignore-promise-species.js: Added.
(shouldBe):
(DerivedPromise.prototype.get Symbol):
(DerivedPromise):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@203052 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/builtins/PromiseConstructor.js
Source/JavaScriptCore/tests/stress/ignore-promise-species.js [new file with mode: 0644]

index b28d19f..5f62f55 100644 (file)
@@ -1,3 +1,21 @@
+2016-07-10  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [ES6] Promise.{all,race} no longer use @@species
+        https://bugs.webkit.org/show_bug.cgi?id=159615
+
+        Reviewed by Keith Miller.
+
+        As per the latest ES draft, Promise.{all,race} no longer use @@species.
+        So, this patch drops FIXMEs.
+
+        * builtins/PromiseConstructor.js:
+        (all):
+        (race):
+        * tests/stress/ignore-promise-species.js: Added.
+        (shouldBe):
+        (DerivedPromise.prototype.get Symbol):
+        (DerivedPromise):
+
 2016-07-10  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r203037.
 2016-07-10  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r203037.
index 77ce57c..8cf1999 100644 (file)
@@ -30,11 +30,7 @@ function all(iterable)
     if (!@isObject(this))
         throw new @TypeError("|this| is not a object");
 
     if (!@isObject(this))
         throw new @TypeError("|this| is not a object");
 
-    // FIXME: Fix this code when @@species well-known symbol is landed.
-    // https://bugs.webkit.org/show_bug.cgi?id=146624
-    var constructor = this;
-
-    var promiseCapability = @newPromiseCapability(constructor);
+    var promiseCapability = @newPromiseCapability(this);
 
     var values = [];
     var index = 0;
 
     var values = [];
     var index = 0;
@@ -62,7 +58,7 @@ function all(iterable)
     try {
         for (var value of iterable) {
             @putByValDirect(values, index, @undefined);
     try {
         for (var value of iterable) {
             @putByValDirect(values, index, @undefined);
-            var nextPromise = constructor.resolve(value);
+            var nextPromise = this.resolve(value);
             var resolveElement = newResolveElement(index);
             ++remainingElementsCount;
             nextPromise.then(resolveElement, promiseCapability.@reject);
             var resolveElement = newResolveElement(index);
             ++remainingElementsCount;
             nextPromise.then(resolveElement, promiseCapability.@reject);
@@ -86,15 +82,11 @@ function race(iterable)
     if (!@isObject(this))
         throw new @TypeError("|this| is not a object");
 
     if (!@isObject(this))
         throw new @TypeError("|this| is not a object");
 
-    // FIXME: Fix this code when @@species well-known symbol is landed.
-    // https://bugs.webkit.org/show_bug.cgi?id=146624
-    var constructor = this;
-
-    var promiseCapability = @newPromiseCapability(constructor);
+    var promiseCapability = @newPromiseCapability(this);
 
     try {
         for (var value of iterable) {
 
     try {
         for (var value of iterable) {
-            var nextPromise = constructor.resolve(value);
+            var nextPromise = this.resolve(value);
             nextPromise.then(promiseCapability.@resolve, promiseCapability.@reject);
         }
     } catch (error) {
             nextPromise.then(promiseCapability.@resolve, promiseCapability.@reject);
         }
     } catch (error) {
diff --git a/Source/JavaScriptCore/tests/stress/ignore-promise-species.js b/Source/JavaScriptCore/tests/stress/ignore-promise-species.js
new file mode 100644 (file)
index 0000000..b5b25cf
--- /dev/null
@@ -0,0 +1,13 @@
+function shouldBe(actual, expected) {
+    if (actual !== expected)
+        throw new Error('bad value: ' + actual);
+}
+
+class DerivedPromise extends Promise {
+    static get [Symbol.species]() {
+        return Promise;
+    }
+}
+
+shouldBe(DerivedPromise.all([ 1, 2, 3]) instanceof DerivedPromise, true);
+shouldBe(DerivedPromise.race([ 1, 2, 3]) instanceof DerivedPromise, true);