fix(AbortSignal.any) fire dependents signals (#11789)

This commit is contained in:
Ciro Spaciari
2024-06-11 15:42:48 -03:00
committed by GitHub
parent ee30e8660c
commit 27d0912f9d
2 changed files with 36 additions and 0 deletions

View File

@@ -156,6 +156,11 @@ void AbortSignal::signalAbort(JSC::JSValue reason)
// 5. Fire an event named abort at signal.
dispatchEvent(Event::create(eventNames().abortEvent, Event::CanBubble::No, Event::IsCancelable::No));
// 6. For each dependent signal of signal, call signal's signalAbort method with reason.
auto dependentSignals = std::exchange(m_dependentSignals, {});
for (auto& signal : dependentSignals)
signal.signalAbort(reason);
}
void AbortSignal::cleanNativeBindings(void* ref)

View File

@@ -39,4 +39,35 @@ describe("AbortSignal", () => {
expect(exitCode).toBe(0);
});
test("AbortSignal.any() should fire abort event", async () => {
async function testAny(signalToAbort: number) {
const { promise, resolve } = Promise.withResolvers();
const a = new AbortController();
const b = new AbortController();
// @ts-ignore
const signal = AbortSignal.any([a.signal, b.signal]);
const timeout = setTimeout(() => {
resolve(false);
}, 100);
signal.addEventListener("abort", () => {
clearTimeout(timeout);
resolve(true);
});
if (signalToAbort) {
b.abort();
} else {
a.abort();
}
expect(await promise).toBe(true);
expect(signal.aborted).toBe(true);
}
await testAny(0);
await testAny(1);
});
});