Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upDOMMatrix and DOMMatrixReadOnly #12202
Conversation
highfive
commented
Jul 3, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Jul 3, 2016
| } | ||
|
|
||
| // https://drafts.fxtf.org/geometry-1/#dom-dommatrix-multiplyself | ||
| fn MultiplySelf(&self, other:&DOMMatrixInit) -> Root<DOMMatrix> { |
This comment has been minimized.
This comment has been minimized.
peterjoel
Jul 3, 2016
•
Author
Contributor
@nox The various methods on DOMMatrixReadOnly, that are actually really there to be used by DOMMatrix, all now have a return value. However, this is a DOMMatrixReadOnly because they can only return self. I can't see a clean way to make this value be used by the DOMMatrix methods. Currently the implementation is technically correct because these DOM methods return the current object, but the implementations (e.g. multiply_self) are a bit misleading because they return a value that is never used.
I have tried a few things, but advice would be welcome in how to make that better.
This comment has been minimized.
This comment has been minimized.
nox
Jul 4, 2016
Member
Oh right damn it. Please remove the returning values from the DOMMatrixReadOnly helpers and keep only Root::from_ref(&*self) in their DOMMatrix call sites.
This comment has been minimized.
This comment has been minimized.
peterjoel
Jul 4, 2016
•
Author
Contributor
Ok. But if I'm going to add matrix and is_2d accessors to DOMMatrix anyway, then I can just move the contents of the *Self methods to DOMMatrixReadOnly and get rid of the *_self methods from DOMMatrix.
It will be overall less code, and will keep each of the sets of steps together nicely.
This comment has been minimized.
This comment has been minimized.
nox
Jul 4, 2016
Member
No you can't, because the matrix method would just return a Matrix4D<f32>, not a Ref<Matrix4D<_>> or a RefMut<Matrix4D<_>>.
It is no worry to have mutating methods on DOMMatrixReadOnly, the only thing that matters is what gets exposed to JS.
This comment has been minimized.
This comment has been minimized.
peterjoel
Jul 4, 2016
•
Author
Contributor
Ok, fair enough. I can document the steps like this:
// https://drafts.fxtf.org/geometry-1/#dom-dommatrix-multiplyself
fn MultiplySelf(&self, other:&DOMMatrixInit) -> Root<DOMMatrix> {
// Steps 1-3.
self.upcast::<DOMMatrixReadOnly>().multiply_self(other);
// Step 4.
Root::from_ref(&self)
}With the remaining steps listed inside multiply_self.
| }) | ||
| } | ||
|
|
||
| fn to_DOMMatrix(&self) -> Root<DOMMatrix> { |
This comment has been minimized.
This comment has been minimized.
peterjoel
Jul 3, 2016
•
Author
Contributor
@nox In your previous feedback, you suggested that I move this to DOMMatrix and rename it from_readonly. However, I have struggled to find a way to make that work. Here are my comments from the previous discussion:
Are you suggesting an implementation like one of these?
pub fn from_readonly(ro: &DOMMatrixReadOnly) -> Root<DOMMatrix> {
Self::new(ro.global().r(), ro.is2D.get(), ro.matrix.borrow().clone())
}I'm unsure about the global ref. I would also have to make the DOMMatrixReadOnly fields public, which isn't permitted without adding a pragma.
I tried explicitly downcasting, but I'd still have to move the value, which can't be done since it's borrowed already and DOMMatrixReadOnly cannot be cloned.
pub fn from_readonly(ro: &DOMMatrixReadOnly) -> Root<DOMMatrix> {
reflect_dom_object(box ro.downcast().unwrap(), ro.global().r(), Wrap)
}I also tried skipping the root and letting the consumer deal with that, but it doesn't work because parent can't be a reference, so it's the same problem.
pub fn from_readonly(ro: &DOMMatrixReadOnly) -> DOMMatrix {
DOMMatrix {
parent: ro
}
}Another way would be to add public accessors to DOMMatrixReadOnly for matrix and is2D, so that a new one can be constructed from those parts inside from_readonly.
This comment has been minimized.
This comment has been minimized.
nox
Jul 4, 2016
Member
Another way would be to add public accessors to DOMMatrixReadOnly for matrix and is2D, so that a new one can be constructed from those parts inside from_readonly.
That is what I had in mind. Just add two new methods on DOMMatrixReadOnly, matrix and is_2d.
|
@bors-servo try |
DOMMatrix and DOMMatrixReadOnly <!-- Please describe your changes on the following line: --> --- <!-- 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 fix #8509. <!-- Either: --> - [ ] 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12202) <!-- Reviewable:end -->
|
|
This is relevant. |
|
@nox DOMRefCell doesn't get static protection against being borrowed multiple times? |
|
I've reorganised the code so that the borrows don't overlap. Is there a better way, or a way that can make this a static check? |
|
@peterjoel Yes, DOMRefCell is no different than RefCell in that respect. |
|
@jdm I've re-read the docs on this now. Is there a best practice for avoiding panics here? Using |
|
There's no better practice than making mutable borrows as small as possible, unfortunately. |
|
Thanks @jdm. I've made an improvement to move all the RefCell borrows as close as possible to where they are used, and to limit their scopes. I think it's more readable too. |
fdeb039
to
14cf6cb
|
@peterjoel You could even do: *self.matrix.borrow_mut() = ...;That way you don't even bind the borrow to a local variable. |
|
@nox I find it a bit weird to look at (first glance it looks like it's assigning to a function call), but I think you are right, it's better. I'll need to use the borrowed value again on the right hand side, so it will need two borrows and it won't work in one line. let rotated = self.matrix.borrow().mul(&rotation);
*self.matrix.borrow_mut() = rotated;Unless you can see a better way? |
|
@nox Can you suggest how I should deal with the differences between Euclid matrices and the geom spec? This is what is blocking me, and I'm not sure of the right approach. |
|
@bors-servo r=nox |
|
|
DOMMatrix and DOMMatrixReadOnly <!-- Please describe your changes on the following line: --> --- <!-- 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 fix #8509. <!-- Either: --> - [ ] 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12202) <!-- Reviewable:end -->
|
|
|
Needs update on test expectations. Good work! |
Updated test expectations
|
@nox can this be merged now? |
|
@bors-servo r=nox |
|
|
|
|
DOMMatrix and DOMMatrixReadOnly <!-- Please describe your changes on the following line: --> --- <!-- 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 fix #8509. <!-- Either: --> - [ ] 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12202) <!-- Reviewable:end -->
|
|
highfive
commented
Sep 16, 2016
|
|
@bors-servo retry |
|
|
|
|
peterjoel commentedJul 3, 2016
•
edited
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is