Changeset 286904 in webkit


Ignore:
Timestamp:
Dec 10, 2021 11:00:12 PM (7 months ago)
Author:
Chris Dumez
Message:

Implement AbortSignal.throwIfAborted
https://bugs.webkit.org/show_bug.cgi?id=234127

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Resync WPT test from upstream to gain test coverage and rebaseline it.

  • 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.throwIfAborted as per:

No new tests, updated / rebaselined existing test.

  • dom/AbortSignal.cpp:

(WebCore::AbortSignal::throwIfAborted):

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

Legend:

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

    r286898 r286904  
     12021-12-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement AbortSignal.throwIfAborted
     4        https://bugs.webkit.org/show_bug.cgi?id=234127
     5
     6        Reviewed by Darin Adler.
     7
     8        Resync WPT test from upstream to gain test coverage and rebaseline it.
     9
     10        * web-platform-tests/dom/abort/event.any-expected.txt:
     11        * web-platform-tests/dom/abort/event.any.js:
     12        * web-platform-tests/dom/abort/event.any.worker-expected.txt:
     13
    1142021-12-10  Alexey Shvayka  <ashvayka@apple.com>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any-expected.txt

    r285428 r286904  
    88PASS aborting AbortController without reason creates an "AbortError" DOMException
    99PASS AbortController abort(undefined) creates an "AbortError" DOMException
     10PASS AbortController abort(null) should set signal.reason
    1011PASS static aborting signal should have right properties
    1112PASS static aborting signal with reason should set signal.reason
     13PASS throwIfAborted() should throw abort.reason if signal aborted
     14PASS throwIfAborted() should throw primitive abort.reason if signal aborted
     15PASS throwIfAborted() should not throw if signal not aborted
    1216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js

    r285428 r286904  
    112112
    113113test(t => {
     114  const controller = new AbortController();
     115  const signal = controller.signal;
     116
     117  assert_true("reason" in signal, "signal has reason property");
     118  assert_equals(signal.reason, undefined, "signal.reason is initially undefined");
     119
     120  controller.abort(null);
     121
     122  assert_true(signal.aborted, "signal.aborted");
     123  assert_equals(signal.reason, null, "signal.reason");
     124}, "AbortController abort(null) should set signal.reason");
     125
     126test(t => {
    114127  const signal = AbortSignal.abort();
    115128
     
    127140}, "static aborting signal with reason should set signal.reason");
    128141
     142test(t => {
     143  const reason = new Error('boom');
     144  const signal = AbortSignal.abort(reason);
     145  assert_true(signal.aborted);
     146  assert_throws_exactly(reason, () => signal.throwIfAborted());
     147}, "throwIfAborted() should throw abort.reason if signal aborted");
     148
     149test(t => {
     150  const signal = AbortSignal.abort('hello');
     151  assert_true(signal.aborted);
     152  assert_throws_exactly('hello', () => signal.throwIfAborted());
     153}, "throwIfAborted() should throw primitive abort.reason if signal aborted");
     154
     155test(t => {
     156  const controller = new AbortController();
     157  assert_false(controller.signal.aborted);
     158  controller.signal.throwIfAborted();
     159}, "throwIfAborted() should not throw if signal not aborted");
     160
    129161done();
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.worker-expected.txt

    r285428 r286904  
    88PASS aborting AbortController without reason creates an "AbortError" DOMException
    99PASS AbortController abort(undefined) creates an "AbortError" DOMException
     10PASS AbortController abort(null) should set signal.reason
    1011PASS static aborting signal should have right properties
    1112PASS static aborting signal with reason should set signal.reason
     13PASS throwIfAborted() should throw abort.reason if signal aborted
     14PASS throwIfAborted() should throw primitive abort.reason if signal aborted
     15PASS throwIfAborted() should not throw if signal not aborted
    1216
  • trunk/Source/WebCore/ChangeLog

    r286898 r286904  
     12021-12-10  Chris Dumez  <cdumez@apple.com>
     2
     3        Implement AbortSignal.throwIfAborted
     4        https://bugs.webkit.org/show_bug.cgi?id=234127
     5
     6        Reviewed by Darin Adler.
     7
     8        Implement AbortSignal.throwIfAborted as per:
     9        - https://dom.spec.whatwg.org/#dom-abortsignal-throwifaborted
     10
     11        No new tests, updated / rebaselined existing test.
     12
     13        * dom/AbortSignal.cpp:
     14        (WebCore::AbortSignal::throwIfAborted):
     15        * dom/AbortSignal.h:
     16        * dom/AbortSignal.idl:
     17
    1182021-12-10  Alexey Shvayka  <ashvayka@apple.com>
    219
  • trunk/Source/WebCore/dom/AbortSignal.cpp

    r285747 r286904  
    3333#include "JSDOMException.h"
    3434#include "ScriptExecutionContext.h"
     35#include <JavaScriptCore/Exception.h>
    3536#include <wtf/IsoMallocInlines.h>
    3637
     
    114115}
    115116
     117void AbortSignal::throwIfAborted(JSC::JSGlobalObject& lexicalGlobalObject)
     118{
     119    if (!aborted())
     120        return;
     121
     122    auto& vm = lexicalGlobalObject.vm();
     123    auto scope = DECLARE_THROW_SCOPE(vm);
     124    throwException(&lexicalGlobalObject, scope, m_reason);
    116125}
     126
     127} // namespace WebCore
  • trunk/Source/WebCore/dom/AbortSignal.h

    r285747 r286904  
    6363    bool isFollowingSignal() const { return !!m_followingSignal; }
    6464
     65    void throwIfAborted(JSC::JSGlobalObject&);
     66
    6567private:
    6668    enum class Aborted : bool { No, Yes };
  • trunk/Source/WebCore/dom/AbortSignal.idl

    r285428 r286904  
    3636    readonly attribute boolean aborted;
    3737    readonly attribute any reason;
     38    [CallWith=GlobalObject] undefined throwIfAborted();
    3839
    3940    attribute EventHandler onabort;
Note: See TracChangeset for help on using the changeset viewer.