Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix borrow hazard creating intersection observer entries#45001

Open
SharanRP wants to merge 1 commit into
servo:mainfrom
SharanRP:44988
Open

Fix borrow hazard creating intersection observer entries#45001
SharanRP wants to merge 1 commit into
servo:mainfrom
SharanRP:44988

Conversation

@SharanRP
Copy link
Copy Markdown
Contributor

IntersectionObserverEntry::new() can trigger garbage collection but self.queued_entries.borrow_mut() was held during the call when GC traces the cell it tries to borrow again causing a panic , create the entry first then push it to avoid the borrow hazard

Fixes #44988

@SharanRP SharanRP requested a review from gterzian as a code owner May 19, 2026 06:12
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 19, 2026
Copy link
Copy Markdown
Contributor

@xiaochengh xiaochengh left a comment

Choose a reason for hiding this comment

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

The PR doesn't compile, can we fix it?

@SharanRP
Copy link
Copy Markdown
Contributor Author

yes looking into that

Finite::wrap(intersection_ratio),
target,
)
.as_traced();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move the as_traced() call to the push call instead to avoid this error.

target,
)
.as_traced(),
// > 2. Append it to observer's internal [[QueuedEntries]] slot.
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: move this comment above self.queued_entries.borrow_mut().push(entry.as_traced());

@servo-highfive servo-highfive 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 May 19, 2026
Signed-off-by: SharanRP <[email protected]>
@servo-highfive servo-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 May 19, 2026
@SharanRP
Copy link
Copy Markdown
Contributor Author

are the changes good ? @Gae24 @jdm @xiaochengh

Copy link
Copy Markdown
Contributor

@Gae24 Gae24 left a comment

Choose a reason for hiding this comment

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

Just to keep it consistent with how spec comments are written nowadays.

Comment on lines +340 to 341
// Step 1
// > 1. Construct an IntersectionObserverEntry, passing in time, rootBounds,
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.

Suggested change
// Step 1
// > 1. Construct an IntersectionObserverEntry, passing in time, rootBounds,
// Step 1. Construct an IntersectionObserverEntry, passing in time, rootBounds,

Comment on lines +359 to +360
// Step 2
// > 2. Append it to observer's internal [[QueuedEntries]] slot.
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.

Suggested change
// Step 2
// > 2. Append it to observer's internal [[QueuedEntries]] slot.
// Step 2. Append it to observer's internal [[QueuedEntries]] slot.

Comment on lines 362 to 363
// > Step 3
// Queue an intersection observer task for document.
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.

Suggested change
// > Step 3
// Queue an intersection observer task for document.
// Step 3. Queue an intersection observer task for document.

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label May 21, 2026
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.

Borrow hazard creating intersection observer entries

5 participants