script: Upgrade node_ids to pipeline_to_node_ids to track the owner pipeline of the node (#37213)

Upgrade `ScriptThread::node_ids` to `pipeline_to_node_ids` to track the
owner pipeline of the node
This will enable webdriver to know if it is requesting element from
other origins and properly distinguish "stale element reference" from
"no such element".

Testing: [Action
run](https://github.com/yezhizhen/servo/actions/runs/15385994907), no
regression. We can now pass WebDriver "cross origin" tests.

Fixes: #35749

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-06-02 20:26:45 +08:00 committed by GitHub
parent 2a07ef01f5
commit c28394f476
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 61 additions and 43 deletions

View file

@ -1261,13 +1261,13 @@ impl Node {
}
}
pub(crate) fn unique_id(&self) -> String {
pub(crate) fn unique_id(&self, pipeline: PipelineId) -> String {
let mut rare_data = self.ensure_rare_data();
if rare_data.unique_id.is_none() {
let id = UniqueId::new();
ScriptThread::save_node_id(id.borrow().simple().to_string());
rare_data.unique_id = Some(id);
let node_id = UniqueId::new();
ScriptThread::save_node_id(pipeline, node_id.borrow().simple().to_string());
rare_data.unique_id = Some(node_id);
}
rare_data
.unique_id
@ -1281,6 +1281,7 @@ impl Node {
pub(crate) fn summarize(&self, can_gc: CanGc) -> NodeInfo {
let USVString(base_uri) = self.BaseURI();
let node_type = self.NodeType();
let pipeline = self.owner_document().window().pipeline_id();
let maybe_shadow_root = self.downcast::<ShadowRoot>();
let shadow_root_mode = maybe_shadow_root
@ -1288,7 +1289,7 @@ impl Node {
.map(ShadowRootMode::convert);
let host = maybe_shadow_root
.map(ShadowRoot::Host)
.map(|host| host.upcast::<Node>().unique_id());
.map(|host| host.upcast::<Node>().unique_id(pipeline));
let is_shadow_host = self.downcast::<Element>().is_some_and(|potential_host| {
let Some(root) = potential_host.shadow_root() else {
return false;
@ -1310,12 +1311,12 @@ impl Node {
.map(|style| style.Display().into());
NodeInfo {
unique_id: self.unique_id(),
unique_id: self.unique_id(pipeline),
host,
base_uri,
parent: self
.GetParentNode()
.map_or("".to_owned(), |node| node.unique_id()),
.map_or("".to_owned(), |node| node.unique_id(pipeline)),
node_type,
is_top_level_document: node_type == NodeConstants::DOCUMENT_NODE,
node_name: String::from(self.NodeName()),