Skip to content

Commit 1e471b9

Browse files
authored
Script: Change the rest of script to not rely on Deref<str> for DOMString (servo#39481)
This is part of the future work of implementing LazyDOMString as outlined in issue servo#39479. We use str() method or direct implementations on DOMString for these methods. We also change some types. This is independent of servo#39480 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 9713bb9 commit 1e471b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+219
-132
lines changed

components/script/body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl Extractable for Vec<u8> {
507507
impl Extractable for Blob {
508508
fn extract(&self, _global: &GlobalScope, can_gc: CanGc) -> Fallible<ExtractedBody> {
509509
let blob_type = self.Type();
510-
let content_type = if blob_type.as_ref().is_empty() {
510+
let content_type = if blob_type.is_empty() {
511511
None
512512
} else {
513513
Some(blob_type)

components/script/dom/bindings/domname.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub(crate) fn is_valid_element_local_name(name: &str) -> bool {
9191
}
9292

9393
/// <https://dom.spec.whatwg.org/#valid-doctype-name>
94-
pub(crate) fn is_valid_doctype_name(name: &str) -> bool {
94+
pub(crate) fn is_valid_doctype_name(name: &DOMString) -> bool {
9595
// A string is a valid doctype name if it does not contain
9696
// ASCII whitespace, U+0000 NULL, or U+003E (>).
9797
!name
@@ -121,7 +121,7 @@ pub(crate) enum Context {
121121
/// <https://dom.spec.whatwg.org/#validate-and-extract>
122122
pub(crate) fn validate_and_extract(
123123
namespace: Option<DOMString>,
124-
qualified_name: &str,
124+
qualified_name: &DOMString,
125125
context: Context,
126126
) -> Fallible<(Namespace, Option<Prefix>, LocalName)> {
127127
// Step 1. If namespace is the empty string, then set it to null.
@@ -130,12 +130,12 @@ pub(crate) fn validate_and_extract(
130130
// Step 2. Let prefix be null.
131131
let mut prefix = None;
132132
// Step 3. Let localName be qualifiedName.
133-
let mut local_name = qualified_name;
133+
let mut local_name = qualified_name.str();
134134
// Step 4. If qualifiedName contains a U+003A (:):
135135
if let Some(idx) = qualified_name.find(':') {
136136
// Step 4.1. Let splitResult be the result of running
137137
// strictly split given qualifiedName and U+003A (:).
138-
let p = &qualified_name[..idx];
138+
let p = &qualified_name.str()[..idx];
139139

140140
// Step 5. If prefix is not a valid namespace prefix,
141141
// then throw an "InvalidCharacterError" DOMException.
@@ -148,7 +148,7 @@ pub(crate) fn validate_and_extract(
148148
prefix = Some(p);
149149

150150
// Step 4.3. Set localName to splitResult[1].
151-
let remaining = &qualified_name[(idx + 1).min(qualified_name.len())..];
151+
let remaining = &qualified_name.str()[(idx + 1).min(qualified_name.len())..];
152152
match remaining.find(':') {
153153
Some(end) => local_name = &remaining[..end],
154154
None => local_name = remaining,

components/script/dom/blob.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl BlobMethods<crate::DomTypeHolder> for Blob {
176176
},
177177
};
178178

179-
let type_string = normalize_type_string(blobPropertyBag.type_.as_ref());
179+
let type_string = normalize_type_string(blobPropertyBag.type_.str());
180180
let blob_impl = BlobImpl::new_from_bytes(bytes, type_string);
181181

182182
Ok(Blob::new_with_proto(global, proto, blob_impl, can_gc))
@@ -206,7 +206,7 @@ impl BlobMethods<crate::DomTypeHolder> for Blob {
206206
can_gc: CanGc,
207207
) -> DomRoot<Blob> {
208208
let global = self.global();
209-
let type_string = normalize_type_string(&content_type.unwrap_or_default());
209+
let type_string = normalize_type_string(content_type.unwrap_or_default().str());
210210

211211
// If our parent is already a sliced blob then we reference the data from the grandparent instead,
212212
// to keep the blob ancestry chain short.

components/script/dom/characterdata.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl CharacterDataMethods<crate::DomTypeHolder> for CharacterData {
136136
let data = self.data.borrow();
137137
// Step 1.
138138
let mut substring = String::new();
139-
let remaining = match split_at_utf16_code_unit_offset(&data, offset) {
139+
let remaining = match split_at_utf16_code_unit_offset(data.str(), offset) {
140140
Ok((_, astral, s)) => {
141141
// As if we had split the UTF-16 surrogate pair in half
142142
// and then transcoded that to UTF-8 lossily,
@@ -169,7 +169,7 @@ impl CharacterDataMethods<crate::DomTypeHolder> for CharacterData {
169169
// https://dom.spec.whatwg.org/#dom-characterdata-appenddatadata
170170
fn AppendData(&self, data: DOMString) {
171171
// FIXME(ajeffrey): Efficient append on DOMStrings?
172-
self.append_data(&data);
172+
self.append_data(data.str());
173173
}
174174

175175
// https://dom.spec.whatwg.org/#dom-characterdata-insertdataoffset-data
@@ -190,7 +190,7 @@ impl CharacterDataMethods<crate::DomTypeHolder> for CharacterData {
190190
let prefix;
191191
let replacement_before;
192192
let remaining;
193-
match split_at_utf16_code_unit_offset(&data, offset) {
193+
match split_at_utf16_code_unit_offset(data.str(), offset) {
194194
Ok((p, astral, r)) => {
195195
prefix = p;
196196
// As if we had split the UTF-16 surrogate pair in half
@@ -231,7 +231,7 @@ impl CharacterDataMethods<crate::DomTypeHolder> for CharacterData {
231231
);
232232
new_data.push_str(prefix);
233233
new_data.push_str(replacement_before);
234-
new_data.push_str(&arg);
234+
new_data.push_str(arg.str());
235235
new_data.push_str(replacement_after);
236236
new_data.push_str(suffix);
237237
}
@@ -290,7 +290,7 @@ impl<'dom> LayoutCharacterDataHelpers<'dom> for LayoutDom<'dom, CharacterData> {
290290
#[allow(unsafe_code)]
291291
#[inline]
292292
fn data_for_layout(self) -> &'dom str {
293-
unsafe { self.unsafe_get().data.borrow_for_layout() }
293+
unsafe { self.unsafe_get().data.borrow_for_layout().str() }
294294
}
295295
}
296296

components/script/dom/clipboarditem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl ClipboardItemMethods<crate::DomTypeHolder> for ClipboardItem {
160160

161161
// Step 6.3 If key starts with `"web "` prefix, then
162162
// Step 6.3.1 Remove `"web "` prefix and assign the remaining string to key.
163-
let (key, is_custom) = match key.strip_prefix(CUSTOM_FORMAT_PREFIX) {
163+
let (key, is_custom) = match key.str().strip_prefix(CUSTOM_FORMAT_PREFIX) {
164164
None => (key.str(), false),
165165
// Step 6.3.2 Set isCustom true
166166
Some(stripped) => (stripped, true),

components/script/dom/compositionevent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl CompositionEvent {
7777
ev
7878
}
7979

80-
pub(crate) fn data(&self) -> &str {
80+
pub(crate) fn data(&self) -> &DOMString {
8181
&self.data
8282
}
8383
}

components/script/dom/console.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl consoleMethods<crate::DomTypeHolder> for Console {
419419

420420
// https://console.spec.whatwg.org/#timelog
421421
fn TimeLog(_cx: JSContext, global: &GlobalScope, label: DOMString, data: Vec<HandleValue>) {
422-
if let Ok(delta) = global.time_log(&label) {
422+
if let Ok(delta) = global.time_log(label.str()) {
423423
let message = format!("{label}: {delta}ms {}", stringify_handle_values(&data));
424424

425425
Console::send_string_message(global, LogLevel::Log, message.clone());
@@ -428,7 +428,7 @@ impl consoleMethods<crate::DomTypeHolder> for Console {
428428

429429
// https://console.spec.whatwg.org/#timeend
430430
fn TimeEnd(global: &GlobalScope, label: DOMString) {
431-
if let Ok(delta) = global.time_end(&label) {
431+
if let Ok(delta) = global.time_end(label.str()) {
432432
let message = format!("{label}: {delta}ms");
433433

434434
Console::send_string_message(global, LogLevel::Log, message.clone());

components/script/dom/css.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ impl CSSMethods<crate::DomTypeHolder> for CSS {
3131
/// <https://drafts.csswg.org/cssom/#the-css.escape()-method>
3232
fn Escape(_: &Window, ident: DOMString) -> Fallible<DOMString> {
3333
let mut escaped = String::new();
34-
serialize_identifier(&ident, &mut escaped).unwrap();
34+
serialize_identifier(ident.str(), &mut escaped).unwrap();
3535
Ok(DOMString::from(escaped))
3636
}
3737

3838
/// <https://drafts.csswg.org/css-conditional/#dom-css-supports>
3939
fn Supports(win: &Window, property: DOMString, value: DOMString) -> bool {
4040
let mut decl = String::new();
41-
serialize_identifier(&property, &mut decl).unwrap();
41+
serialize_identifier(property.str(), &mut decl).unwrap();
4242
decl.push_str(": ");
43-
decl.push_str(&value);
43+
decl.push_str(value.str());
4444
let decl = Declaration(decl);
4545
let url_data = UrlExtraData(win.Document().url().get_arc());
4646
let context = ParserContext::new(
@@ -58,7 +58,7 @@ impl CSSMethods<crate::DomTypeHolder> for CSS {
5858

5959
/// <https://drafts.csswg.org/css-conditional/#dom-css-supports>
6060
fn Supports_(win: &Window, condition: DOMString) -> bool {
61-
let mut input = ParserInput::new(&condition);
61+
let mut input = ParserInput::new(condition.str());
6262
let mut input = Parser::new(&mut input);
6363
let cond = match parse_condition_or_declaration(&mut input) {
6464
Ok(c) => c,

components/script/dom/csskeyframesrule.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl CSSKeyframesRule {
7676
}
7777

7878
/// Given a keyframe selector, finds the index of the first corresponding rule if any
79-
fn find_rule(&self, selector: &str) -> Option<usize> {
80-
let mut input = ParserInput::new(selector);
79+
fn find_rule(&self, selector: &DOMString) -> Option<usize> {
80+
let mut input = ParserInput::new(selector.str());
8181
let mut input = Parser::new(&mut input);
8282
if let Ok(sel) = KeyframeSelector::parse(&mut input) {
8383
let guard = self.cssrule.shared_lock().read();
@@ -117,7 +117,7 @@ impl CSSKeyframesRuleMethods<crate::DomTypeHolder> for CSSKeyframesRule {
117117
fn AppendRule(&self, rule: DOMString, can_gc: CanGc) {
118118
let style_stylesheet = self.cssrule.parent_stylesheet().style_stylesheet();
119119
let rule = Keyframe::parse(
120-
&rule,
120+
rule.str(),
121121
&style_stylesheet.contents,
122122
&style_stylesheet.shared_lock,
123123
);
@@ -161,7 +161,7 @@ impl CSSKeyframesRuleMethods<crate::DomTypeHolder> for CSSKeyframesRule {
161161
// Setting this property to a CSS-wide keyword or `none` does not throw,
162162
// it stores a value that serializes as a quoted string.
163163
self.cssrule.parent_stylesheet().will_modify();
164-
let name = KeyframesName::from_ident(&value);
164+
let name = KeyframesName::from_ident(value.str());
165165
let mut guard = self.cssrule.shared_lock().write();
166166
self.keyframesrule.borrow().write_with(&mut guard).name = name;
167167
self.cssrule.parent_stylesheet().notify_invalidations();

components/script/dom/cssrulelist.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::cell::RefCell;
99
use dom_struct::dom_struct;
1010
use itertools::izip;
1111
use script_bindings::inheritance::Castable;
12+
use script_bindings::str::DOMString;
1213
use servo_arc::Arc;
1314
use style::shared_lock::{Locked, SharedRwLockReadGuard};
1415
use style::stylesheets::{
@@ -105,7 +106,7 @@ impl CSSRuleList {
105106
/// for keyframes-backed rules.
106107
pub(crate) fn insert_rule(
107108
&self,
108-
rule: &str,
109+
rule: &DOMString,
109110
idx: u32,
110111
containing_rule_types: CssRuleTypes,
111112
parse_relative_rule_type: Option<CssRuleType>,
@@ -138,7 +139,7 @@ impl CSSRuleList {
138139
let new_rule = css_rules
139140
.insert_rule(
140141
&parent_stylesheet.shared_lock,
141-
rule,
142+
rule.str(),
142143
&parent_stylesheet.contents,
143144
index,
144145
containing_rule_types,

0 commit comments

Comments
 (0)