Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Attributes, Tag Name and Value on Element creation #377

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 24 additions & 16 deletions src/browser/tab/element/mod.rs
Expand Up @@ -31,6 +31,9 @@ pub struct Element<'a> {
pub backend_node_id: DOM::NodeId,
pub node_id: DOM::NodeId,
pub parent: &'a super::Tab,
pub attributes: Option<Vec<String>>,
pub tag_name: String,
pub value: String,
}

impl<'a> Debug for Element<'a> {
Expand All @@ -49,28 +52,33 @@ impl<'a> Element<'a> {
return Err(NoElementFound {}.into());
}

let backend_node_id = parent
.describe_node(node_id)
.map_err(NoElementFound::map)?
.backend_node_id;

let remote_object_id = {
let object = parent
.call_method(DOM::ResolveNode {
backend_node_id: Some(backend_node_id),
node_id: None,
object_group: None,
execution_context_id: None,
})?
.object;
object.object_id.expect("couldn't find object ID")
};
let node = parent.describe_node(node_id).map_err(NoElementFound::map)?;

let attributes = node.attributes;
let tag_name = node.node_name;

let backend_node_id = node.backend_node_id;

let object = parent
.call_method(DOM::ResolveNode {
backend_node_id: Some(backend_node_id),
node_id: None,
object_group: None,
execution_context_id: None,
})?
.object;

let value = object.value.unwrap_or("".into()).to_string();
let remote_object_id = object.object_id.expect("couldn't find object ID");

Ok(Element {
remote_object_id,
backend_node_id,
node_id,
parent,
attributes,
tag_name,
value,
})
}

Expand Down