Title: [274773] trunk
Revision
274773
Author
[email protected]
Date
2021-03-22 12:25:16 -0700 (Mon, 22 Mar 2021)

Log 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:
- https://github.com/whatwg/dom/pull/960
- https://github.com/web-platform-tests/wpt/pull/28003

No new tests, covered by updated test.

* dom/AbortSignal.cpp:
(WebCore::AbortSignal::createAborted):
(WebCore::AbortSignal::AbortSignal):
* dom/AbortSignal.h:
* dom/AbortSignal.idl:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (274772 => 274773)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-03-22 19:25:16 UTC (rev 274773)
@@ -1,3 +1,17 @@
+2021-03-22  Chris Dumez  <[email protected]>
+
+        Implement AbortSignal.abort()
+        https://bugs.webkit.org/show_bug.cgi?id=223071
+        <rdar://problem/75575483>
+
+        Reviewed by Darin Adler.
+
+        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:
+
 2021-03-19  Chris Dumez  <[email protected]>
 
         Resync webaudio web-platform-tests from upstream

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any-expected.txt (274772 => 274773)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any-expected.txt	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any-expected.txt	2021-03-22 19:25:16 UTC (rev 274773)
@@ -4,4 +4,5 @@
 PASS controller.abort() should do nothing the second time it is called
 PASS event handler should not be called if added after controller.abort()
 PASS the abort event should have the right properties
+PASS the AbortSignal.abort() static returns an already aborted signal
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js (274772 => 274773)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js	2021-03-22 19:25:16 UTC (rev 274773)
@@ -64,4 +64,9 @@
   controller.abort();
 }, "the abort event should have the right properties");
 
+test(t => {
+  const signal = AbortSignal.abort();
+  assert_true(signal.aborted);
+}, "the AbortSignal.abort() static returns an already aborted signal");
+
 done();

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.worker-expected.txt (274772 => 274773)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.worker-expected.txt	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.worker-expected.txt	2021-03-22 19:25:16 UTC (rev 274773)
@@ -4,4 +4,5 @@
 PASS controller.abort() should do nothing the second time it is called
 PASS event handler should not be called if added after controller.abort()
 PASS the abort event should have the right properties
+PASS the AbortSignal.abort() static returns an already aborted signal
 

Modified: trunk/Source/WebCore/ChangeLog (274772 => 274773)


--- trunk/Source/WebCore/ChangeLog	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/Source/WebCore/ChangeLog	2021-03-22 19:25:16 UTC (rev 274773)
@@ -1,3 +1,23 @@
+2021-03-22  Chris Dumez  <[email protected]>
+
+        Implement AbortSignal.abort()
+        https://bugs.webkit.org/show_bug.cgi?id=223071
+        <rdar://problem/75575483>
+
+        Reviewed by Darin Adler.
+
+        Implement AbortSignal.abort() which creates and returns an already aborted AbortSignal:
+        - https://github.com/whatwg/dom/pull/960
+        - https://github.com/web-platform-tests/wpt/pull/28003
+
+        No new tests, covered by updated test.
+
+        * dom/AbortSignal.cpp:
+        (WebCore::AbortSignal::createAborted):
+        (WebCore::AbortSignal::AbortSignal):
+        * dom/AbortSignal.h:
+        * dom/AbortSignal.idl:
+
 2021-03-22  Wenson Hsieh  <[email protected]>
 
         [macOS] Context menu should account for image overlay content

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (274772 => 274773)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2021-03-22 19:25:16 UTC (rev 274773)
@@ -179,7 +179,7 @@
 
     if (init.signal) {
         if (auto* signal = JSAbortSignal::toWrapped(scriptExecutionContext()->vm(), init.signal))
-            m_signal->follow(*signal);
+            m_signal->signalFollow(*signal);
         else if (!init.signal.isUndefinedOrNull())  {
             if (auto exception = processInvalidSignal(*scriptExecutionContext()))
                 return WTFMove(*exception);
@@ -214,7 +214,7 @@
 
     if (init.signal && !init.signal.isUndefined()) {
         if (auto* signal = JSAbortSignal::toWrapped(scriptExecutionContext()->vm(), init.signal))
-            m_signal->follow(*signal);
+            m_signal->signalFollow(*signal);
         else if (!init.signal.isNull()) {
             if (auto exception = processInvalidSignal(*scriptExecutionContext()))
                 return WTFMove(*exception);
@@ -221,7 +221,7 @@
         }
 
     } else
-        m_signal->follow(input.m_signal.get());
+        m_signal->signalFollow(input.m_signal.get());
 
     if (init.hasMembers()) {
         auto fillResult = init.headers ? m_headers->fill(*init.headers) : m_headers->fill(input.headers());
@@ -324,7 +324,7 @@
 
     auto clone = adoptRef(*new FetchRequest(context, WTF::nullopt, FetchHeaders::create(m_headers.get()), ResourceRequest { m_request }, FetchOptions { m_options}, String { m_referrer }));
     clone->cloneBody(*this);
-    clone->m_signal->follow(m_signal);
+    clone->m_signal->signalFollow(m_signal);
     return clone;
 }
 

Modified: trunk/Source/WebCore/dom/AbortController.cpp (274772 => 274773)


--- trunk/Source/WebCore/dom/AbortController.cpp	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/Source/WebCore/dom/AbortController.cpp	2021-03-22 19:25:16 UTC (rev 274773)
@@ -52,7 +52,7 @@
 
 void AbortController::abort()
 {
-    m_signal->abort();
+    m_signal->signalAbort();
 }
 
 }

Modified: trunk/Source/WebCore/dom/AbortSignal.cpp (274772 => 274773)


--- trunk/Source/WebCore/dom/AbortSignal.cpp	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/Source/WebCore/dom/AbortSignal.cpp	2021-03-22 19:25:16 UTC (rev 274773)
@@ -41,13 +41,20 @@
     return adoptRef(*new AbortSignal(context));
 }
 
