Add safe methods to handles/rootedguard and simplify NoGC#700
Merged
sagudev merged 7 commits intoservo:mainfrom Jan 17, 2026
Merged
Add safe methods to handles/rootedguard and simplify NoGC#700sagudev merged 7 commits intoservo:mainfrom
sagudev merged 7 commits intoservo:mainfrom
Conversation
sagudev
commented
Jan 17, 2026
This comment was marked as resolved.
This comment was marked as resolved.
jdm
approved these changes
Jan 17, 2026
Member
jdm
left a comment
There was a problem hiding this comment.
This is great! Thanks for the doctests, too.
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
Signed-off-by: sagudev <[email protected]>
c3de572 to
8113700
Compare
This was referenced Jan 18, 2026
github-merge-queue bot
pushed a commit
to servo/servo
that referenced
this pull request
Jan 18, 2026
…s artifacts (#41971) This bump includes some new safe wrappers: servo/mozjs#699 servo/mozjs#700 debugmozjs artifacts: servo/mozjs#544 rooted macros with vectors: servo/mozjs#697 Testing: Done in mozjs repo. Signed-off-by: sagudev <[email protected]>
Member
Author
|
For servo dom objects, I think it is safe for /// It's ok to return ref to dom object as they are allocated via Box, thus
/// unmoovable by GC.
pub trait ServoRef {
type Inner;
fn as_servo_ref(&self) -> &Self::Inner;
}
impl<T: DomObject> ServoRef for Handle<'_, T> {
type Inner = T;
fn as_servo_ref(&self) -> &T {
self.deref()
}
}
impl<T: DomObject> ServoRef for MutableHandle<'_, T> {
type Inner = T;
fn as_servo_ref(&self) -> &T {
self.deref()
}
}Huh, that's effectively what Dom(Root) is. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Firstly we simplify
NoGCto be proper ZST without any inner lifetime. One should now useno_gc: &NoGC(this gives us compiler reborrow support, instead of manual reborrows we need to do for handles). This allows us to impl deref from&JSContextso&JSContextand&NoGCcan be used interchangeably.Then we add
as_refandas_mut_refas the safe way (as they require&NoGC, aliasing rules are uphold by &/&mut of handles/root) of obtaining reference to rooted value. This should eventually replace unsound derefs and unsafe as_mut, but until then documentation notice will suffice.Testing: compile doc tests
Servo PR: servo/servo#41971
This is not reviewable per commit.