Avoid borrow panic when Path2D.addPath is called with self (#36847)

Fixes: #36842

Signed-off-by: Taym <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2025-05-05 14:10:33 +02:00 committed by GitHub
parent 3936b1d22b
commit 7ea5951e34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 2 deletions

View file

@ -65,8 +65,14 @@ impl Path2DMethods<crate::DomTypeHolder> for Path2D {
/// <https://html.spec.whatwg.org/multipage/#dom-path2d-addpath>
fn AddPath(&self, other: &Path2D) {
// Step 7. Add all the subpaths in c to a.
let mut dest = self.path.borrow_mut();
dest.extend(other.path.borrow().iter().copied());
if std::ptr::eq(&self.path, &other.path) {
// Note: this is not part of the spec, but it is a workaround to
// avoids borrow conflict when path is same as other.path
self.path.borrow_mut().extend_from_within(..);
} else {
let mut dest = self.path.borrow_mut();
dest.extend(other.path.borrow().iter().copied());
}
}
/// <https://html.spec.whatwg.org/multipage/#dom-context-2d-closepath>