From cc8d14086be24d0f17c3dc50f51baa82be1d231f Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Thu, 19 Nov 2020 02:32:20 +0000 Subject: [PATCH 1/2] fix(abort-controller): make AbortSignal WHATWG Spec compliant --- packages/abort-controller/src/AbortSignal.ts | 8 ++++---- packages/types/src/abort.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/abort-controller/src/AbortSignal.ts b/packages/abort-controller/src/AbortSignal.ts index fc9523634971..1da2c3386b23 100644 --- a/packages/abort-controller/src/AbortSignal.ts +++ b/packages/abort-controller/src/AbortSignal.ts @@ -1,8 +1,8 @@ import { AbortHandler, AbortSignal as IAbortSignal } from "@aws-sdk/types"; export class AbortSignal implements IAbortSignal { - public onabort?: AbortHandler; - private _aborted!: boolean; + public onabort: AbortHandler | null = null; + private _aborted = false; constructor() { Object.defineProperty(this, "_aborted", { @@ -24,8 +24,8 @@ export class AbortSignal implements IAbortSignal { abort(): void { this._aborted = true; if (this.onabort) { - this.onabort(); - this.onabort = undefined; + this.onabort(this); + this.onabort = null; } } } diff --git a/packages/types/src/abort.ts b/packages/types/src/abort.ts index 14644b2d007e..a511cee9da05 100644 --- a/packages/types/src/abort.ts +++ b/packages/types/src/abort.ts @@ -1,5 +1,5 @@ export interface AbortHandler { - (): void; + (this: AbortSignal, ev: any): any; } /** @@ -18,7 +18,7 @@ export interface AbortSignal { * A function to be invoked when the action represented by this signal has * been cancelled. */ - onabort?: AbortHandler; + onabort: AbortHandler | null; } /** From e238aee2bdd1b14bf87eab2ebb476ec86e342cb5 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Thu, 19 Nov 2020 17:18:42 +0000 Subject: [PATCH 2/2] fix: test in *-http-handler --- packages/fetch-http-handler/src/fetch-http-handler.spec.ts | 2 ++ packages/node-http-handler/src/node-http-handler.spec.ts | 1 + packages/node-http-handler/src/node-http2-handler.spec.ts | 2 ++ 3 files changed, 5 insertions(+) diff --git a/packages/fetch-http-handler/src/fetch-http-handler.spec.ts b/packages/fetch-http-handler/src/fetch-http-handler.spec.ts index 59d2c16b441f..748572c2c11a 100644 --- a/packages/fetch-http-handler/src/fetch-http-handler.spec.ts +++ b/packages/fetch-http-handler/src/fetch-http-handler.spec.ts @@ -105,6 +105,7 @@ describe.skip(FetchHttpHandler.name, () => { fetchHttpHandler.handle({} as any, { abortSignal: { aborted: true, + onabort: null, }, }) ).rejects.toHaveProperty("name", "AbortError"); @@ -130,6 +131,7 @@ describe.skip(FetchHttpHandler.name, () => { await fetchHttpHandler.handle({} as any, { abortSignal: { aborted: false, + onabort: null, }, }); diff --git a/packages/node-http-handler/src/node-http-handler.spec.ts b/packages/node-http-handler/src/node-http-handler.spec.ts index 34b0569810f0..607b33adcfd0 100644 --- a/packages/node-http-handler/src/node-http-handler.spec.ts +++ b/packages/node-http-handler/src/node-http-handler.spec.ts @@ -450,6 +450,7 @@ describe("NodeHttpHandler", () => { { abortSignal: { aborted: true, + onabort: null, }, } ) diff --git a/packages/node-http-handler/src/node-http2-handler.spec.ts b/packages/node-http-handler/src/node-http2-handler.spec.ts index b520c2f559e4..f55a0a1ed69f 100644 --- a/packages/node-http-handler/src/node-http2-handler.spec.ts +++ b/packages/node-http-handler/src/node-http2-handler.spec.ts @@ -143,6 +143,7 @@ describe("NodeHttp2Handler", () => { nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), { abortSignal: { aborted: true, + onabort: null, }, }) ).rejects.toHaveProperty("name", "AbortError"); @@ -161,6 +162,7 @@ describe("NodeHttp2Handler", () => { nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), { abortSignal: { aborted: true, + onabort: null, }, }) ).rejects.toHaveProperty("name", "AbortError");