diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/str.rs | 19 | ||||
-rw-r--r-- | components/script/dom/cssstyledeclaration.rs | 56 | ||||
-rw-r--r-- | components/script/dom/document.rs | 22 | ||||
-rw-r--r-- | components/script/dom/htmlmetaelement.rs | 10 | ||||
-rw-r--r-- | components/script/dom/navigator.rs | 7 |
5 files changed, 56 insertions, 58 deletions
diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 7ec868698c8..3489a2da617 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -9,13 +9,13 @@ use std::hash::{Hash, Hasher}; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::str::FromStr; +use std::sync::LazyLock; use std::{fmt, ops, str}; use chrono::prelude::{Utc, Weekday}; use chrono::{Datelike, TimeZone}; use cssparser::CowRcStr; use html5ever::{LocalName, Namespace}; -use lazy_static::lazy_static; use num_traits::Zero; use regex::Regex; use servo_atoms::Atom; @@ -430,10 +430,10 @@ impl DOMString { /// <https://html.spec.whatwg.org/multipage/#valid-floating-point-number> pub fn is_valid_floating_point_number_string(&self) -> bool { - lazy_static! { - static ref RE: Regex = - Regex::new(r"^-?(?:\d+\.\d+|\d+|\.\d+)(?:(e|E)(\+|\-)?\d+)?$").unwrap(); - } + static RE: LazyLock<Regex> = LazyLock::new(|| { + Regex::new(r"^-?(?:\d+\.\d+|\d+|\.\d+)(?:(e|E)(\+|\-)?\d+)?$").unwrap() + }); + RE.is_match(&self.0) && self.parse_floating_point_number().is_some() } @@ -537,13 +537,14 @@ impl DOMString { /// <https://html.spec.whatwg.org/multipage/#valid-e-mail-address> pub fn is_valid_email_address_string(&self) -> bool { - lazy_static! { - static ref RE: Regex = Regex::new(concat!( + static RE: LazyLock<Regex> = LazyLock::new(|| { + Regex::new(concat!( r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?", r"(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" )) - .unwrap(); - } + .unwrap() + }); + RE.is_match(&self.0) } diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 0090bb54eb7..5777e0fe74b 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -3,10 +3,10 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::cmp::Ordering; +use std::sync::LazyLock; use dom_struct::dom_struct; use html5ever::local_name; -use lazy_static::lazy_static; use servo_arc::Arc; use servo_url::ServoUrl; use style::attr::AttrValue; @@ -344,35 +344,33 @@ impl CSSStyleDeclaration { } } -lazy_static! { - static ref ENABLED_LONGHAND_PROPERTIES: Vec<LonghandId> = { - // The 'all' shorthand contains all the enabled longhands with 2 exceptions: - // 'direction' and 'unicode-bidi', so these must be added afterward. - let mut enabled_longhands: Vec<LonghandId> = ShorthandId::All.longhands().collect(); - if PropertyId::NonCustom(LonghandId::Direction.into()).enabled_for_all_content() { - enabled_longhands.push(LonghandId::Direction); - } - if PropertyId::NonCustom(LonghandId::UnicodeBidi.into()).enabled_for_all_content() { - enabled_longhands.push(LonghandId::UnicodeBidi); - } +static ENABLED_LONGHAND_PROPERTIES: LazyLock<Vec<LonghandId>> = LazyLock::new(|| { + // The 'all' shorthand contains all the enabled longhands with 2 exceptions: + // 'direction' and 'unicode-bidi', so these must be added afterward. + let mut enabled_longhands: Vec<LonghandId> = ShorthandId::All.longhands().collect(); + if PropertyId::NonCustom(LonghandId::Direction.into()).enabled_for_all_content() { + enabled_longhands.push(LonghandId::Direction); + } + if PropertyId::NonCustom(LonghandId::UnicodeBidi.into()).enabled_for_all_content() { + enabled_longhands.push(LonghandId::UnicodeBidi); + } - // Sort lexicographically, but with vendor-prefixed properties after standard ones. - enabled_longhands.sort_unstable_by(|a, b| { - let a = a.name(); - let b = b.name(); - let is_a_vendor_prefixed = a.starts_with('-'); - let is_b_vendor_prefixed = b.starts_with('-'); - if is_a_vendor_prefixed == is_b_vendor_prefixed { - a.partial_cmp(b).unwrap() - } else if is_b_vendor_prefixed { - Ordering::Less - } else { - Ordering::Greater - } - }); - enabled_longhands - }; -} + // Sort lexicographically, but with vendor-prefixed properties after standard ones. + enabled_longhands.sort_unstable_by(|a, b| { + let a = a.name(); + let b = b.name(); + let is_a_vendor_prefixed = a.starts_with('-'); + let is_b_vendor_prefixed = b.starts_with('-'); + if is_a_vendor_prefixed == is_b_vendor_prefixed { + a.partial_cmp(b).unwrap() + } else if is_b_vendor_prefixed { + Ordering::Less + } else { + Ordering::Greater + } + }); + enabled_longhands +}); impl CSSStyleDeclarationMethods for CSSStyleDeclaration { // https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-length diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 5dfe624a587..bd4773439b3 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -11,6 +11,7 @@ use std::default::Default; use std::mem; use std::rc::Rc; use std::slice::from_ref; +use std::sync::LazyLock; use std::time::{Duration, Instant}; use base::id::BrowsingContextId; @@ -28,7 +29,6 @@ use hyper_serde::Serde; use ipc_channel::ipc::{self, IpcSender}; use js::rust::{HandleObject, HandleValue}; use keyboard_types::{Code, Key, KeyState}; -use lazy_static::lazy_static; use metrics::{ InteractiveFlag, InteractiveMetrics, InteractiveWindow, ProfilerMetadataFactory, ProgressiveWebMetric, @@ -3219,17 +3219,15 @@ impl Document { anchors: Default::default(), applets: Default::default(), style_shared_lock: { - lazy_static! { - /// Per-process shared lock for author-origin stylesheets - /// - /// FIXME: make it per-document or per-pipeline instead: - /// <https://github.com/servo/servo/issues/16027> - /// (Need to figure out what to do with the style attribute - /// of elements adopted into another document.) - static ref PER_PROCESS_AUTHOR_SHARED_LOCK: StyleSharedRwLock = { - StyleSharedRwLock::new() - }; - } + /// Per-process shared lock for author-origin stylesheets + /// + /// FIXME: make it per-document or per-pipeline instead: + /// <https://github.com/servo/servo/issues/16027> + /// (Need to figure out what to do with the style attribute + /// of elements adopted into another document.) + static PER_PROCESS_AUTHOR_SHARED_LOCK: LazyLock<StyleSharedRwLock> = + LazyLock::new(|| StyleSharedRwLock::new()); + PER_PROCESS_AUTHOR_SHARED_LOCK.clone() //StyleSharedRwLock::new() }, diff --git a/components/script/dom/htmlmetaelement.rs b/components/script/dom/htmlmetaelement.rs index 1cbd709ae1a..45673c55652 100644 --- a/components/script/dom/htmlmetaelement.rs +++ b/components/script/dom/htmlmetaelement.rs @@ -3,6 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use std::str::FromStr; +use std::sync::LazyLock; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; @@ -146,8 +147,8 @@ impl HTMLMetaElement { } // 2-11 - lazy_static::lazy_static! { - static ref REFRESH_REGEX: Regex = Regex::new( + static REFRESH_REGEX: LazyLock<Regex> = LazyLock::new(|| { + Regex::new( r#"(?x) ^ \s* # 3 @@ -169,8 +170,9 @@ impl HTMLMetaElement { $ "#, ) - .unwrap(); - } + .unwrap() + }); + let mut url_record = document.url(); let captures = if let Some(captures) = REFRESH_REGEX.captures(content.as_bytes()) { captures diff --git a/components/script/dom/navigator.rs b/components/script/dom/navigator.rs index 83e59c3ea56..850a4d2e0b6 100644 --- a/components/script/dom/navigator.rs +++ b/components/script/dom/navigator.rs @@ -4,10 +4,10 @@ use std::cell::Cell; use std::convert::TryInto; +use std::sync::LazyLock; use dom_struct::dom_struct; use js::jsval::JSVal; -use lazy_static::lazy_static; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::NavigatorBinding::NavigatorMethods; @@ -32,9 +32,8 @@ use crate::dom::xrsystem::XRSystem; use crate::script_runtime::JSContext; pub(super) fn hardware_concurrency() -> u64 { - lazy_static! { - static ref CPUS: u64 = num_cpus::get().try_into().unwrap_or(1); - } + static CPUS: LazyLock<u64> = LazyLock::new(|| num_cpus::get().try_into().unwrap_or(1)); + *CPUS } |