mirror of
https://github.com/servo/servo.git
synced 2025-09-27 23:30:08 +01:00
Script: Change the rest of script to not rely on Deref<str> for DOMString (#39481)
This is part of the future work of implementing LazyDOMString as outlined in issue #39479. We use str() method or direct implementations on DOMString for these methods. We also change some types. This is independent of https://github.com/servo/servo/pull/39480 Signed-off-by: Narfinger Narfinger@users.noreply.github.com Testing: This is essentially just renaming a method and a type and should not change functionality. Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
parent
9713bb9e1b
commit
1e471b9b41
50 changed files with 219 additions and 132 deletions
|
@ -75,7 +75,7 @@ pub enum StringificationBehavior {
|
|||
// https://heycam.github.io/webidl/#es-DOMString
|
||||
impl ToJSValConvertible for DOMString {
|
||||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
(**self).to_jsval(cx, rval);
|
||||
self.str().to_jsval(cx, rval);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -517,7 +517,10 @@ pub(crate) fn report_cross_origin_denial<D: DomTypes>(
|
|||
debug!(
|
||||
"permission denied to {} property {} on cross-origin object",
|
||||
access,
|
||||
id_to_source(cx, id).as_deref().unwrap_or("< error >"),
|
||||
id_to_source(cx, id)
|
||||
.as_ref()
|
||||
.map(|source| source.str())
|
||||
.unwrap_or("< error >"),
|
||||
);
|
||||
let in_realm_proof = AlreadyInRealm::assert_for_cx(cx);
|
||||
unsafe {
|
||||
|
|
|
@ -36,7 +36,7 @@ pub trait RecordKey: Eq + Hash + Sized {
|
|||
|
||||
impl RecordKey for DOMString {
|
||||
fn to_utf16_vec(&self) -> Vec<u16> {
|
||||
self.encode_utf16().collect::<Vec<_>>()
|
||||
self.str().encode_utf16().collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
unsafe fn from_id(cx: *mut JSContext, id: HandleId) -> Result<ConversionResult<Self>, ()> {
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::default::Default;
|
|||
use std::hash::{Hash, Hasher};
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::str::FromStr;
|
||||
use std::str::{Chars, EncodeUtf16, FromStr};
|
||||
use std::sync::LazyLock;
|
||||
use std::{fmt, ops, slice, str};
|
||||
|
||||
|
@ -18,6 +18,7 @@ use js::rust::wrappers::ToJSON;
|
|||
use js::rust::{HandleObject, HandleValue};
|
||||
use num_traits::Zero;
|
||||
use regex::Regex;
|
||||
use style::str::HTML_SPACE_CHARACTERS;
|
||||
use stylo_atoms::Atom;
|
||||
|
||||
use crate::error::Error;
|
||||
|
@ -296,6 +297,67 @@ impl DOMString {
|
|||
self.0 = parsed_value.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
// What follows are the functions inherited from std::string
|
||||
pub fn make_ascii_lowercase(&mut self) {
|
||||
self.0.make_ascii_lowercase();
|
||||
}
|
||||
|
||||
pub fn to_ascii_lowercase(&self) -> String {
|
||||
self.0.to_ascii_lowercase()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.0.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
pub fn chars(&self) -> Chars<'_> {
|
||||
self.0.chars()
|
||||
}
|
||||
|
||||
pub fn parse<T: FromStr>(&self) -> Result<T, <T as FromStr>::Err> {
|
||||
self.0.parse::<T>()
|
||||
}
|
||||
|
||||
pub fn contains(&self, needle: &str) -> bool {
|
||||
self.0.contains(needle)
|
||||
}
|
||||
|
||||
pub fn to_lowercase(&self) -> String {
|
||||
self.0.to_lowercase()
|
||||
}
|
||||
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
self.0.as_bytes()
|
||||
}
|
||||
|
||||
pub fn to_uppercase(&self) -> String {
|
||||
self.0.to_uppercase()
|
||||
}
|
||||
|
||||
pub fn encode_utf16(&self) -> EncodeUtf16<'_> {
|
||||
self.0.encode_utf16()
|
||||
}
|
||||
|
||||
pub fn find(&self, c: char) -> Option<usize> {
|
||||
self.0.find(c)
|
||||
}
|
||||
|
||||
pub fn starts_with(&self, c: char) -> bool {
|
||||
self.0.starts_with(c)
|
||||
}
|
||||
|
||||
pub fn starts_with_str(&self, needle: &str) -> bool {
|
||||
self.0.starts_with(needle)
|
||||
}
|
||||
|
||||
pub fn contains_html_space_characters(&self) -> bool {
|
||||
self.0.contains(HTML_SPACE_CHARACTERS)
|
||||
}
|
||||
}
|
||||
|
||||
/// Because this converts to a DOMString it becomes UTF-8 encoded which is closer to
|
||||
|
@ -404,6 +466,12 @@ impl PartialEq<str> for DOMString {
|
|||
}
|
||||
}
|
||||
|
||||
impl PartialEq<DOMString> for str {
|
||||
fn eq(&self, other: &DOMString) -> bool {
|
||||
self == other.str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PartialEq<&'a str> for DOMString {
|
||||
fn eq(&self, other: &&'a str) -> bool {
|
||||
&**self == *other
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue