Skip to content

Commit 3e77a0a

Browse files
author
bors-servo
authored
Auto merge of servo#25354 - lberrymage:dom-domroot-lint-check, r=jdm
Add &DomRoot<T> lint check So far, the lint check code appears to work as intended. However, some trait implementations require modification to pass the lint check and I'm not sure how to fix these. Commit 92cf5d5 attempts to correct one of the implementations, but fails to compile with error: ``` --> components/script/dom/servoparser/xml.rs:76:36 | 76 | tree_builder.trace_handles(&tracer); | ^^^^^^^ expected struct `dom::bindings::root::Dom`, found struct `dom::node::Node` | = note: expected struct `dom::bindings::root::Dom<dom::node::Node>` found struct `dom::node::Node` = note: required for the cast to the object type `dyn html5ever::tree_builder::Tracer<Handle = dom::bindings::root::Dom<dom::node::Node>>` ``` I've tried to debug further but to no avail. I also don't want to mangle too much existing code unnecessarily. Any help is appreciated. <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors `./mach test-tidy --all` does, and some are directly related to this PR - [ ] These changes fix servo#25342 The fix is a WIP <!-- Either: --> - [X] There are tests for these changes Note that I will clean up the commit history before the final PR. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
2 parents 19ca0b3 + cd91950 commit 3e77a0a

File tree

9 files changed

+13
-13
lines changed

9 files changed

+13
-13
lines changed

components/script/dom/bindings/serializable.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//! (https://html.spec.whatwg.org/multipage/#serializable-objects).
77
88
use crate::dom::bindings::reflector::DomObject;
9-
use crate::dom::bindings::root::DomRoot;
109
use crate::dom::bindings::structuredclone::StructuredDataHolder;
1110
use crate::dom::globalscope::GlobalScope;
1211

@@ -25,7 +24,7 @@ pub trait Serializable: DomObject {
2524
fn serialize(&self, sc_holder: &mut StructuredDataHolder) -> Result<StorageKey, ()>;
2625
/// <https://html.spec.whatwg.org/multipage/#deserialization-steps>
2726
fn deserialize(
28-
owner: &DomRoot<GlobalScope>,
27+
owner: &GlobalScope,
2928
sc_holder: &mut StructuredDataHolder,
3029
extra_data: StorageKey,
3130
) -> Result<(), ()>;

components/script/dom/bindings/structuredclone.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ enum StructuredCloneTags {
5656
}
5757

5858
unsafe fn read_blob(
59-
owner: &DomRoot<GlobalScope>,
59+
owner: &GlobalScope,
6060
r: *mut JSStructuredCloneReader,
6161
mut sc_holder: &mut StructuredDataHolder,
6262
) -> *mut JSObject {
@@ -88,7 +88,7 @@ unsafe fn read_blob(
8888
}
8989

9090
unsafe fn write_blob(
91-
owner: &DomRoot<GlobalScope>,
91+
owner: &GlobalScope,
9292
blob: DomRoot<Blob>,
9393
w: *mut JSStructuredCloneWriter,
9494
sc_holder: &mut StructuredDataHolder,

components/script/dom/bindings/transferable.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
//! (https://html.spec.whatwg.org/multipage/#transferable-objects).
77
88
use crate::dom::bindings::reflector::DomObject;
9-
use crate::dom::bindings::root::DomRoot;
109
use crate::dom::bindings::structuredclone::StructuredDataHolder;
1110
use crate::dom::globalscope::GlobalScope;
1211
use js::jsapi::MutableHandleObject;
1312

1413
pub trait Transferable: DomObject {
1514
fn transfer(&self, sc_holder: &mut StructuredDataHolder) -> Result<u64, ()>;
1615
fn transfer_receive(
17-
owner: &DomRoot<GlobalScope>,
16+
owner: &GlobalScope,
1817
sc_holder: &mut StructuredDataHolder,
1918
extra_data: u64,
2019
return_object: MutableHandleObject,

components/script/dom/blob.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl Serializable for Blob {
125125

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

162-
let deserialized_blob = Blob::new(&**owner, blob_impl);
162+
let deserialized_blob = Blob::new(&*owner, blob_impl);
163163

164164
let blobs = blobs.get_or_insert_with(|| HashMap::new());
165165
blobs.insert(storage_key, deserialized_blob);

components/script/dom/globalscope.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ impl GlobalScope {
892892
}
893893

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

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

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

911911
let blob_info = BlobInfo {

components/script/dom/messageport.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl Transferable for MessagePort {
199199

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

251251
let transferred_port =
252-
MessagePort::new_transferred(&**owner, id.clone(), port_impl.entangled_port_id());
252+
MessagePort::new_transferred(&*owner, id.clone(), port_impl.entangled_port_id());
253253
owner.track_message_port(&transferred_port, Some(port_impl));
254254

255255
return_object.set(transferred_port.reflector().rootable().get());

python/tidy/servo_tidy/tidy.py

+1
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ def check_rust(file_name, lines):
623623
(r"DomRefCell<Heap<.+>>", "Banned type DomRefCell<Heap<T>> detected. Use MutDom<T> instead", no_filter),
624624
# No benefit to using &Root<T>
625625
(r": &Root<", "use &T instead of &Root<T>", no_filter),
626+
(r": &DomRoot<", "use &T instead of &DomRoot<T>", no_filter),
626627
(r"^&&", "operators should go at the end of the first line", no_filter),
627628
# This particular pattern is not reentrant-safe in script_thread.rs
628629
(r"match self.documents.borrow", "use a separate variable for the match expression",

python/tidy/servo_tidy_tests/rust_tidy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl test {
3838
}
3939
}
4040

41-
fn test_fun2(y : &String, z : &Vec<f32>, r: &Root<isize>) -> () {
41+
fn test_fun2(y : &String, z : &Vec<f32>, r: &Root<isize>, s: &DomRoot<isize>) -> () {
4242
let x = true;
4343
x
4444
&& x;

python/tidy/servo_tidy_tests/test_tidy.py

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def test_rust(self):
112112
self.assertEqual('use &[T] instead of &Vec<T>', next(errors)[2])
113113
self.assertEqual('use &str instead of &String', next(errors)[2])
114114
self.assertEqual('use &T instead of &Root<T>', next(errors)[2])
115+
self.assertEqual('use &T instead of &DomRoot<T>', next(errors)[2])
115116
self.assertEqual('encountered function signature with -> ()', next(errors)[2])
116117
self.assertEqual('operators should go at the end of the first line', next(errors)[2])
117118
self.assertNoMoreErrors(errors)

0 commit comments

Comments
 (0)