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>

View file

@ -53,6 +53,13 @@
{}
]
],
"path2D_addPath-crash.html": [
"f913e6baf8340886c58f99609755ae061bf64f12",
[
null,
{}
]
],
"test-wait-crash.html": [
"2419da6af0c278a17b9ff974d4418f9e386ef3e0",
[

View file

@ -0,0 +1,5 @@
<!DOCTYPE html>
<script>
let path2D = new Path2D();
path2D.addPath(path2D);
</script>