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

Ensure that drawImage(detachedCanvas) throws #43835

Merged
merged 1 commit into from
Mar 3, 2024

Conversation

Kaiido
Copy link
Contributor

@Kaiido Kaiido commented Jan 2, 2024

See whatwg/html#10026 and https://bugs.webkit.org/show_bug.cgi?id=266918

The specs are currently underspecified, though all implementations do agree that a detached OffscreenCanvas has a size of 0, which should throw when passed to drawImage().
Only Safari currently fails the test. A fix is on the way.

Note that I couldn't run update-built due to #23292 and hence I did create the generated html manually...

Copy link
Member

@kenrussell kenrussell left a comment

Choose a reason for hiding this comment

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

Looks fine to me. One small comment.

See whatwg/html#10026 and https://bugs.webkit.org/show_bug.cgi?id=266918

The specs are currently underspecified, though all implementations do agree that a detached OffscreenCanvas has a size of 0, which should throw when passed to drawImage().
Only Safari currently fails the test. A fix is on the way at WebKit/WebKit#22297.
webkit-commit-queue pushed a commit to Kaiido/WebKit that referenced this pull request Feb 13, 2024
…webkit.org/show_bug.cgi?id=266918

Reviewed by @mattwoodrow.

Explanation of why this fixes the bug.

By setting the OffscreenCanvas's `size()` after the DetachedCanvas has been created we ensure that the DetachedCanvas has the correct size to later create the new OffscreenCanvas, and that any method checking the size of the previous OffscreenCanvas, including `drawImage()`, gets the expected `0` width and height.

Also deletes the custom `width` and `height` getters from OffscreenCanvas since these were only used to return a "fake" `0` in case the OffscreenCanvas got detached, and that they are now truly `0`. The special handling in `setWidth` and `setHeight` is still required though.

Tests are not yet published at web-platform-tests/wpt#43835

* Source/WebCore/html/OffscreenCanvas.cpp:
(WebCore::OffscreenCanvas::detach):
(WebCore::OffscreenCanvas::width const): Deleted.
(WebCore::OffscreenCanvas::height const): Deleted.
* Source/WebCore/html/OffscreenCanvas.h:

import new WPT tests

Manually imported since while web-platform-tests/wpt#43835 has been approved, it still hasn't been merged.

drawImage(detachedOffscreenCanvas) is supposed to throw https://bugs.webkit.org/show_bug.cgi?id=266918

Reviewed by @Ahmad-S792.

Since the previous change this method was failing to trigger the proper exception type when
called on a detached OffscreenCanvas, because now the size is actually empty for detached
OffscreenCanvas. We need to separate the case 'detached' and 'no buffer', because zero size
OffscreenCanvas will match 'no buffer' and we'd throw an InvalidStateError instead of an
IndexSizeError for zero-sized OffscreenCanvas.

* Source/WebCore/html/OffscreenCanvas.cpp:
(WebCore::OffscreenCanvas::convertToBlob):

Canonical link: https://commits.webkit.org/274534@main
@Kaiido
Copy link
Contributor Author

Kaiido commented Mar 3, 2024

Small update/bump, the WebKit patch has landed a few weeks ago and now this test has been manually added there.
So now all major vendors pass it. (And I don't have write access so I need help for merging.)

@annevk annevk merged commit 9a0819b into web-platform-tests:master Mar 3, 2024
20 checks passed
@annevk
Copy link
Member

annevk commented Mar 3, 2024

Thanks @Kaiido for your continued efforts on improving canvas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants