Skip to content

Implement ImageData constructors #15671 -- 1 - #15821

Merged
bors-servo merged 1 commit into
servo:masterfrom
tnielens:ImDataConstructors
Mar 15, 2017
Merged

bors-servo merged 1 commit into
servo:masterfrom
tnielens:ImDataConstructors

Conversation

@tnielens

@tnielens tnielens commented Mar 4, 2017 •

Copy link
Copy Markdown

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

  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive

highfive commented Mar 4, 2017

Copy link
Copy Markdown

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.

@highfive

highfive commented Mar 4, 2017

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/canvasrenderingcontext2d.rs, components/script/dom/imagedata.rs, components/script/dom/webidls/ImageData.webidl
  • @KiChjang: components/script/dom/canvasrenderingcontext2d.rs, components/script/dom/imagedata.rs, components/script/dom/webidls/ImageData.webidl

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Mar 4, 2017
@highfive

highfive commented Mar 4, 2017

Copy link
Copy Markdown

warning Warning warning

  • These commits include an empty title element (<title></title>). Consider adding appropriate metadata.
  • These commits modify unsafe code. Please review it carefully!

@nox nox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't yet reviewed whether this follows the spec, nor the tests.

Comment thread components/script/dom/imagedata.rs Outdated
};
let len = width * height * 4;

pub fn from_vec(global: &GlobalScope, width: u32, height: u32, mut data: Option<Vec<u8>>) -> Root<ImageData> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't rename this, this is the only way to create an ImageData with safe code, so it should keep a nice name.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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 ?

Comment thread components/script/dom/imagedata.rs Outdated
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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: let's not rename this, this just makes the diff larger.

Comment thread components/script/dom/imagedata.rs Outdated
global, ImageDataBinding::Wrap)
let len = width * height * 4;
match data {
Some(jsobject) => (*imagedata).data.set(jsobject),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs various checks, such as whether the given object is indeed a proper typed array.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Should I repeat various checks already done in Constructor and Constructor_ or should I remove the pub modifier and comment arguments preconditions?

Comment thread components/script/dom/imagedata.rs Outdated
}
}

pub fn Constructor(global: &GlobalScope, width: u32, height: u32) -> Fallible<Root<Self>> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: spec link.

Comment thread components/script/dom/imagedata.rs Outdated
pub fn Constructor(global: &GlobalScope, width: u32, height: u32) -> Fallible<Root<Self>> {
if width == 0 || height == 0 {
Err(Error::IndexSize)
} else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: remove the else and short-circuit in the error case by returning early.

Comment thread components/script/dom/imagedata.rs Outdated
}
if len % 4 != 0 {
Err(Error::InvalidState)
} else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: remove the else and short-circuit in the error case by returning early.

Comment thread components/script/dom/imagedata.rs Outdated
if len % 4 != 0 {
Err(Error::InvalidState)
} else {
len /= 4;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let len = byte_len / 4;

Comment thread components/script/dom/imagedata.rs Outdated
let height = len / width;
if len % width != 0 {
Err(Error::IndexSize)
} else if opt_height.is_some() && height != opt_height.unwrap() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: remove the else and short-circuit in the error case by returning early.

Comment thread components/script/dom/imagedata.rs Outdated
let height = len / width;
if len % width != 0 {
Err(Error::IndexSize)
} else if opt_height.is_some() && height != opt_height.unwrap() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: remove the commented-out line and instead write the first argument as:

/*Uint8Array*/ object data

@nox nox assigned nox and unassigned cbrewster Mar 5, 2017
@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 5, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 7, 2017
@nox

nox commented Mar 7, 2017

Copy link
Copy Markdown
Contributor

Reviewed 1 of 5 files at r1, 4 of 4 files at r2.
Review status: all files reviewed at latest revision, 3 unresolved discussions, some commit checks failed.


components/script/dom/imagedata.rs, line 31 at r1 (raw file):

Previously, montrivo wrote…

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 ?

You can reuse new_with_jsobject, but the whole method should panic in case of an error.


components/script/dom/imagedata.rs, line 59 at r1 (raw file):

Previously, montrivo wrote…

Should I repeat various checks already done in Constructor and Constructor_ or should I remove the pub modifier and comment arguments preconditions?

Make this method return Fallible<Root<ImageData>> and reuse that in every other method.


components/script/dom/imagedata.rs, line 109 at r1 (raw file):

Previously, nox (Anthony Ramine) wrote…
let mut array = data_res.map_err(|_| {
    Error::Type("Argument to ImageData is not an ArrayBufferView".to_owned())
});

You didn't address this.


Comments from Reviewable

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 7, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 7, 2017
@nox nox removed the S-awaiting-review There is new code that needs to be reviewed. label Mar 8, 2017
@nox

nox commented Mar 8, 2017

Copy link
Copy Markdown
Contributor

-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.
Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


Comments from Reviewable

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit de8201e with merge ab27289...

bors-servo pushed a commit that referenced this pull request Mar 8, 2017
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 -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - android

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Mar 8, 2017
@nox

nox commented Mar 8, 2017

Copy link
Copy Markdown
Contributor
diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json
index 6c2c84a..c1b47c4 100644
--- a/tests/wpt/metadata/MANIFEST.json
+++ b/tests/wpt/metadata/MANIFEST.json
@@ -175569,7 +175569,7 @@
    "testharness"
   ],
   "html/semantics/embedded-content/the-canvas-element/imagedata.html": [
-   "b0dade5b5f0a3e8b7798f52dbcb2ae0f23fed150",
+   "04c670c9a045d924725bedfb09be665f73c3a0ad",
    "testharness"
   ],
   "html/semantics/embedded-content/the-canvas-element/initial.colour.html": [

I'll check whether the other build jobs finish successfully.

@nox

nox commented Mar 8, 2017

Copy link
Copy Markdown
Contributor
  ▶ Unexpected subtest result in /2dcontext/pixel-manipulation/2d.imageData.object.ctor.html:
  │ FAIL [expected PASS] ImageData does not have a usable constructor
  │   → assert_throws: function "function () { new window.ImageData(1,1); }" did not throw
  │ 
  │ @http://web-platform.test:8000/2dcontext/pixel-manipulation/2d.imageData.object.ctor.html:23:1
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1409:20
  │ _addTest/</<@http://web-platform.test:8000/common/canvas-tests.js:62:13
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1409:20
  └ _addTest/<@http://web-platform.test:8000/common/canvas-tests.js:59:9

  ▶ Unexpected subtest result in /html/dom/interfaces.worker.html:
  └ PASS [expected FAIL] ImageData interface object length

  ▶ Unexpected subtest result in /html/dom/interfaces.html:
  └ PASS [expected FAIL] ImageData interface object length

The 2 PASS are good news, the FAIL isn't.

@nox

nox commented Mar 8, 2017

Copy link
Copy Markdown
Contributor

The test /2dcontext/pixel-manipulation/2d.imageData.object.ctor.html doesn't pass in either Safari nor Firefox, it's probably outdated.

@nox

nox commented Mar 8, 2017

Copy link
Copy Markdown
Contributor

@jdm Should it be marked as FAIL, or should we fix the test right now in this PR?

@nox

nox commented Mar 13, 2017

Copy link
Copy Markdown
Contributor

@Ms2ger What do you think about the failing test? Should we just mark it as FAIL and report the erroneous test upstream?

@Ms2ger

Ms2ger commented Mar 13, 2017

Copy link
Copy Markdown
Contributor

Mark it as fail; I want wpt CI to run on the change.

function constructor_domexceptions(domExcepName, description, func) {
test(function() {
var result;
try {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use assert_throws

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-tests-failed The changes caused existing tests to fail. labels Mar 13, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 13, 2017
nox
nox previously requested changes Mar 14, 2017

@nox nox left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few cosmetic changes on the test and this will be ready.

@@ -0,0 +1,68 @@
<!doctype html>
<meta charset="utf-8">
<title></title>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a title.

assert_equals(imageData.height, 3);
assert_equals(imageData.data.length, 24);
assert_true(imageData.data instanceof Uint8ClampedArray);
}, "ImagaData(w, h), exposed attributes check");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please reindent all tests to look like this one.

function(){
new ImageData(0, 1);
})},
"ImagaData(w, h), width cannot be 0");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please fix all the spelling errors, it's ImageData.

@nox nox added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 14, 2017
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Mar 14, 2017
@Ms2ger
Ms2ger dismissed nox’s stale review March 15, 2017 09:23

Comments addressed

@Ms2ger

Ms2ger commented Mar 15, 2017

Copy link
Copy Markdown
Contributor

@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 46a25d6 has been approved by Ms2ger

@highfive highfive assigned Ms2ger and unassigned nox Mar 15, 2017
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Mar 15, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 46a25d6 with merge 5bfa87a...

bors-servo pushed a commit that referenced this pull request Mar 15, 2017
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 -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ 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
Approved by: Ms2ger
Pushing 5bfa87a to master...

@bors-servo
bors-servo merged commit 46a25d6 into servo:master Mar 15, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Mar 15, 2017
jdm pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants