-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
feat(ext/web): add ImageData Web API #21183
Conversation
tools/wpt/expectation.json
Outdated
@@ -6908,6 +6908,9 @@ | |||
} | |||
}, | |||
"embedded-content": { | |||
"the-canvas-element": { | |||
"imagedata.html": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case does not run with Deno's current wpt set up. However, by hacking the wpt.ts
script I got the test running and it appears to pass.
/html/semantics/embedded-content/the-canvas-element/imagedata.html
test ImageData(w, h), width cannot be 0 ... ok
test ImageData(w, h), height cannot be 0 ... ok
test ImageData(w, h), exposed attributes check ... ok
test ImageData(buffer, w), the buffer size must be a multiple of 4 ... ok
test ImageData(buffer, w), buffer size must be a multiple of the image width ... ok
test ImageData(buffer, w, h), buffer.length == 4 * w * h must be true ... ok
test ImageData(buffer, w, opt h), Uint8ClampedArray argument type check ... ok
test ImageData(buffer, w, opt h), exposed attributes check ... ok
file result: ok. 8 passed; 0 failed; 0 expected failure; total 8 (2681ms)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we already have a few hacks in place for WPT. What is specifically failing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the file name is the issue @mmastrac.
To fix this, an upstream PR to WPT should be made to update the naming convention for this specific testing module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we already have a few hacks in place for WPT. What is specifically failing?
When running ./tools/wpt.ts run
the test case is not discovered and not run by the script.
To fix this, an upstream PR to WPT should be made to update the naming convention for this specific testing module
Is this really the case? I might be misunderstanding the situation, but the test and name seems valid to me. The test is the "With HTML boilerplate" type according to the documentation. It appears that these types of tests have not been used yet by Deno.
Do we need to refactor the discoverTestsToRun to support them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the commit 28347cf which I believe resolves the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you are correct. in previous cases we have gone upstream to update the HTML tests to js tests where applicable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see! Well I have no strong feelings, I'll follow whatever your team prefers 🙇
ext/web/16_image_data.js
Outdated
sourceHeight = typeof arg1 !== "undefined" ? parseInt(arg1, 10) : undefined; | ||
settings = arg2; | ||
|
||
if (Number.isNaN(sourceWidth) || sourceWidth < 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some repeated logic between both overloads, but I think the class is simpler to understand with the duplication.
Please let me know there are better or more preferred ways to refactor.
ext/web/16_image_data.js
Outdated
let settings; | ||
|
||
// Overload: new ImageData(data, sw [, sh [, settings ] ]) | ||
if (webidl.type(arg0) === "Object") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (webidl.type(arg0) === "Object") { | |
if ( | |
arguments.length > 3 || | |
TypedArrayPrototypeGetSymbolToStringTag(arg0) === "Uint8ClampedArray" | |
) { |
As per the overload resolution algorithm. WPT will fail as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@crowlKats this is the reason that ImageData(buffer, w, opt h), Uint8ClampedArray argument type check
has to fail. By obeying the overload resolution algorithm we can't handle this case.
All major browsers will fail the test as well. You can test it yourself by visiting https://wpt.live/html/semantics/embedded-content/the-canvas-element/imagedata.html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, thanks for clarifying. probably at some point someone should fix the test (I'll take a look at some point), because its kinda ridiculous if everyone fails it with intent...
The CI is failing for the Web Platform Tests on the Test Result Output: 2023-11-21T14:15:29.8055289Z expected test failures that passed:
2023-11-21T14:15:29.8055848Z
2023-11-21T14:15:29.8057091Z "/workers/semantics/interface-objects/001.worker.html - The ImageData interface object should be exposed."
2023-11-21T14:15:29.8058431Z
2023-11-21T14:15:29.8059149Z final result: failed. 2153 passed; 1 failed; 97 expected failure; total 2154 (449030ms) I'll try look into this over the weekend - Edit: It turns out we were expecting ImageData not to be exposed in the |
I'd like to point out some outstanding problems.
|
Thanks for the thorough review @0f-0b! I think I've addressed those changes, let me know if I misunderstood anything. Running the script in your comment with the debug build now outputs the following
I also additionally
|
@@ -7009,6 +7009,11 @@ | |||
} | |||
}, | |||
"embedded-content": { | |||
"the-canvas-element": { | |||
"imagedata.html": [ | |||
"ImageData(buffer, w, opt h), Uint8ClampedArray argument type check" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this test failing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question, I've tagged you in a comment above that explains why this has to fail – #21183 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thanks a lot for adding this
@lucacasonato could you take a look at the WPT changes? |
They look fine |
Fixes #19288
Adds the
ImageData
Web API.This would be beneficial to projects using
ImageData
as a convenient transport layer for pixel data. This is common in Web Assembly projects that manipulate images. Having this global available in Deno would improve compatibility of existing JS libraries.References