From b1912ed75b09746e659ce7b1d9b1393bf91b831e Mon Sep 17 00:00:00 2001 From: Sten Laane <21343173+StenAL@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:43:43 +0000 Subject: [PATCH] Add overloads for specific context types to OffscreenCanvas.getContext Each context type can only return the relevant context or null. There are already similar overloads in place for HTMLCanvasElement.getContext. Relevant part of the HTML spec: https://html.spec.whatwg.org/multipage/canvas.html#dom-offscreencanvas-getcontext --- baselines/dom.generated.d.ts | 4 ++++ baselines/serviceworker.generated.d.ts | 4 ++++ baselines/sharedworker.generated.d.ts | 4 ++++ baselines/webworker.generated.d.ts | 4 ++++ inputfiles/overridingTypes.jsonc | 14 ++++++++++++++ 5 files changed, 30 insertions(+) diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index cbec67c3e..dccb1df34 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -10559,6 +10559,10 @@ interface OffscreenCanvas extends EventTarget { * * Returns null if the canvas has already been initialized with another context type (e.g., trying to get a "2d" context after getting a "webgl" context). */ + getContext(contextId: "2d", options?: any): OffscreenCanvasRenderingContext2D | null; + getContext(contextId: "bitmaprenderer", options?: any): ImageBitmapRenderingContext | null; + getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null; + getContext(contextId: "webgl2", options?: any): WebGL2RenderingContext | null; getContext(contextId: OffscreenRenderingContextId, options?: any): OffscreenRenderingContext | null; /** Returns a newly created ImageBitmap object with the image in the OffscreenCanvas object. The image in the OffscreenCanvas object is replaced with a new blank image. */ transferToImageBitmap(): ImageBitmap; diff --git a/baselines/serviceworker.generated.d.ts b/baselines/serviceworker.generated.d.ts index a9d49219b..589047288 100644 --- a/baselines/serviceworker.generated.d.ts +++ b/baselines/serviceworker.generated.d.ts @@ -2512,6 +2512,10 @@ interface OffscreenCanvas extends EventTarget { * * Returns null if the canvas has already been initialized with another context type (e.g., trying to get a "2d" context after getting a "webgl" context). */ + getContext(contextId: "2d", options?: any): OffscreenCanvasRenderingContext2D | null; + getContext(contextId: "bitmaprenderer", options?: any): ImageBitmapRenderingContext | null; + getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null; + getContext(contextId: "webgl2", options?: any): WebGL2RenderingContext | null; getContext(contextId: OffscreenRenderingContextId, options?: any): OffscreenRenderingContext | null; /** Returns a newly created ImageBitmap object with the image in the OffscreenCanvas object. The image in the OffscreenCanvas object is replaced with a new blank image. */ transferToImageBitmap(): ImageBitmap; diff --git a/baselines/sharedworker.generated.d.ts b/baselines/sharedworker.generated.d.ts index 02d0e22e2..ea691ca2d 100644 --- a/baselines/sharedworker.generated.d.ts +++ b/baselines/sharedworker.generated.d.ts @@ -2420,6 +2420,10 @@ interface OffscreenCanvas extends EventTarget { * * Returns null if the canvas has already been initialized with another context type (e.g., trying to get a "2d" context after getting a "webgl" context). */ + getContext(contextId: "2d", options?: any): OffscreenCanvasRenderingContext2D | null; + getContext(contextId: "bitmaprenderer", options?: any): ImageBitmapRenderingContext | null; + getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null; + getContext(contextId: "webgl2", options?: any): WebGL2RenderingContext | null; getContext(contextId: OffscreenRenderingContextId, options?: any): OffscreenRenderingContext | null; /** Returns a newly created ImageBitmap object with the image in the OffscreenCanvas object. The image in the OffscreenCanvas object is replaced with a new blank image. */ transferToImageBitmap(): ImageBitmap; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index a9f8a6438..f94fc9c6d 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -2607,6 +2607,10 @@ interface OffscreenCanvas extends EventTarget { * * Returns null if the canvas has already been initialized with another context type (e.g., trying to get a "2d" context after getting a "webgl" context). */ + getContext(contextId: "2d", options?: any): OffscreenCanvasRenderingContext2D | null; + getContext(contextId: "bitmaprenderer", options?: any): ImageBitmapRenderingContext | null; + getContext(contextId: "webgl", options?: any): WebGLRenderingContext | null; + getContext(contextId: "webgl2", options?: any): WebGL2RenderingContext | null; getContext(contextId: OffscreenRenderingContextId, options?: any): OffscreenRenderingContext | null; /** Returns a newly created ImageBitmap object with the image in the OffscreenCanvas object. The image in the OffscreenCanvas object is replaced with a new blank image. */ transferToImageBitmap(): ImageBitmap; diff --git a/inputfiles/overridingTypes.jsonc b/inputfiles/overridingTypes.jsonc index c688ef390..1fd634694 100644 --- a/inputfiles/overridingTypes.jsonc +++ b/inputfiles/overridingTypes.jsonc @@ -1136,6 +1136,20 @@ } } }, + "OffscreenCanvas": { + "methods": { + "method": { + "getContext": { + "additionalSignatures": [ + "getContext(contextId: \"2d\", options?: any): OffscreenCanvasRenderingContext2D | null", + "getContext(contextId: \"bitmaprenderer\", options?: any): ImageBitmapRenderingContext | null", + "getContext(contextId: \"webgl\", options?: any): WebGLRenderingContext | null", + "getContext(contextId: \"webgl2\", options?: any): WebGL2RenderingContext | null" + ] + } + } + } + }, "BeforeUnloadEvent": { "properties": { "property": {