Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add &DomRoot<T> lint check #25354

Merged
merged 1 commit into from Dec 22, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add lint check for `&DomRoot<T>`

`&DomRoot<T> is strictly less expressive than `&T`, so using it is
pointless.
  • Loading branch information
lberrymage committed Dec 21, 2019
commit cd9195056c7a83b44ed439ef607b94ed4824431d
@@ -6,7 +6,6 @@
//! (https://html.spec.whatwg.org/multipage/#serializable-objects).

use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::structuredclone::StructuredDataHolder;
use crate::dom::globalscope::GlobalScope;

@@ -25,7 +24,7 @@ pub trait Serializable: DomObject {
fn serialize(&self, sc_holder: &mut StructuredDataHolder) -> Result<StorageKey, ()>;
/// <https://html.spec.whatwg.org/multipage/#deserialization-steps>
fn deserialize(
owner: &DomRoot<GlobalScope>,
owner: &GlobalScope,
sc_holder: &mut StructuredDataHolder,
extra_data: StorageKey,
) -> Result<(), ()>;
@@ -56,7 +56,7 @@ enum StructuredCloneTags {
}

unsafe fn read_blob(
owner: &DomRoot<GlobalScope>,
owner: &GlobalScope,
r: *mut JSStructuredCloneReader,
mut sc_holder: &mut StructuredDataHolder,
) -> *mut JSObject {
@@ -88,7 +88,7 @@ unsafe fn read_blob(
}

unsafe fn write_blob(
owner: &DomRoot<GlobalScope>,
owner: &GlobalScope,
blob: DomRoot<Blob>,
w: *mut JSStructuredCloneWriter,
sc_holder: &mut StructuredDataHolder,
@@ -6,15 +6,14 @@
//! (https://html.spec.whatwg.org/multipage/#transferable-objects).

use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::structuredclone::StructuredDataHolder;
use crate::dom::globalscope::GlobalScope;
use js::jsapi::MutableHandleObject;

pub trait Transferable: DomObject {
fn transfer(&self, sc_holder: &mut StructuredDataHolder) -> Result<u64, ()>;
fn transfer_receive(
owner: &DomRoot<GlobalScope>,
owner: &GlobalScope,
sc_holder: &mut StructuredDataHolder,
extra_data: u64,
return_object: MutableHandleObject,
@@ -125,7 +125,7 @@ impl Serializable for Blob {

/// <https://w3c.github.io/FileAPI/#ref-for-deserialization-steps>
fn deserialize(
owner: &DomRoot<GlobalScope>,
owner: &GlobalScope,
sc_holder: &mut StructuredDataHolder,
storage_key: StorageKey,
) -> Result<(), ()> {
@@ -159,7 +159,7 @@ impl Serializable for Blob {
*blob_impls = None;
}

let deserialized_blob = Blob::new(&**owner, blob_impl);
let deserialized_blob = Blob::new(&*owner, blob_impl);

let blobs = blobs.get_or_insert_with(|| HashMap::new());
blobs.insert(storage_key, deserialized_blob);
@@ -892,7 +892,7 @@ impl GlobalScope {
}

/// Start tracking a blob
pub fn track_blob(&self, dom_blob: &DomRoot<Blob>, blob_impl: BlobImpl) {
pub fn track_blob(&self, dom_blob: &Blob, blob_impl: BlobImpl) {
let blob_id = blob_impl.blob_id();

let blob_info = BlobInfo {
@@ -905,7 +905,7 @@ impl GlobalScope {
}

/// Start tracking a file
pub fn track_file(&self, file: &DomRoot<File>, blob_impl: BlobImpl) {
pub fn track_file(&self, file: &File, blob_impl: BlobImpl) {
let blob_id = blob_impl.blob_id();

let blob_info = BlobInfo {
@@ -199,7 +199,7 @@ impl Transferable for MessagePort {

/// https://html.spec.whatwg.org/multipage/#message-ports:transfer-receiving-steps
fn transfer_receive(
owner: &DomRoot<GlobalScope>,
owner: &GlobalScope,
sc_holder: &mut StructuredDataHolder,
extra_data: u64,
return_object: MutableHandleObject,
@@ -249,7 +249,7 @@ impl Transferable for MessagePort {
};

let transferred_port =
MessagePort::new_transferred(&**owner, id.clone(), port_impl.entangled_port_id());
MessagePort::new_transferred(&*owner, id.clone(), port_impl.entangled_port_id());
owner.track_message_port(&transferred_port, Some(port_impl));

return_object.set(transferred_port.reflector().rootable().get());
@@ -623,6 +623,7 @@ def check_rust(file_name, lines):
(r"DomRefCell<Heap<.+>>", "Banned type DomRefCell<Heap<T>> detected. Use MutDom<T> instead", no_filter),
# No benefit to using &Root<T>
(r": &Root<", "use &T instead of &Root<T>", no_filter),
(r": &DomRoot<", "use &T instead of &DomRoot<T>", no_filter),
(r"^&&", "operators should go at the end of the first line", no_filter),
# This particular pattern is not reentrant-safe in script_thread.rs
(r"match self.documents.borrow", "use a separate variable for the match expression",
@@ -38,7 +38,7 @@ impl test {
}
}

fn test_fun2(y : &String, z : &Vec<f32>, r: &Root<isize>) -> () {
fn test_fun2(y : &String, z : &Vec<f32>, r: &Root<isize>, s: &DomRoot<isize>) -> () {
let x = true;
x
&& x;
@@ -112,6 +112,7 @@ def test_rust(self):
self.assertEqual('use &[T] instead of &Vec<T>', next(errors)[2])
self.assertEqual('use &str instead of &String', next(errors)[2])
self.assertEqual('use &T instead of &Root<T>', next(errors)[2])
self.assertEqual('use &T instead of &DomRoot<T>', next(errors)[2])
self.assertEqual('encountered function signature with -> ()', next(errors)[2])
self.assertEqual('operators should go at the end of the first line', next(errors)[2])
self.assertNoMoreErrors(errors)
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.