Repository navigation
Implement ImageData constructors #15671 -- 1 - #15821
Conversation
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @cbrewster (or someone else) soon. |
|
Heads up! This PR modifies the following files: |
nox
left a comment
There was a problem hiding this comment.
I haven't yet reviewed whether this follows the spec, nor the tests.
| }; | ||
| let len = width * height * 4; | ||
|
|
||
| pub fn from_vec(global: &GlobalScope, width: u32, height: u32, mut data: Option<Vec<u8>>) -> Root<ImageData> { |
There was a problem hiding this comment.
Don't rename this, this is the only way to create an ImageData with safe code, so it should keep a nice name.
There was a problem hiding this comment.
The new method doesn't validate arguments, neither returns a Faillible<Root<ImageData>>. Should it do the same kind of validations as the two new constructors ?
| assert!(!cx.is_null()); | ||
| typedarray!(in(cx) let array: Uint8ClampedArray = self.data.get()); | ||
| let vec = array.unwrap().as_slice().to_vec(); | ||
| typedarray!(in(cx) let typedarray: Uint8ClampedArray = self.data.get()); |
There was a problem hiding this comment.
Nit: let's not rename this, this just makes the diff larger.
| global, ImageDataBinding::Wrap) | ||
| let len = width * height * 4; | ||
| match data { | ||
| Some(jsobject) => (*imagedata).data.set(jsobject), |
There was a problem hiding this comment.
This needs various checks, such as whether the given object is indeed a proper typed array.
There was a problem hiding this comment.
Should I repeat various checks already done in Constructor and Constructor_ or should I remove the pub modifier and comment arguments preconditions?
| } | ||
| } | ||
|
|
||
| pub fn Constructor(global: &GlobalScope, width: u32, height: u32) -> Fallible<Root<Self>> { |
| pub fn Constructor(global: &GlobalScope, width: u32, height: u32) -> Fallible<Root<Self>> { | ||
| if width == 0 || height == 0 { | ||
| Err(Error::IndexSize) | ||
| } else { |
There was a problem hiding this comment.
Nit: remove the else and short-circuit in the error case by returning early.
| } | ||
| if len % 4 != 0 { | ||
| Err(Error::InvalidState) | ||
| } else { |
There was a problem hiding this comment.
Nit: remove the else and short-circuit in the error case by returning early.
| if len % 4 != 0 { | ||
| Err(Error::InvalidState) | ||
| } else { | ||
| len /= 4; |
| let height = len / width; | ||
| if len % width != 0 { | ||
| Err(Error::IndexSize) | ||
| } else if opt_height.is_some() && height != opt_height.unwrap() { |
There was a problem hiding this comment.
Nit: remove the else and short-circuit in the error case by returning early.
| let height = len / width; | ||
| if len % width != 0 { | ||
| Err(Error::IndexSize) | ||
| } else if opt_height.is_some() && height != opt_height.unwrap() { |
There was a problem hiding this comment.
if opt_height.map_or(false, |x| x != height) {
return Err(Error::IndexSize);
}| [Exposed=(Window,Worker)] | ||
| [Constructor(unsigned long sw, unsigned long sh), | ||
| // Constructor(Uint8Array data, unsigned long sw, optional unsigned long sh), | ||
| Constructor(object data, unsigned long sw, optional unsigned long sh), |
There was a problem hiding this comment.
Nit: remove the commented-out line and instead write the first argument as:
/*Uint8Array*/ object data
|
Reviewed 1 of 5 files at r1, 4 of 4 files at r2. components/script/dom/imagedata.rs, line 31 at r1 (raw file): Previously, montrivo wrote…
You can reuse components/script/dom/imagedata.rs, line 59 at r1 (raw file): Previously, montrivo wrote…
Make this method return components/script/dom/imagedata.rs, line 109 at r1 (raw file): Previously, nox (Anthony Ramine) wrote…
You didn't address this. Comments from Reviewable |
|
-S-awaiting-review Seems ok! Running try because I think there will be test expectations to change. @bors-servo try Reviewed 1 of 1 files at r3. Comments from Reviewable |
Implement ImageData constructors #15671 -- 1 <!-- Please describe your changes on the following line: --> Implement ImageData constructors * new constructors in the imagedata.rs file * modification of the ImageData::new method * new method ImageData::from_vec * new wpt test file imagedata.html --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes affect #15671 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15821) <!-- Reviewable:end -->
|
💔 Test failed - android |
I'll check whether the other build jobs finish successfully. |
The 2 |
|
The test |
|
@jdm Should it be marked as |
|
@Ms2ger What do you think about the failing test? Should we just mark it as FAIL and report the erroneous test upstream? |
|
Mark it as fail; I want wpt CI to run on the change. |
| function constructor_domexceptions(domExcepName, description, func) { | ||
| test(function() { | ||
| var result; | ||
| try { |
nox
left a comment
There was a problem hiding this comment.
A few cosmetic changes on the test and this will be ready.
| @@ -0,0 +1,68 @@ | |||
| <!doctype html> | |||
| <meta charset="utf-8"> | |||
| <title></title> | |||
| assert_equals(imageData.height, 3); | ||
| assert_equals(imageData.data.length, 24); | ||
| assert_true(imageData.data instanceof Uint8ClampedArray); | ||
| }, "ImagaData(w, h), exposed attributes check"); |
There was a problem hiding this comment.
Please reindent all tests to look like this one.
| function(){ | ||
| new ImageData(0, 1); | ||
| })}, | ||
| "ImagaData(w, h), width cannot be 0"); |
There was a problem hiding this comment.
Please fix all the spelling errors, it's ImageData.
|
@bors-servo r+ |
|
📌 Commit 46a25d6 has been approved by |
Implement ImageData constructors #15671 -- 1 <!-- Please describe your changes on the following line: --> Implement ImageData constructors * new constructors in the imagedata.rs file * modification of the ImageData::new method * new method ImageData::from_vec * new wpt test file imagedata.html --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes affect #15671 (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15821) <!-- Reviewable:end -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-gnu-dev, windows-msvc-dev |
Upstreamed from servo/servo#15821 [ci skip]
Implement ImageData constructors
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is