Add exception info for `HTMLCanvasElement.transferControlToOffscreen()` and `OffscreenCanvas.transferToImageBitmap()` by skyclouds2001 · Pull Request #36631 · mdn/content · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception info for HTMLCanvasElement.transferControlToOffscreen() and OffscreenCanvas.transferToImageBitmap() #36631

Merged
merged 7 commits into from
Nov 22, 2024

Conversation

skyclouds2001
Copy link
Contributor

…)` and `OffscreenCanvas.transferToImageBitmap()`
@github-actions github-actions bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Nov 3, 2024
@skyclouds2001 skyclouds2001 marked this pull request as ready for review November 3, 2024 15:04
@skyclouds2001 skyclouds2001 requested a review from a team as a code owner November 3, 2024 15:04
@skyclouds2001 skyclouds2001 requested review from wbamberg and removed request for a team November 3, 2024 15:04
Copy link
Contributor

github-actions bot commented Nov 3, 2024

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be slow to review this @skyclouds2001 .

### Exceptions

- `InvalidStateError` {{domxref("DOMException")}}
- : Throws if the canvas has been set to a context mode via calling {{domxref("HTMLCanvasElement.getContext()")}} or has transferred its control to offscreen via calling {{domxref("HTMLCanvasElement.transferControlToOffscreen()")}}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see in https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-transfercontroltooffscreen where we throw an exception if the canvas "has transferred its control to offscreen via calling {{domxref("HTMLCanvasElement.transferControlToOffscreen()")}}", can you point to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transferControlToOffscreen() method, when invoked, must run these steps:
If this canvas element's context mode is not set to none, throw an "InvalidStateError" DOMException.
Let offscreenCanvas be a new OffscreenCanvas object with its width and height equal to the values of the width and height content attributes of this canvas element.
Set the placeholder canvas element of offscreenCanvas to a weak reference to this canvas element.
Set this canvas element's context mode to placeholder.
Return offscreenCanvas.The transferControlToOffscreen() method, when invoked, must run these steps:
If this canvas element's context mode is not set to none, throw an "InvalidStateError" DOMException.
Let offscreenCanvas be a new OffscreenCanvas object with its width and height equal to the values of the width and height content attributes of this canvas element.
Set the placeholder canvas element of offscreenCanvas to a weak reference to this canvas element.
Set this canvas element's context mode to placeholder.
Return offscreenCanvas.

After calling transferControlToOffscreen(), the canvas's context mode will be set to "placeholder"; so if calling transferControlToOffscreen() again, it will fail at the first step.

Sample code is as follows:

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! (I didn't doubt you were right here, I just couldn't see it!)

…x.md

Co-authored-by: wbamberg <will@bootbonnet.ca>
skyclouds2001 and others added 2 commits November 16, 2024 20:11
…x.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…en/index.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thank you @skyclouds2001 !

@wbamberg wbamberg merged commit 46dd9c0 into mdn:main Nov 22, 2024
8 checks passed
@skyclouds2001 skyclouds2001 deleted the canvas-transfer-exception branch November 22, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants