script: Avoid double borrow crash in DataTransferItem (#35699)

* avoid double borrow inside GetAsString

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

* added crashtest

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>

---------

Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This commit is contained in:
Gae24 2025-02-27 20:28:35 +01:00 committed by GitHub
parent 8a3f62933b
commit 900655fbc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 1 deletions

View file

@ -123,7 +123,8 @@ impl DataTransferItemMethods<crate::DomTypeHolder> for DataTransferItem {
.task_manager()
.dom_manipulation_task_source()
.queue(task!(invoke_callback: move || {
if let Some(index) = this.root().pending_callbacks.borrow().iter().position(|val| val.id == id) {
let maybe_index = this.root().pending_callbacks.borrow().iter().position(|val| val.id == id);
if let Some(index) = maybe_index {
let callback = this.root().pending_callbacks.borrow_mut().swap_remove(index).callback;
let _ = callback.Call__(DOMString::from(string), ExceptionHandling::Report);
}