Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (285427 => 285428)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-11-08 21:36:35 UTC (rev 285428)
@@ -1,3 +1,18 @@
+2021-11-08 Chris Dumez <[email protected]>
+
+ Add abort reason to AbortSignal
+ https://bugs.webkit.org/show_bug.cgi?id=232299
+ <rdar://problem/84921281>
+
+ Reviewed by Alexey Shvayka.
+
+ Import https://github.com/web-platform-tests/wpt/commit/9c7dfd2809b6c3a209a2c4df43c1d6816e6bfc1b from
+ upstream WPT to gain layout test coverage and rebaseline the test.
+
+ * 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-11-08 Tim Nguyen <[email protected]>
Stop skipping html/semantics/interactive-elements/the-details-element/toggleEvent.html in import-expectations.json
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any-expected.txt (285427 => 285428)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any-expected.txt 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any-expected.txt 2021-11-08 21:36:35 UTC (rev 285428)
@@ -4,4 +4,9 @@
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 AbortController abort(reason) should set signal.reason
+PASS aborting AbortController without reason creates an "AbortError" DOMException
+PASS AbortController abort(undefined) creates an "AbortError" DOMException
+PASS static aborting signal should have right properties
+PASS static aborting signal with reason should set signal.reason
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js (285427 => 285428)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.js 2021-11-08 21:36:35 UTC (rev 285428)
@@ -4,6 +4,8 @@
let state = "begin";
assert_false(s.aborted);
+ assert_true("reason" in s, "signal has reason property");
+ assert_equals(s.reason, undefined, "signal.reason is initially undefined");
s.addEventListener("abort",
t.step_func(e => {
@@ -15,6 +17,8 @@
assert_equals(state, "aborted");
assert_true(s.aborted);
+ assert_true(s.reason instanceof DOMException, "signal.reason is DOMException");
+ assert_equals(s.reason.name, "AbortError", "signal.reason is AbortError");
c.abort();
}, "AbortController abort() should fire event synchronously");
@@ -64,4 +68,62 @@
controller.abort();
}, "the abort event should have the right properties");
+test(t => {
+ const controller = new AbortController();
+ const signal = controller.signal;
+
+ assert_true("reason" in signal, "signal has reason property");
+ assert_equals(signal.reason, undefined, "signal.reason is initially undefined");
+
+ const reason = Error("hello");
+ controller.abort(reason);
+
+ assert_true(signal.aborted, "signal.aborted");
+ assert_equals(signal.reason, reason, "signal.reason");
+}, "AbortController abort(reason) should set signal.reason");
+
+test(t => {
+ const controller = new AbortController();
+ const signal = controller.signal;
+
+ assert_true("reason" in signal, "signal has reason property");
+ assert_equals(signal.reason, undefined, "signal.reason is initially undefined");
+
+ controller.abort();
+
+ assert_true(signal.aborted, "signal.aborted");
+ assert_true(signal.reason instanceof DOMException, "signal.reason is DOMException");
+ assert_equals(signal.reason.name, "AbortError", "signal.reason is AbortError");
+}, "aborting AbortController without reason creates an \"AbortError\" DOMException");
+
+test(t => {
+ const controller = new AbortController();
+ const signal = controller.signal;
+
+ assert_true("reason" in signal, "signal has reason property");
+ assert_equals(signal.reason, undefined, "signal.reason is initially undefined");
+
+ controller.abort(undefined);
+
+ assert_true(signal.aborted, "signal.aborted");
+ assert_true(signal.reason instanceof DOMException, "signal.reason is DOMException");
+ assert_equals(signal.reason.name, "AbortError", "signal.reason is AbortError");
+}, "AbortController abort(undefined) creates an \"AbortError\" DOMException");
+
+test(t => {
+ const signal = AbortSignal.abort();
+
+ assert_true(signal.aborted, "signal.aborted");
+ assert_true(signal.reason instanceof DOMException, "signal.reason is DOMException");
+ assert_equals(signal.reason.name, "AbortError", "signal.reason is AbortError");
+}, "static aborting signal should have right properties");
+
+test(t => {
+ const reason = Error("hello");
+ const signal = AbortSignal.abort(reason);
+
+ assert_true(signal.aborted, "signal.aborted");
+ assert_equals(signal.reason, reason, "signal.reason");
+}, "static aborting signal with reason should set signal.reason");
+
done();
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.worker-expected.txt (285427 => 285428)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.worker-expected.txt 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/dom/abort/event.any.worker-expected.txt 2021-11-08 21:36:35 UTC (rev 285428)
@@ -4,4 +4,9 @@
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 AbortController abort(reason) should set signal.reason
+PASS aborting AbortController without reason creates an "AbortError" DOMException
+PASS AbortController abort(undefined) creates an "AbortError" DOMException
+PASS static aborting signal should have right properties
+PASS static aborting signal with reason should set signal.reason
Modified: trunk/Source/WebCore/ChangeLog (285427 => 285428)
--- trunk/Source/WebCore/ChangeLog 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/Source/WebCore/ChangeLog 2021-11-08 21:36:35 UTC (rev 285428)
@@ -1,3 +1,31 @@
+2021-11-08 Chris Dumez <[email protected]>
+
+ Add abort reason to AbortSignal
+ https://bugs.webkit.org/show_bug.cgi?id=232299
+ <rdar://problem/84921281>
+
+ Reviewed by Alexey Shvayka.
+
+ Add abort reason to AbortSignal:
+ - https://github.com/whatwg/dom/pull/1027
+ - https://dom.spec.whatwg.org/#abortsignal
+
+ No new tests, updated & rebaselined existing WPT test.
+
+ * bindings/js/JSAbortSignalCustom.cpp:
+ (WebCore::JSAbortSignal::visitAdditionalChildren):
+ * dom/AbortController.cpp:
+ (WebCore::AbortController::abort):
+ * dom/AbortController.h:
+ * dom/AbortController.idl:
+ * dom/AbortSignal.cpp:
+ (WebCore::AbortSignal::abort):
+ (WebCore::AbortSignal::AbortSignal):
+ (WebCore::AbortSignal::signalAbort):
+ (WebCore::AbortSignal::signalFollow):
+ * dom/AbortSignal.h:
+ * dom/AbortSignal.idl:
+
2021-11-08 Ross Kirsling <[email protected]>
Fix !ENABLE(ACCESSIBILITY) build following r285399
Modified: trunk/Source/WebCore/bindings/js/JSAbortSignalCustom.cpp (285427 => 285428)
--- trunk/Source/WebCore/bindings/js/JSAbortSignalCustom.cpp 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/Source/WebCore/bindings/js/JSAbortSignalCustom.cpp 2021-11-08 21:36:35 UTC (rev 285428)
@@ -46,4 +46,12 @@
return visitor.containsOpaqueRoot(&abortSignal);
}
+template<typename Visitor>
+void JSAbortSignal::visitAdditionalChildren(Visitor& visitor)
+{
+ wrapped().reason().visit(visitor);
+}
+
+DEFINE_VISIT_ADDITIONAL_CHILDREN(JSAbortSignal);
+
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/AbortController.cpp (285427 => 285428)
--- trunk/Source/WebCore/dom/AbortController.cpp 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/Source/WebCore/dom/AbortController.cpp 2021-11-08 21:36:35 UTC (rev 285428)
@@ -27,6 +27,8 @@
#include "AbortController.h"
#include "AbortSignal.h"
+#include "DOMException.h"
+#include "JSDOMException.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
@@ -50,9 +52,13 @@
return m_signal.get();
}
-void AbortController::abort()
+void AbortController::abort(JSDOMGlobalObject& globalObject, JSC::JSValue reason)
{
- m_signal->signalAbort();
+ ASSERT(reason);
+ if (reason.isUndefined())
+ reason = toJS(&globalObject, &globalObject, DOMException::create(AbortError));
+
+ m_signal->signalAbort(reason);
}
}
Modified: trunk/Source/WebCore/dom/AbortController.h (285427 => 285428)
--- trunk/Source/WebCore/dom/AbortController.h 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/Source/WebCore/dom/AbortController.h 2021-11-08 21:36:35 UTC (rev 285428)
@@ -29,9 +29,14 @@
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
+namespace JSC {
+class JSValue;
+}
+
namespace WebCore {
class AbortSignal;
+class JSDOMGlobalObject;
class ScriptExecutionContext;
class AbortController final : public ScriptWrappable, public RefCounted<AbortController> {
@@ -41,7 +46,7 @@
~AbortController();
AbortSignal& signal();
- void abort();
+ void abort(JSDOMGlobalObject&, JSC::JSValue reason);
private:
explicit AbortController(ScriptExecutionContext&);
Modified: trunk/Source/WebCore/dom/AbortController.idl (285427 => 285428)
--- trunk/Source/WebCore/dom/AbortController.idl 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/Source/WebCore/dom/AbortController.idl 2021-11-08 21:36:35 UTC (rev 285428)
@@ -32,5 +32,5 @@
[SameObject] readonly attribute AbortSignal signal;
- undefined abort();
+ [CallWith=GlobalObject] undefined abort(optional any reason);
};
Modified: trunk/Source/WebCore/dom/AbortSignal.cpp (285427 => 285428)
--- trunk/Source/WebCore/dom/AbortSignal.cpp 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/Source/WebCore/dom/AbortSignal.cpp 2021-11-08 21:36:35 UTC (rev 285428)
@@ -27,8 +27,10 @@
#include "AbortSignal.h"
#include "AbortAlgorithm.h"
+#include "DOMException.h"
#include "Event.h"
#include "EventNames.h"
+#include "JSDOMException.h"
#include "ScriptExecutionContext.h"
#include <wtf/IsoMallocInlines.h>
@@ -42,19 +44,23 @@
}
// https://dom.spec.whatwg.org/#dom-abortsignal-abort
-Ref<AbortSignal> AbortSignal::abort(ScriptExecutionContext& context)
+Ref<AbortSignal> AbortSignal::abort(JSDOMGlobalObject& globalObject, ScriptExecutionContext& context, JSC::JSValue reason)
{
- return adoptRef(*new AbortSignal(context, Aborted::Yes));
+ ASSERT(reason);
+ if (reason.isUndefined())
+ reason = toJS(&globalObject, &globalObject, DOMException::create(AbortError));
+ return adoptRef(*new AbortSignal(context, Aborted::Yes, reason));
}
-AbortSignal::AbortSignal(ScriptExecutionContext& context, Aborted aborted)
+AbortSignal::AbortSignal(ScriptExecutionContext& context, Aborted aborted, JSC::JSValue reason)
: ContextDestructionObserver(&context)
, m_aborted(aborted == Aborted::Yes)
+ , m_reason(reason)
{
}
// https://dom.spec.whatwg.org/#abortsignal-signal-abort
-void AbortSignal::signalAbort()
+void AbortSignal::signalAbort(JSC::JSValue reason)
{
// 1. If signal's aborted flag is set, then return.
if (m_aborted)
@@ -63,6 +69,9 @@
// 2. Set signal’s aborted flag.
m_aborted = true;
+ ASSERT(reason);
+ m_reason = reason;
+
Ref protectedThis { *this };
auto algorithms = std::exchange(m_algorithms, { });
for (auto& algorithm : algorithms)
@@ -79,7 +88,7 @@
return;
if (signal.aborted()) {
- signalAbort();
+ signalAbort(signal.reason());
return;
}
@@ -87,7 +96,7 @@
m_followingSignal = signal;
signal.addAlgorithm([weakThis = WeakPtr { this }] {
if (weakThis)
- weakThis->signalAbort();
+ weakThis->signalAbort(weakThis->m_followingSignal ? static_cast<JSC::JSValue>(weakThis->m_followingSignal->reason()) : JSC::jsUndefined());
});
}
Modified: trunk/Source/WebCore/dom/AbortSignal.h (285427 => 285428)
--- trunk/Source/WebCore/dom/AbortSignal.h 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/Source/WebCore/dom/AbortSignal.h 2021-11-08 21:36:35 UTC (rev 285428)
@@ -28,6 +28,7 @@
#include "ContextDestructionObserver.h"
#include "EventTarget.h"
#include "JSDOMPromiseDeferred.h"
+#include "JSValueInWrappedObject.h"
#include <wtf/Function.h>
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
@@ -43,14 +44,15 @@
public:
static Ref<AbortSignal> create(ScriptExecutionContext&);
- static Ref<AbortSignal> abort(ScriptExecutionContext&);
+ static Ref<AbortSignal> abort(JSDOMGlobalObject&, ScriptExecutionContext&, JSC::JSValue reason);
static bool whenSignalAborted(AbortSignal&, Ref<AbortAlgorithm>&&);
- void signalAbort();
+ void signalAbort(JSC::JSValue reason);
void signalFollow(AbortSignal&);
bool aborted() const { return m_aborted; }
+ const JSValueInWrappedObject& reason() const { return m_reason; }
using RefCounted::ref;
using RefCounted::deref;
@@ -62,7 +64,7 @@
private:
enum class Aborted : bool { No, Yes };
- explicit AbortSignal(ScriptExecutionContext&, Aborted = Aborted::No);
+ explicit AbortSignal(ScriptExecutionContext&, Aborted = Aborted::No, JSC::JSValue reason = { });
// EventTarget.
EventTargetInterface eventTargetInterface() const final { return AbortSignalEventTargetInterfaceType; }
@@ -73,6 +75,7 @@
bool m_aborted { false };
Vector<Algorithm> m_algorithms;
WeakPtr<AbortSignal> m_followingSignal;
+ JSValueInWrappedObject m_reason;
};
}
Modified: trunk/Source/WebCore/dom/AbortSignal.idl (285427 => 285428)
--- trunk/Source/WebCore/dom/AbortSignal.idl 2021-11-08 21:12:36 UTC (rev 285427)
+++ trunk/Source/WebCore/dom/AbortSignal.idl 2021-11-08 21:36:35 UTC (rev 285428)
@@ -26,12 +26,15 @@
[
CustomIsReachable,
Exposed=(Window,Worker),
+ JSCustomMarkFunction,
PrivateIdentifier,
PublicIdentifier
] interface AbortSignal : EventTarget {
[PrivateIdentifier] static boolean whenSignalAborted(AbortSignal object, AbortAlgorithm algorithm);
- [NewObject, CallWith=ScriptExecutionContext] static AbortSignal abort();
+ [NewObject, CallWith=ScriptExecutionContext&GlobalObject] static AbortSignal abort(optional any reason);
readonly attribute boolean aborted;
+ readonly attribute any reason;
+
attribute EventHandler onabort;
};