mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
script: Lazy init and reuse const BOOLEAN_ATTRIBUTES
(#38423)
Follow up of #38401. - The constant String array was recreated for every invocation. Chromium store this as a global const. https://source.chromium.org/chromium/chromium/src/+/main:chrome/test/chromedriver/element_commands.cc;l=48-94?q=chrome%2Ftest%2Fchromedriver%2Felement_commands.cc We now use static `LazyLock` to lazy init and avoid recreation. - Clean up some comments Testing: Just refactor. --------- Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
parent
a27715a5a8
commit
ee1bfa61ce
2 changed files with 39 additions and 35 deletions
|
@ -5,6 +5,7 @@
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cell::LazyCell;
|
use std::cell::LazyCell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use devtools_traits::AttrInfo;
|
use devtools_traits::AttrInfo;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
@ -298,6 +299,7 @@ pub(crate) fn is_boolean_attribute(name: &str) -> bool {
|
||||||
// webdriver/tests/classic/get_element_attribute/get.py
|
// webdriver/tests/classic/get_element_attribute/get.py
|
||||||
//
|
//
|
||||||
// [1] <https://html.spec.whatwg.org/multipage/#attributes-3>
|
// [1] <https://html.spec.whatwg.org/multipage/#attributes-3>
|
||||||
|
static BOOLEAN_ATTRIBUTES: LazyLock<[&str; 30]> = LazyLock::new(|| {
|
||||||
[
|
[
|
||||||
"allowfullscreen",
|
"allowfullscreen",
|
||||||
"alpha",
|
"alpha",
|
||||||
|
@ -330,6 +332,9 @@ pub(crate) fn is_boolean_attribute(name: &str) -> bool {
|
||||||
"shadowrootdelegatesfocus",
|
"shadowrootdelegatesfocus",
|
||||||
"shadowrootserializable",
|
"shadowrootserializable",
|
||||||
]
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
BOOLEAN_ATTRIBUTES
|
||||||
.iter()
|
.iter()
|
||||||
.any(|&boolean_attr| boolean_attr.eq_ignore_ascii_case(name))
|
.any(|&boolean_attr| boolean_attr.eq_ignore_ascii_case(name))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1584,7 +1584,6 @@ pub(crate) fn handle_get_attribute(
|
||||||
.send(
|
.send(
|
||||||
get_known_element(documents, pipeline, node_id).map(|element| {
|
get_known_element(documents, pipeline, node_id).map(|element| {
|
||||||
if is_boolean_attribute(&name) {
|
if is_boolean_attribute(&name) {
|
||||||
// element.get_attribute_by_name(DOMString::from(name)).map(|_| String::from("true"))
|
|
||||||
if element.HasAttribute(DOMString::from(name)) {
|
if element.HasAttribute(DOMString::from(name)) {
|
||||||
Some(String::from("true"))
|
Some(String::from("true"))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue