Skip to content

Commit a4c8ffe

Browse files
authored
Script: Change script/dom/{bluetooth,canvas,html} to not rely on Deref<str> for DOMString (servo#39480)
This is part of the future work of implementing LazyDOMString as outlined in servo#39479. We use str() method or direct implementations on DOMString for these methods. We also change some types. Signed-off-by: Narfinger <[email protected]> Testing: This is essentially just renaming a method and a type and should not change functionality. Signed-off-by: Narfinger <[email protected]>
1 parent 1e471b9 commit a4c8ffe

23 files changed

+97
-95
lines changed

components/script/dom/bluetooth/bluetooth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fn canonicalize_filter(filter: &BluetoothLEScanFilterInit) -> Fallible<Bluetooth
432432
let mut map = HashMap::new();
433433
for (key, bdfi) in manufacturer_data_map.iter() {
434434
// Step 7.1 - 7.2.
435-
let manufacturer_id = match u16::from_str(key.as_ref()) {
435+
let manufacturer_id = match u16::from_str(key.str()) {
436436
Ok(id) => id,
437437
Err(err) => {
438438
return Err(Type(format!("{} {} {}", KEY_CONVERSION_ERROR, key, err)));
@@ -461,7 +461,7 @@ fn canonicalize_filter(filter: &BluetoothLEScanFilterInit) -> Fallible<Bluetooth
461461
}
462462
let mut map = HashMap::new();
463463
for (key, bdfi) in service_data_map.iter() {
464-
let service_name = match u32::from_str(key.as_ref()) {
464+
let service_name = match u32::from_str(key.str()) {
465465
// Step 9.1.
466466
Ok(number) => StringOrUnsignedLong::UnsignedLong(number),
467467
// Step 9.2.
@@ -687,7 +687,7 @@ impl PermissionAlgorithm for Bluetooth {
687687
continue;
688688
}
689689
}
690-
let device_id = String::from(allowed_device.deviceId.as_ref());
690+
let device_id = String::from(allowed_device.deviceId.str());
691691

692692
// Step 6.2.
693693
if let Some(ref filters) = descriptor.filters {

components/script/dom/bluetooth/bluetoothremotegattcharacteristic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
153153
let p = Promise::new_in_current_realm(comp, can_gc);
154154

155155
// Step 1.
156-
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
156+
if uuid_is_blocklisted(self.uuid.str(), Blocklist::Reads) {
157157
p.reject_error(Security, can_gc);
158158
return p;
159159
}
@@ -191,7 +191,7 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
191191
let p = Promise::new_in_current_realm(comp, can_gc);
192192

193193
// Step 1.
194-
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) {
194+
if uuid_is_blocklisted(self.uuid.str(), Blocklist::Writes) {
195195
p.reject_error(Security, can_gc);
196196
return p;
197197
}
@@ -242,7 +242,7 @@ impl BluetoothRemoteGATTCharacteristicMethods<crate::DomTypeHolder>
242242
let p = Promise::new_in_current_realm(comp, can_gc);
243243

244244
// Step 1.
245-
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
245+
if uuid_is_blocklisted(self.uuid.str(), Blocklist::Reads) {
246246
p.reject_error(Security, can_gc);
247247
return p;
248248
}

components/script/dom/bluetooth/bluetoothremotegattdescriptor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl BluetoothRemoteGATTDescriptorMethods<crate::DomTypeHolder> for BluetoothRem
101101
let p = Promise::new_in_current_realm(comp, can_gc);
102102

103103
// Step 1.
104-
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Reads) {
104+
if uuid_is_blocklisted(self.uuid.str(), Blocklist::Reads) {
105105
p.reject_error(Security, can_gc);
106106
return p;
107107
}
@@ -138,7 +138,7 @@ impl BluetoothRemoteGATTDescriptorMethods<crate::DomTypeHolder> for BluetoothRem
138138
let p = Promise::new_in_current_realm(comp, can_gc);
139139

140140
// Step 1.
141-
if uuid_is_blocklisted(self.uuid.as_ref(), Blocklist::Writes) {
141+
if uuid_is_blocklisted(self.uuid.str(), Blocklist::Writes) {
142142
p.reject_error(Security, can_gc);
143143
return p;
144144
}

components/script/dom/bluetooth/bluetoothuuid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ fn resolve_uuid_name(
638638
StringOrUnsignedLong::String(dstring) => {
639639
// Step 2.
640640
let regex = Regex::new(VALID_UUID_REGEX).unwrap();
641-
if regex.is_match(&dstring) {
641+
if regex.is_match(dstring.str()) {
642642
Ok(dstring)
643643
} else {
644644
// Step 3.

components/script/dom/canvas/2d/canvas_state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ impl CanvasState {
12981298
repetition.push_str("repeat");
12991299
}
13001300

1301-
if let Ok(rep) = RepetitionStyle::from_str(&repetition) {
1301+
if let Ok(rep) = RepetitionStyle::from_str(repetition.str()) {
13021302
let size = snapshot.size();
13031303
Ok(Some(CanvasPattern::new(
13041304
global,
@@ -1357,7 +1357,7 @@ impl CanvasState {
13571357

13581358
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
13591359
pub(super) fn set_global_composite_operation(&self, op_str: DOMString) {
1360-
if let Ok(op) = CompositionOrBlending::from_str(&op_str) {
1360+
if let Ok(op) = CompositionOrBlending::from_str(op_str.str()) {
13611361
self.state.borrow_mut().global_composition = op;
13621362
}
13631363
}
@@ -2506,9 +2506,9 @@ impl UnshapedTextRun<'_> {
25062506

25072507
pub(super) fn parse_color(
25082508
canvas: Option<&HTMLCanvasElement>,
2509-
string: &str,
2509+
string: &DOMString,
25102510
) -> Result<AbsoluteColor, ()> {
2511-
let mut input = ParserInput::new(string);
2511+
let mut input = ParserInput::new(string.str());
25122512
let mut parser = Parser::new(&mut input);
25132513
let url = Url::parse("about:blank").unwrap().into();
25142514
let context = ParserContext::new(

components/script/dom/canvas/offscreencanvas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl OffscreenCanvasMethods<crate::DomTypeHolder> for OffscreenCanvas {
297297
return Err(Error::InvalidState);
298298
}
299299

300-
match &*id {
300+
match id.str() {
301301
"2d" => Ok(self
302302
.get_or_init_2d_context(can_gc)
303303
.map(RootedOffscreenRenderingContext::OffscreenCanvasRenderingContext2D)),

components/script/dom/html/htmlareaelement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl HTMLAreaElement {
304304
pub(crate) fn get_shape_from_coords(&self) -> Option<Area> {
305305
let elem = self.upcast::<Element>();
306306
let shape = elem.get_string_attribute(&"shape".into());
307-
let shp: Shape = match_ignore_ascii_case! { &shape,
307+
let shp: Shape = match_ignore_ascii_case! { shape.str(),
308308
"circle" => Shape::Circle,
309309
"circ" => Shape::Circle,
310310
"rectangle" => Shape::Rectangle,
@@ -315,7 +315,7 @@ impl HTMLAreaElement {
315315
};
316316
if elem.has_attribute(&"coords".into()) {
317317
let attribute = elem.get_string_attribute(&"coords".into());
318-
Area::parse(&attribute, shp)
318+
Area::parse(attribute.str(), shp)
319319
} else {
320320
None
321321
}

components/script/dom/html/htmlcanvaselement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl HTMLCanvasElementMethods<crate::DomTypeHolder> for HTMLCanvasElement {
449449
return Err(Error::InvalidState);
450450
}
451451

452-
Ok(match &*id {
452+
Ok(match id.str() {
453453
"2d" => self
454454
.get_or_init_2d_context(can_gc)
455455
.map(RootedRenderingContext::CanvasRenderingContext2D),

components/script/dom/html/htmlcollection.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ impl HTMLCollection {
270270
classes: DOMString,
271271
can_gc: CanGc,
272272
) -> DomRoot<HTMLCollection> {
273-
let class_atoms = split_html_space_chars(&classes).map(Atom::from).collect();
273+
let class_atoms = split_html_space_chars(classes.str())
274+
.map(Atom::from)
275+
.collect();
274276
HTMLCollection::by_atomic_class_name(window, root, class_atoms, can_gc)
275277
}
276278

components/script/dom/html/htmlelement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ impl HTMLElement {
932932
// returns Some if can infer direction by itself or from child nodes
933933
// returns None if requires to go up to parent
934934
pub(crate) fn directionality(&self) -> Option<String> {
935-
let element_direction: &str = &self.Dir();
935+
let element_direction = &self.Dir();
936936

937937
if element_direction == "ltr" {
938938
return Some("ltr".to_owned());

0 commit comments

Comments
 (0)