script: Use xpath ns resolver to resolve namespace prefixes (#39321)

The xpath resolver is a function provided by the user to resolve
namespace prefixes. Previously, we were ignoring the argument.

Testing: New web platform tests start to pass
Part of https://github.com/servo/servo/issues/34527

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker 2025-09-16 19:25:45 +02:00 committed by GitHub
parent f3d5617349
commit 1898a740a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 164 additions and 132 deletions

View file

@ -2,10 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::rc::Rc;
use dom_struct::dom_struct;
use js::rust::HandleObject;
use crate::dom::bindings::codegen::Bindings::XPathExpressionBinding::XPathExpressionMethods;
use crate::dom::bindings::codegen::Bindings::XPathNSResolverBinding::XPathNSResolver;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object_with_proto};
use crate::dom::bindings::root::{Dom, DomRoot};
@ -45,15 +48,13 @@ impl XPathExpression {
can_gc,
)
}
}
impl XPathExpressionMethods<crate::DomTypeHolder> for XPathExpression {
/// <https://dom.spec.whatwg.org/#dom-xpathexpression-evaluate>
fn Evaluate(
pub(crate) fn evaluate_internal(
&self,
context_node: &Node,
result_type_num: u16,
_result: Option<&XPathResult>,
resolver: Option<Rc<XPathNSResolver>>,
can_gc: CanGc,
) -> Fallible<DomRoot<XPathResult>> {
let result_type = XPathResultType::try_from(result_type_num)
@ -62,8 +63,7 @@ impl XPathExpressionMethods<crate::DomTypeHolder> for XPathExpression {
let global = self.global();
let window = global.as_window();
let result_value = evaluate_parsed_xpath(&self.parsed_expression, context_node)
.map_err(|_e| Error::Operation)?;
let result_value = evaluate_parsed_xpath(&self.parsed_expression, context_node, resolver)?;
// TODO(vlindhol): support putting results into mutable `_result` as per the spec
Ok(XPathResult::new(
@ -75,3 +75,16 @@ impl XPathExpressionMethods<crate::DomTypeHolder> for XPathExpression {
))
}
}
impl XPathExpressionMethods<crate::DomTypeHolder> for XPathExpression {
/// <https://dom.spec.whatwg.org/#dom-xpathexpression-evaluate>
fn Evaluate(
&self,
context_node: &Node,
result_type_num: u16,
result: Option<&XPathResult>,
can_gc: CanGc,
) -> Fallible<DomRoot<XPathResult>> {
self.evaluate_internal(context_node, result_type_num, result, None, can_gc)
}
}