mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Add unrooted_must_root lint for enums and structs containing JS<T>, as well as functions with JS<T> in their parameter list
For safe wrappers over JS<T> (eg Temporary<T>) use #[allow(unrooted_must_root)]. For all other types containing a #[must_root] value, annotate the type with #[must_root] to ensure that it is never used unrooted
This commit is contained in:
parent
13ae369dec
commit
12dc54d238
22 changed files with 101 additions and 4 deletions
|
@ -2868,7 +2868,10 @@ class CGUnionStruct(CGThing):
|
|||
enumConversions = [
|
||||
" e%s(ref inner) => inner.to_jsval(cx)," % v["name"] for v in templateVars
|
||||
]
|
||||
return ("""pub enum %s {
|
||||
# XXXManishearth The following should be #[must_root],
|
||||
# however we currently allow it till #2661 is fixed
|
||||
return ("""#[allow(unrooted_must_root)]
|
||||
pub enum %s {
|
||||
%s
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ pub enum GlobalRoot<'a, 'b> {
|
|||
/// A traced reference to a global object, for use in fields of traced Rust
|
||||
/// structures.
|
||||
#[deriving(Encodable)]
|
||||
#[must_root]
|
||||
pub enum GlobalField {
|
||||
WindowField(JS<Window>),
|
||||
WorkerField(JS<WorkerGlobalScope>),
|
||||
|
|
|
@ -61,6 +61,7 @@ use std::mem;
|
|||
/// Importantly, it requires explicit rooting in order to interact with the inner value.
|
||||
/// Can be assigned into JS-owned member fields (i.e. `JS<T>` types) safely via the
|
||||
/// `JS<T>::assign` method or `OptionalSettable::assign` (for `Option<JS<T>>` fields).
|
||||
#[allow(unrooted_must_root)]
|
||||
pub struct Temporary<T> {
|
||||
inner: JS<T>,
|
||||
/// On-stack JS pointer to assuage conservative stack scanner
|
||||
|
@ -106,6 +107,7 @@ impl<T: Reflectable> Temporary<T> {
|
|||
}
|
||||
|
||||
/// A rooted, JS-owned value. Must only be used as a field in other JS-owned types.
|
||||
#[must_root]
|
||||
pub struct JS<T> {
|
||||
ptr: *const T
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue