Implement selector matching for :nth-child(An+B of selector list) and :nth-last-child(An+B of selector list)

Since we have been using a single hash map to cache all :nth-child
indices (with no selector list), each different selector will need its
own cache.

As a side note, this patch does not address invalidation.

Differential Revision: https://phabricator.services.mozilla.com/D166266

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1808228
gecko-commit: 798bdb0f29c62ab3691b4815250ad2760123d36e
gecko-reviewers: emilio
diff --git a/css/selectors/nth-child-of-nesting-ref.html b/css/selectors/nth-child-of-nesting-ref.html
new file mode 100644
index 0000000..cdd66ed
--- /dev/null
+++ b/css/selectors/nth-child-of-nesting-ref.html
@@ -0,0 +1,17 @@
+<!doctype html>
+<html>
+<body>
+    <p>White</p>
+    <p style="background-color: lime">Green</p>
+    <p>White</p>
+    <p>White</p>
+    <p>White</p>
+    <p style="background-color: lime">Green</p>
+    <p>White</p>
+    <p>White</p>
+    <p>White</p>
+    <p style="background-color: lime">Green</p>
+    <p>White</p>
+    <p>White</p>
+</body>
+</html>
diff --git a/css/selectors/nth-child-of-nesting.html b/css/selectors/nth-child-of-nesting.html
new file mode 100644
index 0000000..8512606
--- /dev/null
+++ b/css/selectors/nth-child-of-nesting.html
@@ -0,0 +1,28 @@
+<!doctype html>
+<html>
+<head>
+<title>:nth-last-child nesting</title>
+<link rel="help" href="https://w3c.github.io/csswg-drafts/selectors-4/#child-index">
+<link rel=author href="mailto:zach@zrhoffman.net" title="Zach Hoffman">
+<link rel="match" href="nth-child-of-nesting-ref.html">
+<style>
+:nth-child(2n + 1 of :nth-child(n of .target)) {
+    background-color: lime;
+}
+</style>
+</head>
+<body>
+    <p>White</p>
+    <p class="target">Green</p>
+    <p>White</p>
+    <p class="target">White</p>
+    <p>White</p>
+    <p class="target">Green</p>
+    <p>White</p>
+    <p class="target">White</p>
+    <p>White</p>
+    <p class="target">Green</p>
+    <p>White</p>
+    <p class="target">White</p>
+</body>
+</html>
diff --git a/css/selectors/nth-last-child-of-nesting.html b/css/selectors/nth-last-child-of-nesting.html
new file mode 100644
index 0000000..0dd18f2
--- /dev/null
+++ b/css/selectors/nth-last-child-of-nesting.html
@@ -0,0 +1,28 @@
+<!doctype html>
+<html>
+<head>
+<title>:nth-last-child nesting</title>
+<link rel="help" href="https://w3c.github.io/csswg-drafts/selectors-4/#child-index">
+<link rel=author href="mailto:zach@zrhoffman.net" title="Zach Hoffman">
+<link rel="match" href="nth-child-of-nesting-ref.html">
+<style>
+:nth-last-child(2n - 2 of :nth-last-child(n of .target)) {
+    background-color: lime;
+}
+</style>
+</head>
+<body>
+    <p>White</p>
+    <p class="target">Green</p>
+    <p>White</p>
+    <p class="target">White</p>
+    <p>White</p>
+    <p class="target">Green</p>
+    <p>White</p>
+    <p class="target">White</p>
+    <p>White</p>
+    <p class="target">Green</p>
+    <p>White</p>
+    <p class="target">White</p>
+</body>
+</html>