⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245869 in webkit


Ignore:
Timestamp:
May 29, 2019, 2:28:09 PM (7 years ago)
Author:
dino@apple.com
Message:

Implement Promise.allSettled
https://bugs.webkit.org/show_bug.cgi?id=197600
<rdar://problem/50483885>

Reviewed by Keith Miller.

JSTests:

Start testing Promise.allSettled. We pass most of the tests.
The ones that fail are similar to the Promise.all tests we already fail.

  • test262/config.yaml: Remove Promise.allSettled from skipped tests.
  • test262/expectations.yaml: Add new expectations for allSettled tests.

Source/JavaScriptCore:

Implement Promise.allSettled
https://github.com/tc39/proposal-promise-allSettled/

Shipping in Firefox since version 68.
Shipping in V8 since https://chromium.googlesource.com/v8/v8.git/+/1f6d27e8df819b448712dface6ad367fb8de426b

  • builtins/PromiseConstructor.js:

(allSettled.newResolveRejectElements.resolveElement):
(allSettled.newResolveRejectElements.rejectElement):
(allSettled.newResolveRejectElements):
(allSettled): Added.

  • runtime/JSPromiseConstructor.cpp: Add ref to allSettled.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r245815 r245869  
     12019-05-28  Dean Jackson  <dino@apple.com>
     2
     3        Implement Promise.allSettled
     4        https://bugs.webkit.org/show_bug.cgi?id=197600
     5        <rdar://problem/50483885>
     6
     7        Reviewed by Keith Miller.
     8
     9        Start testing Promise.allSettled. We pass most of the tests.
     10        The ones that fail are similar to the Promise.all tests we already fail.
     11
     12        * test262/config.yaml: Remove Promise.allSettled from skipped tests.
     13        * test262/expectations.yaml: Add new expectations for allSettled tests.
     14
    1152019-05-28  Michael Saboff  <msaboff@apple.com>
    216
  • trunk/JSTests/test262/config.yaml

    r245201 r245869  
    3232    - Intl.RelativeTimeFormat
    3333    - Intl.Segmenter
    34     # https://bugs.webkit.org/show_bug.cgi?id=196332
    35     - Promise.allSettled
    3634  files:
    3735    - test/built-ins/Array/prototype/reverse/length-exceeding-integer-limit-with-object.js
  • trunk/JSTests/test262/expectations.yaml

    r245655 r245869  
    10871087  default: 'Test262Error: Got `resolve` only once for each iterated value Expected SameValue(«4», «1») to be true'
    10881088  strict mode: 'Test262Error: Got `resolve` only once for each iterated value Expected SameValue(«4», «1») to be true'
     1089test/built-ins/Promise/all/invoke-resolve-get-once-no-calls.js:
     1090  default: 'Test262Error: Got `resolve` only once for each iterated value Expected SameValue(«0», «1») to be true'
     1091  strict mode: 'Test262Error: Got `resolve` only once for each iterated value Expected SameValue(«0», «1») to be true'
    10891092test/built-ins/Promise/all/resolve-element-function-nonconstructor.js:
     1093  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
     1094  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
     1095test/built-ins/Promise/allSettled/invoke-resolve-get-error-close.js:
     1096  default: 'Test262Error: Expected SameValue(«1», «0») to be true'
     1097  strict mode: 'Test262Error: Expected SameValue(«1», «0») to be true'
     1098test/built-ins/Promise/allSettled/invoke-resolve-get-once-multiple-calls.js:
     1099  default: 'Test262Error: Got `resolve` only once for each iterated value Expected SameValue(«4», «1») to be true'
     1100  strict mode: 'Test262Error: Got `resolve` only once for each iterated value Expected SameValue(«4», «1») to be true'
     1101test/built-ins/Promise/allSettled/invoke-resolve-get-once-no-calls.js:
     1102  default: 'Test262Error: Got `resolve` only once for each iterated value Expected SameValue(«0», «1») to be true'
     1103  strict mode: 'Test262Error: Got `resolve` only once for each iterated value Expected SameValue(«0», «1») to be true'
     1104test/built-ins/Promise/allSettled/reject-element-function-nonconstructor.js:
     1105  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
     1106  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
     1107test/built-ins/Promise/allSettled/resolve-element-function-nonconstructor.js:
    10901108  default: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
    10911109  strict mode: 'Test262Error: Expected a TypeError to be thrown but no exception was thrown at all'
  • trunk/Source/JavaScriptCore/ChangeLog

    r245815 r245869  
     12019-05-28  Dean Jackson  <dino@apple.com>
     2
     3        Implement Promise.allSettled
     4        https://bugs.webkit.org/show_bug.cgi?id=197600
     5        <rdar://problem/50483885>
     6
     7        Reviewed by Keith Miller.
     8
     9        Implement Promise.allSettled
     10        https://github.com/tc39/proposal-promise-allSettled/
     11
     12        Shipping in Firefox since version 68.
     13        Shipping in V8 since https://chromium.googlesource.com/v8/v8.git/+/1f6d27e8df819b448712dface6ad367fb8de426b
     14
     15        * builtins/PromiseConstructor.js:
     16        (allSettled.newResolveRejectElements.resolveElement):
     17        (allSettled.newResolveRejectElements.rejectElement):
     18        (allSettled.newResolveRejectElements):
     19        (allSettled): Added.
     20        * runtime/JSPromiseConstructor.cpp: Add ref to allSettled.
     21
    1222019-05-28  Michael Saboff  <msaboff@apple.com>
    223
  • trunk/Source/JavaScriptCore/builtins/PromiseConstructor.js

    r221417 r245869  
    7676}
    7777
     78function allSettled(iterable)
     79{
     80    "use strict";
     81
     82    if (!@isObject(this))
     83        @throwTypeError("|this| is not a object");
     84
     85    var promiseCapability = @newPromiseCapability(this);
     86
     87    var values = [];
     88    var remainingElementsCount = 1;
     89    var index = 0;
     90
     91    function newResolveRejectElements(index)
     92    {
     93        var alreadyCalled = false;
     94
     95        var resolveElement = function @resolve(x)
     96        {
     97            if (alreadyCalled)
     98                return @undefined;
     99            alreadyCalled = true;
     100
     101            var obj = {
     102                status: "fulfilled",
     103                value: x
     104            };
     105
     106            @putByValDirect(values, index, obj);
     107
     108            --remainingElementsCount;
     109            if (remainingElementsCount === 0)
     110                return promiseCapability.@resolve.@call(@undefined, values);
     111
     112            return @undefined;
     113        };
     114
     115        var rejectElement = function @reject(x)
     116        {
     117            if (alreadyCalled)
     118                return @undefined;
     119            alreadyCalled = true;
     120
     121            var obj = {
     122                status: "rejected",
     123                reason: x
     124            };
     125
     126            @putByValDirect(values, index, obj);
     127
     128            --remainingElementsCount;
     129            if (remainingElementsCount === 0)
     130                return promiseCapability.@resolve.@call(@undefined, values);
     131
     132            return @undefined;
     133        };
     134
     135        return [resolveElement, rejectElement];
     136    }
     137
     138    try {
     139        for (var value of iterable) {
     140            @putByValDirect(values, index, @undefined);
     141            var nextPromise = this.resolve(value);
     142            var [resolveElement, rejectElement] = newResolveRejectElements(index);
     143            ++remainingElementsCount;
     144            nextPromise.then(resolveElement, rejectElement);
     145            ++index;
     146        }
     147
     148        --remainingElementsCount;
     149        if (remainingElementsCount === 0)
     150            promiseCapability.@resolve.@call(@undefined, values);
     151    } catch (error) {
     152        promiseCapability.@reject.@call(@undefined, error);
     153    }
     154
     155    return promiseCapability.@promise;
     156}
     157
    78158function race(iterable)
    79159{
  • trunk/Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp

    r242650 r245869  
    5858  race            JSBuiltin             DontEnum|Function 1
    5959  all             JSBuiltin             DontEnum|Function 1
     60  allSettled      JSBuiltin             DontEnum|Function 1
    6061@end
    6162*/
Note: See TracChangeset for help on using the changeset viewer.