-AbortSignal::AbortSignal(ScriptExecutionContext& context)
+// https://dom.spec.whatwg.org/#dom-abortsignal-abort
+Ref<AbortSignal> AbortSignal::abort(ScriptExecutionContext& context)
+{
+    return adoptRef(*new AbortSignal(context, Aborted::Yes));
+}
+
+AbortSignal::AbortSignal(ScriptExecutionContext& context, Aborted aborted)
     : ContextDestructionObserver(&context)
+    , m_aborted(aborted == Aborted::Yes)
 {
 }
 
 // https://dom.spec.whatwg.org/#abortsignal-signal-abort
-void AbortSignal::abort()
+void AbortSignal::signalAbort()
 {
     // 1. If signal's aborted flag is set, then return.
     if (m_aborted)
@@ -57,7 +64,7 @@
     m_aborted = true;
 
     auto protectedThis = makeRef(*this);
-    auto algorithms = WTFMove(m_algorithms);
+    auto algorithms = std::exchange(m_algorithms, { });
     for (auto& algorithm : algorithms)
         algorithm();
 
@@ -66,13 +73,13 @@
 }
 
 // https://dom.spec.whatwg.org/#abortsignal-follow
-void AbortSignal::follow(AbortSignal& signal)
+void AbortSignal::signalFollow(AbortSignal& signal)
 {
     if (aborted())
         return;
 
     if (signal.aborted()) {
-        abort();
+        signalAbort();
         return;
     }
 
@@ -79,9 +86,8 @@
     ASSERT(!m_followingSignal);
     m_followingSignal = makeWeakPtr(signal);
     signal.addAlgorithm([weakThis = makeWeakPtr(this)] {
-        if (!weakThis)
-            return;
-        weakThis->abort();
+        if (weakThis)
+            weakThis->signalAbort();
     });
 }
 

Modified: trunk/Source/WebCore/dom/AbortSignal.h (274772 => 274773)


--- trunk/Source/WebCore/dom/AbortSignal.h	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/Source/WebCore/dom/AbortSignal.h	2021-03-22 19:25:16 UTC (rev 274773)
@@ -43,9 +43,12 @@
 public:
     static Ref<AbortSignal> create(ScriptExecutionContext&);
 
+    static Ref<AbortSignal> abort(ScriptExecutionContext&);
+
     static bool whenSignalAborted(AbortSignal&, Ref<AbortAlgorithm>&&);
 
-    void abort();
+    void signalAbort();
+    void signalFollow(AbortSignal&);
 
     bool aborted() const { return m_aborted; }
 
@@ -55,13 +58,13 @@
     using Algorithm = Function<void()>;
     void addAlgorithm(Algorithm&& algorithm) { m_algorithms.append(WTFMove(algorithm)); }
 
-    void follow(AbortSignal&);
-
     bool isFollowingSignal() const { return !!m_followingSignal; }
 
 private:
-    explicit AbortSignal(ScriptExecutionContext&);
+    enum class Aborted : bool { No, Yes };
+    explicit AbortSignal(ScriptExecutionContext&, Aborted = Aborted::No);
 
+    // EventTarget.
     EventTargetInterface eventTargetInterface() const final { return AbortSignalEventTargetInterfaceType; }
     ScriptExecutionContext* scriptExecutionContext() const final { return ContextDestructionObserver::scriptExecutionContext(); }
     void refEventTarget() final { ref(); }

Modified: trunk/Source/WebCore/dom/AbortSignal.idl (274772 => 274773)


--- trunk/Source/WebCore/dom/AbortSignal.idl	2021-03-22 19:06:02 UTC (rev 274772)
+++ trunk/Source/WebCore/dom/AbortSignal.idl	2021-03-22 19:25:16 UTC (rev 274773)
@@ -31,6 +31,7 @@
 ] interface AbortSignal : EventTarget {
     [ PrivateIdentifier ] static undefined whenSignalAborted(AbortSignal object, AbortAlgorithm algorithm);
 
+    [NewObject, CallWith=ScriptExecutionContext] static AbortSignal abort();
     readonly attribute boolean aborted;
     attribute EventHandler onabort;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to