script: Allow reusing results from xpath queries (#39392)

This behaviour is optional, but observable. Other browsers implement it,
so we should do it too.

Testing: There are no WPT tests for this, which is fair since the spec
explicitly states implementors may choose to not reuse the result.
Fixes: 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-19 19:19:04 +02:00 committed by GitHub
parent 2c3d580ef1
commit 84577c9fd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 85 additions and 24 deletions

View file

@ -14613,6 +14613,13 @@
{}
]
],
"xpath-result-out-parameter.html": [
"e4206aba44d2c4f6d299d9860d80b5f736094789",
[
null,
{}
]
],
"zero_size_canvas_crash.html": [
"45eb9b559e8d6105baca5ab4d336de520d33b36b",
[

View file

@ -0,0 +1,40 @@
<!doctype html>
<head>
<link rel="help" href="https://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator-evaluate">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<script>
const xmlString = `
<root>
<section>
<item id="a"><name>Item A</name></item>
<item id="b"><name>Item B</name></item>
</section>
</root>
`;
const parser = new DOMParser();
const test_document = parser.parseFromString(xmlString, "application/xml");
test(function () {
const first_result = test_document.evaluate(
"//section/item",
test_document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
const second_result = test_document.evaluate(
"//section/item[@id='b']",
test_document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
first_result
);
assert_equals(first_result, second_result);
}, "Passing an existing xpath result as an out-parameter should overwrite the result");
</script>