Commit Graph

12 Commits

Author SHA1 Message Date
Ashwin Naren
e0eb23ce18 script: Finish converting all error message enum variants to Option<String> (#40750)
I used find and replace to finish the job. All this PR does is replace
all `Error::<error_name>` occurrences with `Error::<error_name>(None)`.

Testing: Refactor
Fixes: #39053

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-11-20 06:20:47 +00:00
Simon Wülker
c039078ab3 xpath: Apply predicate list before sorting result when evaluating location step expression (#40592)
The result of a predicate can depend on the position of the node in its
set, and this position is dependent on the axis that the node set came
from. This is specified in
https://www.w3.org/TR/1999/REC-xpath-19991116/#predicates.

Additionally, this change fixes a small bug in the implementation of
`preceding::` (https://github.com/servo/servo/pull/40588) where the root
of a subtree would be included twice. That wasn't discovered earlier
because nodes are deduplicated at the end of the evaluation.

Testing: New tests start to pass, this change adds more tests

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-13 10:27:06 +00:00
Simon Wülker
5ecf09d76a xpath: Fix implementation for preceding::/following:: axes (#40588)
`preceding::` needs to yield all preceding nodes, excluding ancestors.
`following::` needs to yield all following nodes, excluding descendants.

Both `Node::preceding_nodes` and `Node::following_nodes` (which we're
currently using) don't quite match these requirements, so we have to
engineer some xpath-specific iterators.

Testing: New tests start to pass

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-12 10:40:36 +00:00
Simon Wülker
9193b1d310 xpath: Enforce tree order in node sets during evaluation (#40451)
This change adds `NodeSet`, which is more or less a `Vec<Node>` that
knows whether it is sorted, and can sort itself if it isn't. This allows
us to efficiently enforce tree order in intermediary node sets that
occur during evaluation.

Notably, in many cases it is not necessary to sort at all, because all
location step expressions yield node sets that are either already sorted
(`Axis::DescendantOrSelf` for example), or that are in inverse tree
order (`Axis::PrecedingSiblings` for example).

There's still optimization work left to be done. When merging two node
sets that are already sorted then we could use merge sort instead of
appending one to the other and naively sorting. But I suspect that the
sorting algorithm used by the standard library is already well tuned to
handle such cases...

Testing: This change adds a web platform test
Fixes https://github.com/servo/servo/issues/40435

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-06 12:24:07 +00:00
Simon Wülker
d3fd90b916 xpath: Throw a NAMESPACE_ERR DOMException when namespace resolver callback returns invalid value or throws (#40167)
I always thought that exceptions thrown in namespace resolver callbacks
should be propagated to the call site of `document.evaluate`.
That is not the case - the exception is silently swallowed and you get a
namespace error, the same as if the callback had returned any other
invalid value.

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

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-10-27 07:31:28 +00:00
Simon Wülker
ada2efd7d6 xpath: Compare local names in html documents case-insensitively when there's no prefix (#40161)
Relevant gecko code:
https://searchfox.org/firefox-main/rev/16707ce1df112d9e067175ed8e16be717ab684c4/dom/xslt/xpath/txExprParser.cpp#839.

Testing: New tests start to pass
Part of #34527

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-10-25 23:25:01 +00:00
Simon Wülker
74859780f1 xpath: Replace nom with hand-written parsing rules (#39977)
The new parser is more verbose, but also more correct and easier to
reason about. Apologies for the size of the change, I don't think
there's an alternative to swapping out the entire parser at once.

Testing: Covered by existing tests, new tests also start to pass
Fixes https://github.com/servo/servo/issues/38552
Fixes https://github.com/servo/servo/issues/38553
Fixes https://github.com/servo/servo/issues/39596
Closes https://github.com/servo/servo/issues/39602
Part of https://github.com/servo/servo/issues/34527

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-10-25 03:23:02 +00:00
Simon Wülker
184fc21456 xpath: Provide error message when throwing SyntaxError from parsing (#40103)
This change was split of from https://github.com/servo/servo/pull/39977
to make that PR easier to review.

The `Debug` impl for the error is not very useful yet, but
https://github.com/servo/servo/pull/39977 swaps out the error type
itself, so there's no point in improving it here.

Testing: I've manually tested that the error message appears. I don't
think we have tests for error messages.
Part of #34527

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-10-23 14:37:24 +00:00
Simon Wülker
a417dc5f23 xpath: Don't panic in node name test when namespace prefix is unknown (#39952)
We don't need to care about namespace prefixes in name tests because
they are already resolved to namespaces at this point.

The old implementation was also masking a few other small bugs which
I've fixed here. When the namespace resolver doesn't give us any results
then we should not lookup the namespace on the node itself. In XPath,
namespaces on html elements in html documents are compared a in a
relaxed way, and we were previously also using the relaxed comparison
mode on non-html elements in html documents (like svg).

Testing: Existing tests continue to pass (and the web platform tests
contain numerous namespace tests which cover this behaviour)
Fixes https://github.com/servo/servo/issues/39939
Part of #34527

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-10-18 07:14:37 +00:00
Simon Wülker
01641b2374 xpath: let absolute path expressions begin at the root node (#39965)
Testing: This change adds a test
Fixes #39964
Part of https://github.com/servo/servo/issues/34527

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-10-17 18:11:53 +00:00
Simon Wülker
a037ef0fc4 xpath: Let the parents of attribute nodes be their owner elements (#39749)
This is different from the rest of the DOM, see
https://www.w3.org/TR/1999/REC-xpath-19991116/#attribute-nodes. Luckily,
this can cleanly be implemented for XPath because we already abstract
over the concrete DOM implementation.

Testing: This change adds a test
Part of #34527

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-10-10 04:06:44 +00:00
Simon Wülker
e5017b1b50 Move XPath implementation into its own crate (#39546)
XPath (and, in the future, XSLT) is only loosely coupled to `script`. As
`script` is already very large, I'd like to move the xpath parser and
evaluator into a seperate crate. Doing so allows us to iterate on it
more easily, without having to recompile `script`. Abstracting over the
concrete DOM implementation could also allow us to write some more
comprehensive unit tests.

Testing: Covered by existing web platform tests
Part of https://github.com/servo/servo/issues/34527
Fixes https://github.com/servo/servo/issues/39551

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-09-30 19:55:10 +00:00