Changeset 274773 in webkit


Ignore:
Timestamp:
Mar 22, 2021 12:25:16 PM (16 months ago)
Author:
Chris Dumez
Message:

Implement AbortSignal.abort()
https://bugs.webkit.org/show_bug.cgi?id=223071
<rdar://problem/75575483>

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Resync WPT test from upstream a8cbe9c712ad032d36 to gain test coverage.

  • web-platform-tests/dom/abort/event.any-expected.txt:
  • web-platform-tests/dom/abort/event.any.js:
  • web-platform-tests/dom/abort/event.any.worker-expected.txt:

Source/WebCore:

Implement AbortSignal.abort() which creates and returns an already aborted AbortSignal:

No new tests, covered by updated test.

  • dom/AbortSignal.cpp:

(WebCore::AbortSignal::createAborted):
(WebCore::AbortSignal::AbortSignal):

  • dom/AbortSignal.h:
  • dom/AbortSignal.idl:
Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r274748 r274773  
     12021-03-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement AbortSignal.abort()
     4        https://bugs.webkit.org/show_bug.cgi?id=223071
     5        <rdar://problem/75575483>
     6
     7        Reviewed by Darin Adler.
     8
     9        Resync WPT test from upstream a8cbe9c712ad032d36 to gain test coverage.
     10
     11        * web-platform-tests/dom/abort/event.any-expected.txt:
     12        * web-platform-tests/dom/abort/event.any.js:
     13        * web-platform-tests/dom/abort/event.any.worker-expected.txt:
     14
    1152021-03-19  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any-expected.txt

    r267660 r274773  
    55PASS event handler should not be called if added after controller.abort()
    66PASS the abort event should have the right properties
     7PASS the AbortSignal.abort() static returns an already aborted signal
    78
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js

    r229544 r274773  
    6565}, "the abort event should have the right properties");
    6666
     67test(t => {
     68  const signal = AbortSignal.abort();
     69  assert_true(signal.aborted);
     70}, "the AbortSignal.abort() static returns an already aborted signal");
     71
    6772done();
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.worker-expected.txt

    r267660 r274773  
    55PASS event handler should not be called if added after controller.abort()
    66PASS the abort event should have the right properties
     7PASS the AbortSignal.abort() static returns an already aborted signal
    78
  • trunk/Source/WebCore/ChangeLog

    r274772 r274773  
     12021-03-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement AbortSignal.abort()
     4        https://bugs.webkit.org/show_bug.cgi?id=223071
     5        <rdar://problem/75575483>
     6
     7        Reviewed by Darin Adler.
     8
     9        Implement AbortSignal.abort() which creates and returns an already aborted AbortSignal:
     10        - https://github.com/whatwg/dom/pull/960
     11        - https://github.com/web-platform-tests/wpt/pull/28003
     12
     13        No new tests, covered by updated test.
     14
     15        * dom/AbortSignal.cpp:
     16        (WebCore::AbortSignal::createAborted):
     17        (WebCore::AbortSignal::AbortSignal):
     18        * dom/AbortSignal.h:
     19        * dom/AbortSignal.idl:
     20
    1212021-03-22  Wenson Hsieh  <wenson_hsieh@apple.com>
    222
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r264853 r274773  
    180180    if (init.signal) {
    181181        if (auto* signal = JSAbortSignal::toWrapped(scriptExecutionContext()->vm(), init.signal))
    182             m_signal->follow(*signal);
     182            m_signal->signalFollow(*signal);
    183183        else if (!init.signal.isUndefinedOrNull())  {
    184184            if (auto exception = processInvalidSignal(*scriptExecutionContext()))
     
    215215    if (init.signal && !init.signal.isUndefined()) {
    216216        if (auto* signal = JSAbortSignal::toWrapped(scriptExecutionContext()->vm(), init.signal))
    217             m_signal->follow(*signal);
     217            m_signal->signalFollow(*signal);
    218218        else if (!init.signal.isNull()) {
    219219            if (auto exception = processInvalidSignal(*scriptExecutionContext()))
     
    222222
    223223    } else
    224         m_signal->follow(input.m_signal.get());
     224        m_signal->signalFollow(input.m_signal.get());
    225225
    226226    if (init.hasMembers()) {
     
    325325    auto clone = adoptRef(*new FetchRequest(context, WTF::nullopt, FetchHeaders::create(m_headers.get()), ResourceRequest { m_request }, FetchOptions { m_options}, String { m_referrer }));
    326326    clone->cloneBody(*this);
    327     clone->m_signal->follow(m_signal);
     327    clone->m_signal->signalFollow(m_signal);
    328328    return clone;
    329329}
  • trunk/Source/WebCore/dom/AbortController.cpp

    r243887 r274773  
    5353void AbortController::abort()
    5454{
    55     m_signal->abort();
     55    m_signal->signalAbort();
    5656}
    5757
  • trunk/Source/WebCore/dom/AbortSignal.cpp

    r266177 r274773  
    4242}
    4343
    44 AbortSignal::AbortSignal(ScriptExecutionContext& context)
     44// https://dom.spec.whatwg.org/#dom-abortsignal-abort
     45Ref<AbortSignal> AbortSignal::abort(ScriptExecutionContext& context)
     46{
     47    return adoptRef(*new AbortSignal(context, Aborted::Yes));
     48}
     49
     50AbortSignal::AbortSignal(ScriptExecutionContext& context, Aborted aborted)
    4551    : ContextDestructionObserver(&context)
     52    , m_aborted(aborted == Aborted::Yes)
    4653{
    4754}
    4855
    4956// https://dom.spec.whatwg.org/#abortsignal-signal-abort
    50 void AbortSignal::abort()
     57void AbortSignal::signalAbort()
    5158{
    5259    // 1. If signal's aborted flag is set, then return.
     
    5865
    5966    auto protectedThis = makeRef(*this);
    60     auto algorithms = WTFMove(m_algorithms);
     67    auto algorithms = std::exchange(m_algorithms, { });
    6168    for (auto& algorithm : algorithms)
    6269        algorithm();
     
    6774
    6875// https://dom.spec.whatwg.org/#abortsignal-follow
    69 void AbortSignal::follow(AbortSignal& signal)
     76void AbortSignal::signalFollow(AbortSignal& signal)
    7077{
    7178    if (aborted())
     
    7380
    7481    if (signal.aborted()) {
    75         abort();
     82        signalAbort();
    7683        return;
    7784    }
     
    8087    m_followingSignal = makeWeakPtr(signal);
    8188    signal.addAlgorithm([weakThis = makeWeakPtr(this)] {
    82         if (!weakThis)
    83             return;
    84         weakThis->abort();
     89        if (weakThis)
     90            weakThis->signalAbort();
    8591    });
    8692}
  • trunk/Source/WebCore/dom/AbortSignal.h

    r271806 r274773  
    4444    static Ref<AbortSignal> create(ScriptExecutionContext&);
    4545
     46    static Ref<AbortSignal> abort(ScriptExecutionContext&);
     47
    4648    static bool whenSignalAborted(AbortSignal&, Ref<AbortAlgorithm>&&);
    4749
    48     void abort();
     50    void signalAbort();
     51    void signalFollow(AbortSignal&);
    4952
    5053    bool aborted() const { return m_aborted; }
     
    5659    void addAlgorithm(Algorithm&& algorithm) { m_algorithms.append(WTFMove(algorithm)); }
    5760
    58     void follow(AbortSignal&);
    59 
    6061    bool isFollowingSignal() const { return !!m_followingSignal; }
    6162
    6263private:
    63     explicit AbortSignal(ScriptExecutionContext&);
     64    enum class Aborted : bool { No, Yes };
     65    explicit AbortSignal(ScriptExecutionContext&, Aborted = Aborted::No);
    6466
     67    // EventTarget.
    6568    EventTargetInterface eventTargetInterface() const final { return AbortSignalEventTargetInterfaceType; }
    6669    ScriptExecutionContext* scriptExecutionContext() const final { return ContextDestructionObserver::scriptExecutionContext(); }
  • trunk/Source/WebCore/dom/AbortSignal.idl

    r266311 r274773  
    3232    [ PrivateIdentifier ] static undefined whenSignalAborted(AbortSignal object, AbortAlgorithm algorithm);
    3333
     34    [NewObject, CallWith=ScriptExecutionContext] static AbortSignal abort();
    3435    readonly attribute boolean aborted;
    3536    attribute EventHandler onabort;
Note: See TracChangeset for help on using the changeset viewer.