<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[179535] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/179535">179535</a></dd>
<dt>Author</dt> <dd>benjamin@webkit.org</dd>
<dt>Date</dt> <dd>2015-02-02 20:11:42 -0800 (Mon, 02 Feb 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>JIT Compile simple cases of :nth-last-child()
https://bugs.webkit.org/show_bug.cgi?id=141053

Reviewed by Andreas Kling.

Source/WebCore:

This patch adds the code generator for :nth-last-child(), skipping
any :nth-last-child(An+B of selector list).

The code generator is boring here, nothing fancy.
There is no optimization opportunity here so it is basically the same
speed as the code generated by Clang when the simple selector is alone.

The only reason to JIT compile this is to avoid going to slow-path
for every selector that contain :nth-last-child().

* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addNthChildType):
The code creating the intermediate representation of :nth-child() is exactly
the same as what we need for :nth-last-child(). I extracted the code from addPseudoClassType()
and share it for both simple selectors.

(WebCore::SelectorCompiler::addPseudoClassType):
I fail :nth-last-child(An+B of selector list). Let's add it later.

(WebCore::SelectorCompiler::minimumRegisterRequirements):
Oops, there was a bug with nthChildOfFilters.

(WebCore::SelectorCompiler::hasAnyCombinators):
(WebCore::SelectorCompiler::computeBacktrackingMemoryRequirements):
(WebCore::SelectorCompiler::computeBacktrackingInformation):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching):
(WebCore::SelectorCompiler::setChildrenAffectedByBackwardPositionalRules):
(WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsNthLastChild):

LayoutTests:

There was almost no test coverage for :nth-last-child(). I copied the main tests
from :nth-child() and updated the expected results.

This is not ideal because we should have style update tests targetting
backward invalidation... Still better than nothing :)

* fast/selectors/nth-last-child-as-first-simple-selector-style-update-expected.txt: Added.
* fast/selectors/nth-last-child-as-first-simple-selector-style-update.html: Added.
* fast/selectors/nth-last-child-basics-expected.txt: Added.
* fast/selectors/nth-last-child-basics.html: Added.
* fast/selectors/nth-last-child-bounds-expected.txt: Added.
* fast/selectors/nth-last-child-bounds.html: Added.
* fast/selectors/nth-last-child-chained-expected.txt: Added.
* fast/selectors/nth-last-child-chained.html: Added.
* fast/selectors/nth-last-child-on-root-expected.txt: Added.
* fast/selectors/nth-last-child-on-root.html: Added.
* fast/selectors/nth-last-child-style-update-expected.txt: Added.
* fast/selectors/nth-last-child-style-update.html: Added.
* fast/selectors/nth-last-child-with-backtracking-expected.txt: Added.
* fast/selectors/nth-last-child-with-backtracking.html: Added.
* fast/selectors/several-nth-last-child-expected.txt: Added.
* fast/selectors/several-nth-last-child.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssjitSelectorCompilercpp">trunk/Source/WebCore/cssjit/SelectorCompiler.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildasfirstsimpleselectorstyleupdateexpectedtxt">trunk/LayoutTests/fast/selectors/nth-last-child-as-first-simple-selector-style-update-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildasfirstsimpleselectorstyleupdatehtml">trunk/LayoutTests/fast/selectors/nth-last-child-as-first-simple-selector-style-update.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildbasicsexpectedtxt">trunk/LayoutTests/fast/selectors/nth-last-child-basics-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildbasicshtml">trunk/LayoutTests/fast/selectors/nth-last-child-basics.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildboundsexpectedtxt">trunk/LayoutTests/fast/selectors/nth-last-child-bounds-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildboundshtml">trunk/LayoutTests/fast/selectors/nth-last-child-bounds.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildchainedexpectedtxt">trunk/LayoutTests/fast/selectors/nth-last-child-chained-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildchainedhtml">trunk/LayoutTests/fast/selectors/nth-last-child-chained.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildonrootexpectedtxt">trunk/LayoutTests/fast/selectors/nth-last-child-on-root-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildonroothtml">trunk/LayoutTests/fast/selectors/nth-last-child-on-root.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildstyleupdateexpectedtxt">trunk/LayoutTests/fast/selectors/nth-last-child-style-update-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildstyleupdatehtml">trunk/LayoutTests/fast/selectors/nth-last-child-style-update.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildwithbacktrackingexpectedtxt">trunk/LayoutTests/fast/selectors/nth-last-child-with-backtracking-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsnthlastchildwithbacktrackinghtml">trunk/LayoutTests/fast/selectors/nth-last-child-with-backtracking.html</a></li>
<li><a href="#trunkLayoutTestsfastselectorsseveralnthlastchildexpectedtxt">trunk/LayoutTests/fast/selectors/several-nth-last-child-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastselectorsseveralnthlastchildhtml">trunk/LayoutTests/fast/selectors/several-nth-last-child.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (179534 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-02-03 03:08:33 UTC (rev 179534)
+++ trunk/LayoutTests/ChangeLog        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2015-02-02  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
+
+        JIT Compile simple cases of :nth-last-child()
+        https://bugs.webkit.org/show_bug.cgi?id=141053
+
+        Reviewed by Andreas Kling.
+
+        There was almost no test coverage for :nth-last-child(). I copied the main tests
+        from :nth-child() and updated the expected results.
+
+        This is not ideal because we should have style update tests targetting
+        backward invalidation... Still better than nothing :)
+
+        * fast/selectors/nth-last-child-as-first-simple-selector-style-update-expected.txt: Added.
+        * fast/selectors/nth-last-child-as-first-simple-selector-style-update.html: Added.
+        * fast/selectors/nth-last-child-basics-expected.txt: Added.
+        * fast/selectors/nth-last-child-basics.html: Added.
+        * fast/selectors/nth-last-child-bounds-expected.txt: Added.
+        * fast/selectors/nth-last-child-bounds.html: Added.
+        * fast/selectors/nth-last-child-chained-expected.txt: Added.
+        * fast/selectors/nth-last-child-chained.html: Added.
+        * fast/selectors/nth-last-child-on-root-expected.txt: Added.
+        * fast/selectors/nth-last-child-on-root.html: Added.
+        * fast/selectors/nth-last-child-style-update-expected.txt: Added.
+        * fast/selectors/nth-last-child-style-update.html: Added.
+        * fast/selectors/nth-last-child-with-backtracking-expected.txt: Added.
+        * fast/selectors/nth-last-child-with-backtracking.html: Added.
+        * fast/selectors/several-nth-last-child-expected.txt: Added.
+        * fast/selectors/several-nth-last-child.html: Added.
+
</ins><span class="cx"> 2015-02-02  Gyuyoung Kim  &lt;gyuyoung.kim@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, EFL gardening. Update flakiness tests on W3C SVG 1.1 tests.
</span></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildasfirstsimpleselectorstyleupdateexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-as-first-simple-selector-style-update-expected.txt (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-as-first-simple-selector-style-update-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-as-first-simple-selector-style-update-expected.txt        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,189 @@
</span><ins>+Test style update of :nth-last-child() when the tree structure is modified. In this case, :nth-last-child() is not the last component of the compound selector, which is a bit less common.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Initialy, only the first element should match.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;testnode&gt; on top, we should now match 0 and 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;nottestnode&gt; on top, we should now match -1, 0 and 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;nottestnode&gt; on top, we should now match -2, -1, 0 and 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[14]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[15]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;testnode&gt; on top, we should now match -3, -2, -1, 0 and 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[12]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[13]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[14]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[15]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[16]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[17]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;nottestnode&gt; on top, we should now match -4, -3, -2, -1, 0 and 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[12]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[13]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[14]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[15]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[16]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[17]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[18]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[19]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;nottestnode&gt;, -2 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[12]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[13]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[14]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[15]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[16]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[17]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;testnode&gt;, -4 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[14]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[15]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;notestnode&gt;, -1 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;testnode&gt;, -3 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;testnode&gt;, 0 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;testnode&gt;, there are only 4 siblings left, nothing can match.
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[0]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[1]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildasfirstsimpleselectorstyleupdatehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-as-first-simple-selector-style-update.html (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-as-first-simple-selector-style-update.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-as-first-simple-selector-style-update.html        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,110 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+testnode {
+    background-color: white;
+}
+:nth-last-child(n+5).target {
+    background-color: rgb(1, 2, 3);
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div id=&quot;with-renderer&quot;&gt;
+        &lt;testnode class=&quot;element_1 target&quot;&gt;&lt;/testnode&gt;
+        &lt;testnode class=&quot;element_2 target&quot;&gt;&lt;/testnode&gt;
+        &lt;testnode class=&quot;element_3 target&quot;&gt;&lt;/testnode&gt;
+        &lt;testnode class=&quot;element_4 target&quot;&gt;&lt;/testnode&gt;
+        &lt;testnode class=&quot;element_5 target&quot;&gt;&lt;/testnode&gt;
+    &lt;/div&gt;
+    &lt;div id=&quot;without-renderer&quot; style=&quot;display:none;&quot;&gt;
+        &lt;testnode class=&quot;element_1 target&quot;&gt;&lt;/testnode&gt;
+        &lt;testnode class=&quot;element_2 target&quot;&gt;&lt;/testnode&gt;
+        &lt;testnode class=&quot;element_3 target&quot;&gt;&lt;/testnode&gt;
+        &lt;testnode class=&quot;element_4 target&quot;&gt;&lt;/testnode&gt;
+        &lt;testnode class=&quot;element_5 target&quot;&gt;&lt;/testnode&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;script&gt;
+description('Test style update of :nth-last-child() when the tree structure is modified. In this case, :nth-last-child() is not the last component of the compound selector, which is a bit less common.');
+
+function testColor(classesThatShouldMatch) {
+    var alltestnodes = document.querySelectorAll(&quot;testnode&quot;);
+    for (var i = 0; i &lt; alltestnodes.length; ++i) {
+        var expectMath = classesThatShouldMatch.indexOf(alltestnodes[i].classList[0]) != -1;
+        shouldBeEqualToString('getComputedStyle(document.querySelectorAll(&quot;testnode&quot;)[' + i + ']).backgroundColor', expectMath ? 'rgb(1, 2, 3)' : 'rgb(255, 255, 255)');
+    }
+}
+
+function addElementAsFirstChild(tagName, className)
+{
+    var newElement = document.createElement(tagName);
+    newElement.className = className;
+
+    var withRenderer = document.getElementById(&quot;with-renderer&quot;);
+    withRenderer.insertBefore(newElement, withRenderer.firstChild);
+
+    var withoutRenderer = document.getElementById(&quot;without-renderer&quot;);
+    withoutRenderer.insertBefore(newElement.cloneNode(), withoutRenderer.firstChild);
+}
+
+function removeElementsOfClass(className)
+{
+    var allElementsToRemove = document.querySelectorAll('.' + className);
+    for (var i = 0; i &lt; allElementsToRemove.length; ++i)
+        allElementsToRemove[i].parentElement.removeChild(allElementsToRemove[i]);
+}
+
+debug(&quot;Initialy, only the first element should match.&quot;);
+testColor([&quot;element_1&quot;]);
+
+debug(&quot;Adding an element &amp;lt;testnode&amp;gt; on top, we should now match 0 and 1.&quot;);
+addElementAsFirstChild(&quot;testnode&quot;, &quot;element_0 target&quot;)
+testColor([&quot;element_0&quot;, &quot;element_1&quot;]);
+
+// Using nottestnode is interesting because the ':nth-last-child()' part is not matched for those elements.
+debug(&quot;Adding an element &amp;lt;nottestnode&amp;gt; on top, we should now match -1, 0 and 1.&quot;);
+addElementAsFirstChild(&quot;testnode&quot;, &quot;element_-1 target&quot;)
+testColor([&quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Adding an element &amp;lt;nottestnode&amp;gt; on top, we should now match -2, -1, 0 and 1.&quot;);
+addElementAsFirstChild(&quot;testnode&quot;, &quot;element_-2 target&quot;)
+testColor([&quot;element_-2&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Adding an element &amp;lt;testnode&amp;gt; on top, we should now match -3, -2, -1, 0 and 1.&quot;);
+addElementAsFirstChild(&quot;testnode&quot;, &quot;element_-3 target&quot;)
+testColor([&quot;element_-3&quot;, &quot;element_-2&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Adding an element &amp;lt;nottestnode&amp;gt; on top, we should now match -4, -3, -2, -1, 0 and 1.&quot;);
+addElementAsFirstChild(&quot;testnode&quot;, &quot;element_-4 target&quot;)
+testColor([&quot;element_-4&quot;, &quot;element_-3&quot;, &quot;element_-2&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;nottestnode&amp;gt;, -2 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_-2&quot;);
+testColor([&quot;element_-4&quot;, &quot;element_-3&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;testnode&amp;gt;, -4 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_-4&quot;);
+testColor([&quot;element_-3&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;notestnode&amp;gt;, -1 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_-1&quot;);
+testColor([&quot;element_-3&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;testnode&amp;gt;, -3 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_-3&quot;);
+testColor([&quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;testnode&amp;gt;, 0 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_0&quot;);
+testColor([&quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;testnode&amp;gt;, there are only 4 siblings left, nothing can match.&quot;);
+removeElementsOfClass(&quot;element_1&quot;);
+testColor([]);
+
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildbasicsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-basics-expected.txt (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-basics-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-basics-expected.txt        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,664 @@
</span><ins>+Test basic uses cases of :nth-last-child().
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Testing &quot;:nth-last-child(8)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(8)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(8)')[0].id is &quot;testcase4&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+6)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+6)').length is 6
+PASS document.querySelectorAll('#test-root :nth-last-child(n+6)')[0].id is &quot;testcase1&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+6)')[1].id is &quot;testcase2&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+6)')[2].id is &quot;testcase3&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+6)')[3].id is &quot;testcase4&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+6)')[4].id is &quot;testcase5&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+6)')[5].id is &quot;testcase6&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+9)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)').length is 9
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[0].id is &quot;testcase3&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[1].id is &quot;testcase4&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[2].id is &quot;testcase5&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[3].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[4].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[5].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[6].id is &quot;testcase9&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[7].id is &quot;testcase10&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+9)')[8].id is &quot;testcase11&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+
+Testing &quot;:nth-last-child(n+4):nth-last-child(-n+8)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+4):nth-last-child(-n+8)').length is 5
+PASS document.querySelectorAll('#test-root :nth-last-child(n+4):nth-last-child(-n+8)')[0].id is &quot;testcase4&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+4):nth-last-child(-n+8)')[1].id is &quot;testcase5&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+4):nth-last-child(-n+8)')[2].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+4):nth-last-child(-n+8)')[3].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+4):nth-last-child(-n+8)')[4].id is &quot;testcase8&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+8):nth-last-child(n+4)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+8):nth-last-child(n+4)').length is 5
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+8):nth-last-child(n+4)')[0].id is &quot;testcase4&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+8):nth-last-child(n+4)')[1].id is &quot;testcase5&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+8):nth-last-child(n+4)')[2].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+8):nth-last-child(n+4)')[3].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+8):nth-last-child(n+4)')[4].id is &quot;testcase8&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+2):nth-last-child(odd):nth-last-child(-n+9)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+2):nth-last-child(odd):nth-last-child(-n+9)').length is 4
+PASS document.querySelectorAll('#test-root :nth-last-child(n+2):nth-last-child(odd):nth-last-child(-n+9)')[0].id is &quot;testcase3&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+2):nth-last-child(odd):nth-last-child(-n+9)')[1].id is &quot;testcase5&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+2):nth-last-child(odd):nth-last-child(-n+9)')[2].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+2):nth-last-child(odd):nth-last-child(-n+9)')[3].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(3n+1):nth-last-child(even)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(3n+1):nth-last-child(even)').length is 2
+PASS document.querySelectorAll('#test-root :nth-last-child(3n+1):nth-last-child(even)')[0].id is &quot;testcase2&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(3n+1):nth-last-child(even)')[1].id is &quot;testcase8&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(even):nth-last-child(3n+1)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(even):nth-last-child(3n+1)').length is 2
+PASS document.querySelectorAll('#test-root :nth-last-child(even):nth-last-child(3n+1)')[0].id is &quot;testcase2&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(even):nth-last-child(3n+1)')[1].id is &quot;testcase8&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(3)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(3)')[0].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(4)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(4)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(4)')[0].id is &quot;testcase8&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(3):nth-last-child(4)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(3):nth-last-child(4)').length is 0
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(4):nth-last-child(3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(4):nth-last-child(3)').length is 0
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)').length is 9
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[0].id is &quot;testcase1&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[1].id is &quot;testcase2&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[2].id is &quot;testcase3&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[3].id is &quot;testcase4&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[4].id is &quot;testcase5&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[5].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[6].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[7].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3)')[8].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(2n+2)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2)').length is 5
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2)')[0].id is &quot;testcase2&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2)')[1].id is &quot;testcase4&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2)')[2].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2)')[3].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2)')[4].id is &quot;testcase10&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+3):nth-last-child(2n+2)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(2n+2)').length is 4
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(2n+2)')[0].id is &quot;testcase2&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(2n+2)')[1].id is &quot;testcase4&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(2n+2)')[2].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(2n+2)')[3].id is &quot;testcase8&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(2n+2):nth-last-child(n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2):nth-last-child(n+3)').length is 4
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2):nth-last-child(n+3)')[0].id is &quot;testcase2&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2):nth-last-child(n+3)')[1].id is &quot;testcase4&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2):nth-last-child(n+3)')[2].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(2n+2):nth-last-child(n+3)')[3].id is &quot;testcase8&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+4)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4)').length is 4
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4)')[0].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4)')[1].id is &quot;testcase9&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4)')[2].id is &quot;testcase10&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4)')[3].id is &quot;testcase11&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+
+Testing &quot;:nth-last-child(-n+5)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5)').length is 5
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5)')[0].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5)')[1].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5)')[2].id is &quot;testcase9&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5)')[3].id is &quot;testcase10&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5)')[4].id is &quot;testcase11&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+
+Testing &quot;:nth-last-child(-n+4):nth-last-child(-n+5)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4):nth-last-child(-n+5)').length is 4
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4):nth-last-child(-n+5)')[0].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4):nth-last-child(-n+5)')[1].id is &quot;testcase9&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4):nth-last-child(-n+5)')[2].id is &quot;testcase10&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+4):nth-last-child(-n+5)')[3].id is &quot;testcase11&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+
+Testing &quot;:nth-last-child(-n+5):nth-last-child(-n+4)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5):nth-last-child(-n+4)').length is 4
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5):nth-last-child(-n+4)')[0].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5):nth-last-child(-n+4)')[1].id is &quot;testcase9&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5):nth-last-child(-n+4)')[2].id is &quot;testcase10&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+5):nth-last-child(-n+4)')[3].id is &quot;testcase11&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+
+Testing &quot;:nth-last-child(n+3):nth-last-child(-n+6)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6)').length is 4
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6)')[0].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6)')[1].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6)')[2].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6)')[3].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+6):nth-last-child(n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3)').length is 4
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3)')[0].id is &quot;testcase6&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3)')[1].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3)')[2].id is &quot;testcase8&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3)')[3].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+1):nth-last-child(-n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+1):nth-last-child(-n+3)').length is 3
+PASS document.querySelectorAll('#test-root :nth-last-child(n+1):nth-last-child(-n+3)')[0].id is &quot;testcase9&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+1):nth-last-child(-n+3)')[1].id is &quot;testcase10&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+1):nth-last-child(-n+3)')[2].id is &quot;testcase11&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+
+Testing &quot;:nth-last-child(-n+3):nth-last-child(n+1)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+3):nth-last-child(n+1)').length is 3
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+3):nth-last-child(n+1)')[0].id is &quot;testcase9&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+3):nth-last-child(n+1)')[1].id is &quot;testcase10&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+3):nth-last-child(n+1)')[2].id is &quot;testcase11&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+
+Testing &quot;:nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(n+1):nth-last-child(-n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(n+1):nth-last-child(-n+3)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(n+1):nth-last-child(-n+3)')[0].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(-n+3):nth-last-child(n+1)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(-n+3):nth-last-child(n+1)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(-n+3):nth-last-child(n+1)')[0].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+3):nth-last-child(odd):nth-last-child(-n+6)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(odd):nth-last-child(-n+6)').length is 2
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(odd):nth-last-child(-n+6)')[0].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(odd):nth-last-child(-n+6)')[1].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+6):nth-last-child(odd):nth-last-child(n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(odd):nth-last-child(n+3)').length is 2
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(odd):nth-last-child(n+3)')[0].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(odd):nth-last-child(n+3)')[1].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(odd):nth-last-child(n+3):nth-last-child(-n+6)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(odd):nth-last-child(n+3):nth-last-child(-n+6)').length is 2
+PASS document.querySelectorAll('#test-root :nth-last-child(odd):nth-last-child(n+3):nth-last-child(-n+6)')[0].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(odd):nth-last-child(n+3):nth-last-child(-n+6)')[1].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(odd):nth-last-child(-n+6):nth-last-child(n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(odd):nth-last-child(-n+6):nth-last-child(n+3)').length is 2
+PASS document.querySelectorAll('#test-root :nth-last-child(odd):nth-last-child(-n+6):nth-last-child(n+3)')[0].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(odd):nth-last-child(-n+6):nth-last-child(n+3)')[1].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(odd)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(odd)').length is 2
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(odd)')[0].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(odd)')[1].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(odd)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(odd)').length is 2
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(odd)')[0].id is &quot;testcase7&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(odd)')[1].id is &quot;testcase9&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+1):nth-last-child(even):nth-last-child(-n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+1):nth-last-child(even):nth-last-child(-n+3)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(n+1):nth-last-child(even):nth-last-child(-n+3)')[0].id is &quot;testcase10&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+3):nth-last-child(even):nth-last-child(n+1)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+3):nth-last-child(even):nth-last-child(n+1)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+3):nth-last-child(even):nth-last-child(n+1)')[0].id is &quot;testcase10&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(even):nth-last-child(n+1):nth-last-child(-n+3)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(even):nth-last-child(n+1):nth-last-child(-n+3)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(even):nth-last-child(n+1):nth-last-child(-n+3)')[0].id is &quot;testcase10&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(even):nth-last-child(-n+3):nth-last-child(n+1)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(even):nth-last-child(-n+3):nth-last-child(n+1)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(even):nth-last-child(-n+3):nth-last-child(n+1)')[0].id is &quot;testcase10&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(-n+3):nth-last-child(n+1):nth-last-child(even)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+3):nth-last-child(n+1):nth-last-child(even)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(-n+3):nth-last-child(n+1):nth-last-child(even)')[0].id is &quot;testcase10&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+1):nth-last-child(-n+3):nth-last-child(even)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+1):nth-last-child(-n+3):nth-last-child(even)').length is 1
+PASS document.querySelectorAll('#test-root :nth-last-child(n+1):nth-last-child(-n+3):nth-last-child(even)')[0].id is &quot;testcase10&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+Testing &quot;:nth-last-child(n+3):nth-last-child(odd):nth-last-child(-n+6):nth-last-child(n+1):nth-last-child(-n+3):nth-last-child(even)&quot;
+PASS document.querySelectorAll('#test-root :nth-last-child(n+3):nth-last-child(odd):nth-last-child(-n+6):nth-last-child(n+1):nth-last-child(-n+3):nth-last-child(even)').length is 0
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildbasicshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-basics.html (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-basics.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-basics.html        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,107 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+#test-root * {
+    background-color: red;
+}
+&lt;/style&gt;
+&lt;style id=&quot;style&quot;&gt;
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div style=&quot;display:none&quot; id=&quot;test-root&quot;&gt;
+        &lt;testcase id=&quot;testcase1&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase2&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase3&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase4&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase5&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase6&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase7&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase8&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase9&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase10&quot;&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase11&quot;&gt;&lt;/testcase&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;script&gt;
+description('Test basic uses cases of :nth-last-child().');
+
+function testQuerySelector(selector, expectedIds) {
+    shouldBe(&quot;document.querySelectorAll('&quot; + selector + &quot;').length&quot;, '' + expectedIds.length);
+    for (var i = 0; i &lt; expectedIds.length; ++i)
+        shouldBeEqualToString(&quot;document.querySelectorAll('&quot; + selector + &quot;')[&quot; + i + &quot;].id&quot;, expectedIds[i]);
+}
+
+function testStyling(selector, expectedIds) {
+    var stylingElement = document.getElementById(&quot;style&quot;);
+    stylingElement.innerHTML = '' + selector + ' { background-color: rgb(10, 100, 200); }';
+
+    var allTestCases = document.querySelectorAll(&quot;#test-root *&quot;);
+    for (var i = 0; i &lt; allTestCases.length; ++i) {
+        var expectMatch = expectedIds.indexOf(allTestCases[i].id) &gt;= 0;
+        shouldBeEqualToString('getComputedStyle(document.querySelectorAll(&quot;#test-root *&quot;)[' + i + ']).backgroundColor', expectMatch ? 'rgb(10, 100, 200)' : 'rgb(255, 0, 0)');
+    }
+
+    stylingElement.innerHTML = '';
+}
+
+function testSelector(selector, expectedIds) {
+    debug(&quot;Testing \&quot;&quot; + selector + &quot;\&quot;&quot;);
+    testQuerySelector(&quot;#test-root &quot; + selector, expectedIds);
+    testStyling(&quot;#test-root &quot; + selector, expectedIds);
+    debug(&quot;&quot;);
+}
+
+// Test cases presented on http://nthmaster.com/ to have a simple baseline.
+testSelector(&quot;:nth-last-child(8)&quot;, [&quot;testcase4&quot;]);
+testSelector(&quot;:nth-last-child(n+6)&quot;, [&quot;testcase1&quot;, &quot;testcase2&quot;, &quot;testcase3&quot;, &quot;testcase4&quot;, &quot;testcase5&quot;, &quot;testcase6&quot;]);
+testSelector(&quot;:nth-last-child(-n+9)&quot;, [&quot;testcase3&quot;, &quot;testcase4&quot;, &quot;testcase5&quot;, &quot;testcase6&quot;, &quot;testcase7&quot;, &quot;testcase8&quot;, &quot;testcase9&quot;, &quot;testcase10&quot;, &quot;testcase11&quot;]);
+testSelector(&quot;:nth-last-child(n+4):nth-last-child(-n+8)&quot;, [&quot;testcase4&quot;, &quot;testcase5&quot;, &quot;testcase6&quot;, &quot;testcase7&quot;, &quot;testcase8&quot;]);
+testSelector(&quot;:nth-last-child(-n+8):nth-last-child(n+4)&quot;, [&quot;testcase4&quot;, &quot;testcase5&quot;, &quot;testcase6&quot;, &quot;testcase7&quot;, &quot;testcase8&quot;]);
+testSelector(&quot;:nth-last-child(n+2):nth-last-child(odd):nth-last-child(-n+9)&quot;, [&quot;testcase3&quot;, &quot;testcase5&quot;, &quot;testcase7&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(3n+1):nth-last-child(even)&quot;, [&quot;testcase2&quot;, &quot;testcase8&quot;]);
+testSelector(&quot;:nth-last-child(even):nth-last-child(3n+1)&quot;, [&quot;testcase2&quot;, &quot;testcase8&quot;]);
+
+// The following was using :nth-last-child() on http://nthmaster.com/. It is adapted here for completness.
+testSelector(&quot;:nth-last-child(3)&quot;, [&quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(4)&quot;, [&quot;testcase8&quot;]);
+testSelector(&quot;:nth-last-child(3):nth-last-child(4)&quot;, []);
+testSelector(&quot;:nth-last-child(4):nth-last-child(3)&quot;, []);
+
+testSelector(&quot;:nth-last-child(n+3)&quot;, [&quot;testcase1&quot;, &quot;testcase2&quot;, &quot;testcase3&quot;, &quot;testcase4&quot;, &quot;testcase5&quot;, &quot;testcase6&quot;, &quot;testcase7&quot;, &quot;testcase8&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(2n+2)&quot;, [&quot;testcase2&quot;, &quot;testcase4&quot;, &quot;testcase6&quot;, &quot;testcase8&quot;, &quot;testcase10&quot;]);
+testSelector(&quot;:nth-last-child(n+3):nth-last-child(2n+2)&quot;, [&quot;testcase2&quot;, &quot;testcase4&quot;, &quot;testcase6&quot;, &quot;testcase8&quot;]);
+testSelector(&quot;:nth-last-child(2n+2):nth-last-child(n+3)&quot;, [&quot;testcase2&quot;, &quot;testcase4&quot;, &quot;testcase6&quot;, &quot;testcase8&quot;]);
+
+testSelector(&quot;:nth-last-child(-n+4)&quot;, [&quot;testcase8&quot;, &quot;testcase9&quot;, &quot;testcase10&quot;, &quot;testcase11&quot;]);
+testSelector(&quot;:nth-last-child(-n+5)&quot;, [&quot;testcase7&quot;, &quot;testcase8&quot;, &quot;testcase9&quot;, &quot;testcase10&quot;, &quot;testcase11&quot;]);
+testSelector(&quot;:nth-last-child(-n+4):nth-last-child(-n+5)&quot;, [&quot;testcase8&quot;, &quot;testcase9&quot;, &quot;testcase10&quot;, &quot;testcase11&quot;]);
+testSelector(&quot;:nth-last-child(-n+5):nth-last-child(-n+4)&quot;, [&quot;testcase8&quot;, &quot;testcase9&quot;, &quot;testcase10&quot;, &quot;testcase11&quot;]);
+
+testSelector(&quot;:nth-last-child(n+3):nth-last-child(-n+6)&quot;, [&quot;testcase6&quot;, &quot;testcase7&quot;, &quot;testcase8&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(-n+6):nth-last-child(n+3)&quot;, [&quot;testcase6&quot;, &quot;testcase7&quot;, &quot;testcase8&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(n+1):nth-last-child(-n+3)&quot;, [&quot;testcase9&quot;, &quot;testcase10&quot;, &quot;testcase11&quot;]);
+testSelector(&quot;:nth-last-child(-n+3):nth-last-child(n+1)&quot;, [&quot;testcase9&quot;, &quot;testcase10&quot;, &quot;testcase11&quot;]);
+testSelector(&quot;:nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(n+1):nth-last-child(-n+3)&quot;, [&quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(-n+3):nth-last-child(n+1)&quot;, [&quot;testcase9&quot;]);
+
+testSelector(&quot;:nth-last-child(n+3):nth-last-child(odd):nth-last-child(-n+6)&quot;, [&quot;testcase7&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(-n+6):nth-last-child(odd):nth-last-child(n+3)&quot;, [&quot;testcase7&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(odd):nth-last-child(n+3):nth-last-child(-n+6)&quot;, [&quot;testcase7&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(odd):nth-last-child(-n+6):nth-last-child(n+3)&quot;, [&quot;testcase7&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(n+3):nth-last-child(-n+6):nth-last-child(odd)&quot;, [&quot;testcase7&quot;, &quot;testcase9&quot;]);
+testSelector(&quot;:nth-last-child(-n+6):nth-last-child(n+3):nth-last-child(odd)&quot;, [&quot;testcase7&quot;, &quot;testcase9&quot;]);
+
+testSelector(&quot;:nth-last-child(n+1):nth-last-child(even):nth-last-child(-n+3)&quot;, [&quot;testcase10&quot;]);
+testSelector(&quot;:nth-last-child(-n+3):nth-last-child(even):nth-last-child(n+1)&quot;, [&quot;testcase10&quot;]);
+testSelector(&quot;:nth-last-child(even):nth-last-child(n+1):nth-last-child(-n+3)&quot;, [&quot;testcase10&quot;]);
+testSelector(&quot;:nth-last-child(even):nth-last-child(-n+3):nth-last-child(n+1)&quot;, [&quot;testcase10&quot;]);
+testSelector(&quot;:nth-last-child(-n+3):nth-last-child(n+1):nth-last-child(even)&quot;, [&quot;testcase10&quot;]);
+testSelector(&quot;:nth-last-child(n+1):nth-last-child(-n+3):nth-last-child(even)&quot;, [&quot;testcase10&quot;]);
+
+testSelector(&quot;:nth-last-child(n+3):nth-last-child(odd):nth-last-child(-n+6):nth-last-child(n+1):nth-last-child(-n+3):nth-last-child(even)&quot;, []);
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildboundsexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-bounds-expected.txt (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-bounds-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-bounds-expected.txt        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+Test the boundary values of the :nth-last-child() selector.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS document.querySelectorAll(&quot;li:nth-last-child(0n+0)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-0n+0)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(0n-0)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-0n-0)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-0n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(0)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-0)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-1)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(2147483647n+2147483647)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(2147483647n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(2147483647)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-2147483648n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-2147483648)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(2147483647n-2147483648)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-2147483648n+2147483647)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(2147483648n+2147483648)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(2147483648n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(2147483648)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(3147483647n+3147483647)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(3147483647n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(3147483647)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-2147483649n-2147483649)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-2147483649n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;li:nth-last-child(-2147483649)&quot;).length is 0
+PASS allItems.length is 20
+PASS coloredCount is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildboundshtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-bounds.html (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-bounds.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-bounds.html        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,161 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+/* The element count starts at 1, no count &lt;= 1 can match anything */
+li:nth-last-child(0n+0) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-0n+0) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(0n-0) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-0n-0) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(0n) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-0n) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(0) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-0) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-1) {
+    background-color:rgb(1, 2, 3);
+}
+
+/* IntMax (2147483647) and IntMin (-2147483647). The tree is not big enough to match any of those. */
+li:nth-last-child(2147483647n+2147483647) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(2147483647n) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(2147483647) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-2147483648n-2147483648) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-2147483648n) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-2147483648) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(2147483647n-2147483648) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-2147483648n+2147483647) {
+    background-color:rgb(1, 2, 3);
+}
+
+/* Values too large/small for int32 */
+li:nth-last-child(2147483648n+2147483648) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(2147483648n) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(2147483648) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(3147483647n+3147483647) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(3147483647n) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(3147483647) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-2147483649n-2147483649) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-2147483649n) {
+    background-color:rgb(1, 2, 3);
+}
+li:nth-last-child(-2147483649) {
+    background-color:rgb(1, 2, 3);
+}
+
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div style=&quot;display:none&quot;&gt;
+    &lt;ul id=targetTree&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+        &lt;li&gt;&lt;/li&gt;
+    &lt;/ul&gt;
+&lt;/div&gt;
+&lt;/body&gt;
+&lt;script&gt;
+description('Test the boundary values of the :nth-last-child() selector.');
+
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(0n+0)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-0n+0)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(0n-0)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-0n-0)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-0n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(0)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-0)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-1)&quot;).length', '0');
+
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(2147483647n+2147483647)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(2147483647n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(2147483647)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-2147483648n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-2147483648)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(2147483647n-2147483648)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-2147483648n+2147483647)&quot;).length', '0');
+
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(2147483648n+2147483648)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(2147483648n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(2147483648)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(3147483647n+3147483647)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(3147483647n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(3147483647)&quot;).length', '0');
+
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-2147483649n-2147483649)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-2147483649n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;li:nth-last-child(-2147483649)&quot;).length', '0');
+
+var allItems = document.querySelectorAll('li');
+var coloredCount = 0;
+for (var i = 0; i &lt; allItems.length; ++i) {
+    if (getComputedStyle(allItems[i]).backgroundColor === 'rgb(1, 2, 3)')
+        coloredCount++;
+}
+
+shouldBe('allItems.length', '20');
+shouldBe('coloredCount', '0');
+
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildchainedexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-chained-expected.txt (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-chained-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-chained-expected.txt        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,184 @@
</span><ins>+Test chaining many :nth-last-child() selectors. This verifies register allocation is correct.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Testing &quot;:nth-last-child(-n+21):nth-last-child(odd):nth-last-child(-2n+21):nth-last-child(3n+1):nth-last-child(-3n+22):nth-last-child(4n+1):nth-last-child(-5n+51)&quot;
+PASS document.querySelectorAll('testcase:nth-last-child(-n+21):nth-last-child(odd):nth-last-child(-2n+21):nth-last-child(3n+1):nth-last-child(-3n+22):nth-last-child(4n+1):nth-last-child(-5n+51)').length is 1
+PASS document.querySelectorAll('testcase:nth-last-child(-n+21):nth-last-child(odd):nth-last-child(-2n+21):nth-last-child(3n+1):nth-last-child(-3n+22):nth-last-child(4n+1):nth-last-child(-5n+51)')[0].id is &quot;testcase20&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[11]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[12]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[13]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[14]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[15]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[16]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[17]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[18]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[19]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS document.querySelectorAll('div&gt;testcase:nth-last-child(-n+21):nth-last-child(odd):nth-last-child(-2n+21):nth-last-child(3n+1):nth-last-child(-3n+22):nth-last-child(4n+1):nth-last-child(-5n+51)&gt;div&gt;div&gt;div span').length is 1
+
+Testing &quot;:nth-last-child(2n-200):nth-last-child(3n-1):nth-last-child(4n-38):nth-last-child(5n-98)&quot;
+PASS document.querySelectorAll('testcase:nth-last-child(2n-200):nth-last-child(3n-1):nth-last-child(4n-38):nth-last-child(5n-98)').length is 1
+PASS document.querySelectorAll('testcase:nth-last-child(2n-200):nth-last-child(3n-1):nth-last-child(4n-38):nth-last-child(5n-98)')[0].id is &quot;testcase19&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[11]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[12]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[13]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[14]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[15]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[16]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[17]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[18]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[19]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS document.querySelectorAll('div&gt;testcase:nth-last-child(2n-200):nth-last-child(3n-1):nth-last-child(4n-38):nth-last-child(5n-98)&gt;div&gt;div&gt;div span').length is 1
+
+Testing &quot;:nth-last-child(even):nth-last-child(3n):nth-last-child(4n-2):nth-last-child(5n+1)&quot;
+PASS document.querySelectorAll('testcase:nth-last-child(even):nth-last-child(3n):nth-last-child(4n-2):nth-last-child(5n+1)').length is 1
+PASS document.querySelectorAll('testcase:nth-last-child(even):nth-last-child(3n):nth-last-child(4n-2):nth-last-child(5n+1)')[0].id is &quot;testcase15&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[11]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[12]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[13]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[14]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[15]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[16]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[17]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[18]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[19]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS document.querySelectorAll('div&gt;testcase:nth-last-child(even):nth-last-child(3n):nth-last-child(4n-2):nth-last-child(5n+1)&gt;div&gt;div&gt;div span').length is 1
+
+Testing &quot;:nth-last-child(-n+9000):nth-last-child(-2n+683):nth-last-child(-3n+31):nth-last-child(-4n+47):nth-last-child(-5n+107):nth-last-child(-6n+73):nth-last-child(-7n+70)&quot;
+PASS document.querySelectorAll('testcase:nth-last-child(-n+9000):nth-last-child(-2n+683):nth-last-child(-3n+31):nth-last-child(-4n+47):nth-last-child(-5n+107):nth-last-child(-6n+73):nth-last-child(-7n+70)').length is 1
+PASS document.querySelectorAll('testcase:nth-last-child(-n+9000):nth-last-child(-2n+683):nth-last-child(-3n+31):nth-last-child(-4n+47):nth-last-child(-5n+107):nth-last-child(-6n+73):nth-last-child(-7n+70)')[0].id is &quot;testcase14&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[11]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[12]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[13]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[14]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[15]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[16]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[17]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[18]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[19]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS document.querySelectorAll('div&gt;testcase:nth-last-child(-n+9000):nth-last-child(-2n+683):nth-last-child(-3n+31):nth-last-child(-4n+47):nth-last-child(-5n+107):nth-last-child(-6n+73):nth-last-child(-7n+70)&gt;div&gt;div&gt;div span').length is 1
+
+Testing &quot;:nth-last-child(odd):nth-last-child(3n+1):nth-last-child(4n-1):nth-last-child(5n+4)&quot;
+PASS document.querySelectorAll('testcase:nth-last-child(odd):nth-last-child(3n+1):nth-last-child(4n-1):nth-last-child(5n+4)').length is 1
+PASS document.querySelectorAll('testcase:nth-last-child(odd):nth-last-child(3n+1):nth-last-child(4n-1):nth-last-child(5n+4)')[0].id is &quot;testcase2&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[1]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[11]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[12]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[13]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[14]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[15]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[16]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[17]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[18]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[19]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS document.querySelectorAll('div&gt;testcase:nth-last-child(odd):nth-last-child(3n+1):nth-last-child(4n-1):nth-last-child(5n+4)&gt;div&gt;div&gt;div span').length is 1
+
+Testing &quot;:nth-last-child(-n+1500):nth-last-child(2n+1):nth-last-child(-3n+45):nth-last-child(4n+3):nth-last-child(-5n+1545)&quot;
+PASS document.querySelectorAll('testcase:nth-last-child(-n+1500):nth-last-child(2n+1):nth-last-child(-3n+45):nth-last-child(4n+3):nth-last-child(-5n+1545)').length is 1
+PASS document.querySelectorAll('testcase:nth-last-child(-n+1500):nth-last-child(2n+1):nth-last-child(-3n+45):nth-last-child(4n+3):nth-last-child(-5n+1545)')[0].id is &quot;testcase6&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[5]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[10]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[11]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[12]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[13]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[14]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[15]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[16]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[17]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[18]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[19]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS document.querySelectorAll('div&gt;testcase:nth-last-child(-n+1500):nth-last-child(2n+1):nth-last-child(-3n+45):nth-last-child(4n+3):nth-last-child(-5n+1545)&gt;div&gt;div&gt;div span').length is 1
+
+Testing &quot;:nth-last-child(n+2):nth-last-child(-n+6000):nth-last-child(n-2):nth-last-child(2n):nth-last-child(-2n+20):nth-last-child(2n+2):nth-last-child(3n+1):nth-last-child(-3n+49):nth-last-child(3n-92):nth-last-child(4n+2):nth-last-child(-4n+50)&quot;
+PASS document.querySelectorAll('testcase:nth-last-child(n+2):nth-last-child(-n+6000):nth-last-child(n-2):nth-last-child(2n):nth-last-child(-2n+20):nth-last-child(2n+2):nth-last-child(3n+1):nth-last-child(-3n+49):nth-last-child(3n-92):nth-last-child(4n+2):nth-last-child(-4n+50)').length is 1
+PASS document.querySelectorAll('testcase:nth-last-child(n+2):nth-last-child(-n+6000):nth-last-child(n-2):nth-last-child(2n):nth-last-child(-2n+20):nth-last-child(2n+2):nth-last-child(3n+1):nth-last-child(-3n+49):nth-last-child(3n-92):nth-last-child(4n+2):nth-last-child(-4n+50)')[0].id is &quot;testcase11&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[0]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[1]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[2]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[3]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[4]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[5]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[6]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[7]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[8]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[9]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[10]).backgroundColor is &quot;rgb(10, 100, 200)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[11]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[12]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[13]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[14]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[15]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[16]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[17]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[18]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[19]).backgroundColor is &quot;rgb(255, 0, 0)&quot;
+PASS document.querySelectorAll('div&gt;testcase:nth-last-child(n+2):nth-last-child(-n+6000):nth-last-child(n-2):nth-last-child(2n):nth-last-child(-2n+20):nth-last-child(2n+2):nth-last-child(3n+1):nth-last-child(-3n+49):nth-last-child(3n-92):nth-last-child(4n+2):nth-last-child(-4n+50)&gt;div&gt;div&gt;div span').length is 1
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildchainedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-chained.html (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-chained.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-chained.html        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,94 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+testcase {
+    background-color: red;
+}
+&lt;/style&gt;
+&lt;style id=&quot;style&quot;&gt;
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div style=&quot;display:none&quot;&gt;
+        &lt;testcase id=&quot;testcase1&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase2&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase3&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase4&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase5&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase6&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase7&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase8&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase9&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase10&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase11&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase12&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase13&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase14&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase15&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase16&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase17&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase18&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase19&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+        &lt;testcase id=&quot;testcase20&quot;&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/testcase&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;script&gt;
+description('Test chaining many :nth-last-child() selectors. This verifies register allocation is correct.');
+
+function testQuerySelector(selector, expectedIds) {
+    shouldBe(&quot;document.querySelectorAll('&quot; + selector + &quot;').length&quot;, '' + expectedIds.length);
+    for (var i = 0; i &lt; expectedIds.length; ++i)
+        shouldBeEqualToString(&quot;document.querySelectorAll('&quot; + selector + &quot;')[&quot; + i + &quot;].id&quot;, expectedIds[i]);
+}
+
+function testStyling(selector, expectedIds) {
+    var stylingElement = document.getElementById(&quot;style&quot;);
+    stylingElement.innerHTML = '' + selector + ' { background-color: rgb(10, 100, 200); }';
+
+    var allTestCases = document.querySelectorAll(&quot;testcase&quot;);
+    for (var i = 0; i &lt; allTestCases.length; ++i) {
+        var expectMatch = expectedIds.indexOf(allTestCases[i].id) &gt;= 0;
+        shouldBeEqualToString('getComputedStyle(document.querySelectorAll(&quot;testcase&quot;)[' + i + ']).backgroundColor', expectMatch ? 'rgb(10, 100, 200)' : 'rgb(255, 0, 0)');
+    }
+
+    stylingElement.innerHTML = '';
+}
+
+function testSelector(selector, expectedIds) {
+    debug(&quot;Testing \&quot;&quot; + selector + &quot;\&quot;&quot;);
+    testQuerySelector(&quot;testcase&quot; + selector, expectedIds);
+    testStyling(&quot;testcase&quot; + selector, expectedIds);
+
+    // Test the same request with a backtracking register.
+    shouldBe(&quot;document.querySelectorAll('div&gt;testcase&quot; + selector + &quot;&gt;div&gt;div&gt;div span').length&quot;, '' + expectedIds.length);
+
+    debug(&quot;&quot;);
+}
+
+// The :nth-last-child() should not completely overlap to ensure all of them are executed.
+
+// All positive B.
+testSelector(&quot;:nth-last-child(-n+21):nth-last-child(odd):nth-last-child(-2n+21):nth-last-child(3n+1):nth-last-child(-3n+22):nth-last-child(4n+1):nth-last-child(-5n+51)&quot;, [&quot;testcase20&quot;]);
+
+// All negative B.
+testSelector(&quot;:nth-last-child(2n-200):nth-last-child(3n-1):nth-last-child(4n-38):nth-last-child(5n-98)&quot;, [&quot;testcase19&quot;]);
+
+// All positive A.
+testSelector(&quot;:nth-last-child(even):nth-last-child(3n):nth-last-child(4n-2):nth-last-child(5n+1)&quot;, [&quot;testcase15&quot;]);
+
+// All negative A.
+testSelector(&quot;:nth-last-child(-n+9000):nth-last-child(-2n+683):nth-last-child(-3n+31):nth-last-child(-4n+47):nth-last-child(-5n+107):nth-last-child(-6n+73):nth-last-child(-7n+70)&quot;, [&quot;testcase14&quot;]);
+
+// Positive and Negative B.
+testSelector(&quot;:nth-last-child(odd):nth-last-child(3n+1):nth-last-child(4n-1):nth-last-child(5n+4)&quot;, [&quot;testcase2&quot;]);
+
+// Positive and Negative A.
+testSelector(&quot;:nth-last-child(-n+1500):nth-last-child(2n+1):nth-last-child(-3n+45):nth-last-child(4n+3):nth-last-child(-5n+1545)&quot;, [&quot;testcase6&quot;]);
+
+// Everything.
+testSelector(&quot;:nth-last-child(n+2):nth-last-child(-n+6000):nth-last-child(n-2):nth-last-child(2n):nth-last-child(-2n+20):nth-last-child(2n+2):nth-last-child(3n+1):nth-last-child(-3n+49):nth-last-child(3n-92):nth-last-child(4n+2):nth-last-child(-4n+50)&quot;, [&quot;testcase11&quot;]);
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildonrootexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-on-root-expected.txt (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-on-root-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-on-root-expected.txt        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+Verify the nth-last-child() pseudo class matcher always test for the parent element. Some :nth-last-child pseudo selectors can skip counting the siblings, but they should never skip the parent check.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS document.querySelectorAll(&quot;html:nth-last-child(1)&quot;).length is 0
+PASS document.querySelectorAll(&quot;html:nth-last-child(n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;html:nth-last-child(n+1)&quot;).length is 0
+PASS document.querySelectorAll(&quot;:root:nth-last-child(1)&quot;).length is 0
+PASS document.querySelectorAll(&quot;:root:nth-last-child(n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;:root:nth-last-child(n+1)&quot;).length is 0
+PASS getComputedStyle(document.documentElement).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS document.querySelectorAll(&quot;svg:root&quot;).length is 0
+PASS document.querySelectorAll(&quot;svg:nth-last-child(1)&quot;).length is 1
+PASS document.querySelectorAll(&quot;svg:nth-last-child(n)&quot;).length is 1
+PASS getComputedStyle(document.querySelector(&quot;svg&quot;)).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildonroothtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-on-root.html (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-on-root.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-on-root.html        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,60 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+html {
+    background-color:white;
+}
+html:nth-last-child(1) {
+    background-color:rgb(1, 2, 3);
+}
+html:nth-last-child(n) {
+    background-color:rgb(1, 2, 3);
+}
+html:nth-last-child(n+1) {
+    background-color:rgb(1, 2, 3);
+}
+
+:root:nth-last-child(1) {
+    background-color:rgb(1, 2, 3);
+}
+:root:nth-last-child(n) {
+    background-color:rgb(1, 2, 3);
+}
+:root:nth-last-child(n+1) {
+    background-color:rgb(1, 2, 3);
+}
+
+svg:nth-last-child(n) {
+    background-color:rgb(1, 2, 3);
+}
+svg:root {
+    background-color:rgb(4, 5, 6);
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div style=&quot;display:none&quot;&gt;
+        &lt;svg&gt;&lt;g&gt;&lt;/g&gt;&lt;/svg&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;script&gt;
+description('Verify the nth-last-child() pseudo class matcher always test for the parent element. Some :nth-last-child pseudo selectors can skip counting the siblings, but they should never skip the parent check.');
+
+shouldBe('document.querySelectorAll(&quot;html:nth-last-child(1)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;html:nth-last-child(n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;html:nth-last-child(n+1)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;:root:nth-last-child(1)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;:root:nth-last-child(n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;:root:nth-last-child(n+1)&quot;).length', '0');
+shouldBeEqualToString('getComputedStyle(document.documentElement).backgroundColor', 'rgb(255, 255, 255)');
+
+// This svg document is not the root, &quot;:root&quot; should not match anything, nth-last-child should work.
+shouldBe('document.querySelectorAll(&quot;svg:root&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;svg:nth-last-child(1)&quot;).length', '1');
+shouldBe('document.querySelectorAll(&quot;svg:nth-last-child(n)&quot;).length', '1');
+shouldBeEqualToString('getComputedStyle(document.querySelector(&quot;svg&quot;)).backgroundColor', 'rgb(1, 2, 3)');
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildstyleupdateexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-style-update-expected.txt (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-style-update-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-style-update-expected.txt        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,167 @@
</span><ins>+Test style update of :nth-last-child() when the tree structure is modified.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Initialy, only the first can match.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;target&gt; on top, we should now match 0 and 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;nottarget&gt; on top, we should now match -1, 0, 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;nottarget&gt; on top, we should now match -2, -1, 0, 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;target&gt; on top, we should now match -3, -2, -1, 0, 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Adding an element &lt;nottarget&gt; on top, we should now match -4, -3, -2, -1, 0, 1.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;nottarget&gt;, -2 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;target&gt;, -4 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;notarget&gt;, -1 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[12]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[13]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;target&gt;, -3 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[10]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[11]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;target&gt;, 0 should no longer match.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[8]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[9]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+Removing one of the &lt;target&gt;, there are only 4 siblings left, nothing can match.
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[0]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[1]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[2]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[3]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[4]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[5]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[6]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS getComputedStyle(document.querySelectorAll(&quot;target&quot;)[7]).backgroundColor is &quot;rgb(255, 255, 255)&quot;
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildstyleupdatehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-style-update.html (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-style-update.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-style-update.html        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,110 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+target {
+    background-color: white;
+}
+target:nth-last-child(n+5) {
+    background-color: rgb(1, 2, 3);
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div id=&quot;with-renderer&quot;&gt;
+        &lt;target class=&quot;element_1&quot;&gt;&lt;/target&gt;
+        &lt;target class=&quot;element_2&quot;&gt;&lt;/target&gt;
+        &lt;target class=&quot;element_3&quot;&gt;&lt;/target&gt;
+        &lt;target class=&quot;element_4&quot;&gt;&lt;/target&gt;
+        &lt;target class=&quot;element_5&quot;&gt;&lt;/target&gt;
+    &lt;/div&gt;
+    &lt;div id=&quot;without-renderer&quot; style=&quot;display:none;&quot;&gt;
+        &lt;target class=&quot;element_1&quot;&gt;&lt;/target&gt;
+        &lt;target class=&quot;element_2&quot;&gt;&lt;/target&gt;
+        &lt;target class=&quot;element_3&quot;&gt;&lt;/target&gt;
+        &lt;target class=&quot;element_4&quot;&gt;&lt;/target&gt;
+        &lt;target class=&quot;element_5&quot;&gt;&lt;/target&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;script&gt;
+description('Test style update of :nth-last-child() when the tree structure is modified.');
+
+function testColor(classesThatShouldMatch) {
+    var allTargets = document.querySelectorAll(&quot;target&quot;);
+    for (var i = 0; i &lt; allTargets.length; ++i) {
+        var expectMath = classesThatShouldMatch.indexOf(allTargets[i].className) != -1;
+        shouldBeEqualToString('getComputedStyle(document.querySelectorAll(&quot;target&quot;)[' + i + ']).backgroundColor', expectMath ? 'rgb(1, 2, 3)' : 'rgb(255, 255, 255)');
+    }
+}
+
+function addElementAsFirstChild(tagName, className)
+{
+    var newElement = document.createElement(tagName);
+    newElement.className = className;
+
+    var withRenderer = document.getElementById(&quot;with-renderer&quot;);
+    withRenderer.insertBefore(newElement, withRenderer.firstChild);
+
+    var withoutRenderer = document.getElementById(&quot;without-renderer&quot;);
+    withoutRenderer.insertBefore(newElement.cloneNode(), withoutRenderer.firstChild);
+}
+
+function removeElementsOfClass(className)
+{
+    var allElementsToRemove = document.querySelectorAll('.' + className);
+    for (var i = 0; i &lt; allElementsToRemove.length; ++i)
+        allElementsToRemove[i].parentElement.removeChild(allElementsToRemove[i]);
+}
+
+debug(&quot;Initialy, only the first can match.&quot;);
+testColor([&quot;element_1&quot;]);
+
+debug(&quot;Adding an element &amp;lt;target&amp;gt; on top, we should now match 0 and 1.&quot;);
+addElementAsFirstChild(&quot;target&quot;, &quot;element_0&quot;)
+testColor([&quot;element_0&quot;, &quot;element_1&quot;]);
+
+// Using nottarget is interesting because the ':nth-last-child()' part is not matched for those elements.
+debug(&quot;Adding an element &amp;lt;nottarget&amp;gt; on top, we should now match -1, 0, 1.&quot;);
+addElementAsFirstChild(&quot;nottarget&quot;, &quot;element_-1&quot;)
+testColor([&quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Adding an element &amp;lt;nottarget&amp;gt; on top, we should now match -2, -1, 0, 1.&quot;);
+addElementAsFirstChild(&quot;nottarget&quot;, &quot;element_-2&quot;)
+testColor([&quot;element_-2&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Adding an element &amp;lt;target&amp;gt; on top, we should now match -3, -2, -1, 0, 1.&quot;);
+addElementAsFirstChild(&quot;target&quot;, &quot;element_-3&quot;)
+testColor([&quot;element_-3&quot;, &quot;element_-2&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Adding an element &amp;lt;nottarget&amp;gt; on top, we should now match -4, -3, -2, -1, 0, 1.&quot;);
+addElementAsFirstChild(&quot;nottarget&quot;, &quot;element_-4&quot;)
+testColor([&quot;element_-4&quot;, &quot;element_-3&quot;, &quot;element_-2&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;nottarget&amp;gt;, -2 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_-2&quot;);
+testColor([&quot;element_-4&quot;, &quot;element_-3&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;target&amp;gt;, -4 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_-4&quot;);
+testColor([&quot;element_-3&quot;, &quot;element_-1&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;notarget&amp;gt;, -1 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_-1&quot;);
+testColor([&quot;element_-3&quot;, &quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;target&amp;gt;, -3 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_-3&quot;);
+testColor([&quot;element_0&quot;, &quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;target&amp;gt;, 0 should no longer match.&quot;);
+removeElementsOfClass(&quot;element_0&quot;);
+testColor([&quot;element_1&quot;]);
+
+debug(&quot;Removing one of the &amp;lt;target&amp;gt;, there are only 4 siblings left, nothing can match.&quot;);
+removeElementsOfClass(&quot;element_1&quot;);
+testColor([]);
+
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildwithbacktrackingexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-with-backtracking-expected.txt (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-with-backtracking-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-with-backtracking-expected.txt        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+Test nth-last-child inside deep backtracking.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS document.querySelectorAll(&quot;li+li+:nth-last-child(-5n+14)+li+li+li~li+li+li~li&quot;).length is 7
+PASS allItems.length is 20
+PASS coloredItems is 7
+PASS document.querySelectorAll(&quot;ul&gt;[foo=bar]:nth-last-child(-3n+18)+li+li+li~li+li+li~li&gt;span.first&gt;span.second a&quot;).length is 11
+PASS allLinks.length is 20
+PASS backgroundColoredCount is 11
+PASS document.querySelectorAll(&quot;ul&gt;:nth-last-child(-3n+3)&gt;*&gt;* a&quot;).length is 1
+PASS nonOpaqueCount is 1
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsnthlastchildwithbacktrackinghtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/nth-last-child-with-backtracking.html (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/nth-last-child-with-backtracking.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/nth-last-child-with-backtracking.html        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,77 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+li+li+:nth-last-child(-5n+14)+li+li+li~li+li+li~li {
+    color:rgb(4, 5, 6);
+}
+ul&gt;[foo=bar]:nth-last-child(-3n+18)+li+li+li~li+li+li~li&gt;span.first&gt;span.second a {
+    background-color:rgb(1,2,3);
+}
+ul&gt;:nth-last-child(-3n+3)&gt;*&gt;* a {
+    opacity: 0.5;
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;div&gt;
+    &lt;ul style=&quot;display:none&quot;&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;li foo=bar&gt;&lt;span class=&quot;first&quot;&gt;&lt;span class=&quot;second&quot;&gt;&lt;span&gt;&lt;a href=&quot;http://www.webkit.org&quot;&gt;WebKit!&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+    &lt;/ul&gt;
+&lt;/div&gt;
+&lt;/body&gt;
+&lt;script&gt;
+
+description('Test nth-last-child inside deep backtracking.');
+
+// nth-last-child inside two adjacent backtracking chains.
+shouldBe('document.querySelectorAll(&quot;li+li+:nth-last-child(-5n+14)+li+li+li~li+li+li~li&quot;).length', '7');
+var allItems = document.querySelectorAll('li');
+shouldBe('allItems.length', '20');
+var coloredItems = 0;
+for (var i = 0; i &lt; allItems.length; ++i) {
+    if (getComputedStyle(allItems[i]).color === 'rgb(4, 5, 6)')
+        coloredItems++;
+}
+shouldBe('coloredItems', '7');
+
+// nth-last-child inside two adjacent backtracking chains, inside one descendant backtracking chain.
+shouldBe('document.querySelectorAll(&quot;ul&gt;[foo=bar]:nth-last-child(-3n+18)+li+li+li~li+li+li~li&gt;span.first&gt;span.second a&quot;).length', '11');
+var allLinks = document.querySelectorAll('a');
+shouldBe('allLinks.length', '20');
+var backgroundColoredCount = 0;
+var nonOpaqueCount = 0;
+for (var i = 0; i &lt; allLinks.length; ++i) {
+    var computedStyle = getComputedStyle(allLinks[i]);
+    if (computedStyle.backgroundColor === 'rgb(1, 2, 3)')
+        backgroundColoredCount++;
+    if (computedStyle.opacity === '0.5')
+        ++nonOpaqueCount;
+}
+shouldBe('backgroundColoredCount', '11');
+
+shouldBe('document.querySelectorAll(&quot;ul&gt;:nth-last-child(-3n+3)&gt;*&gt;* a&quot;).length', '1');
+shouldBe('nonOpaqueCount', '1');
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsseveralnthlastchildexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/several-nth-last-child-expected.txt (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/several-nth-last-child-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/several-nth-last-child-expected.txt        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,17 @@
</span><ins>+Verify the nth-last-child() pseudo class does not leak registers.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS document.querySelectorAll(&quot;body:nth-last-child(n) div:nth-last-child(n) ul:nth-last-child(n) li:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n)&quot;).length is 1
+PASS getComputedStyle(document.getElementById(&quot;target&quot;)).backgroundColor is &quot;rgb(1, 2, 3)&quot;
+PASS document.querySelectorAll(&quot;body:nth-last-child(n+1) div:nth-last-child(n+1) ul:nth-last-child(n+1) li:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1)&quot;).length is 1
+PASS getComputedStyle(document.getElementById(&quot;target&quot;)).color is &quot;rgb(4, 5, 6)&quot;
+PASS document.querySelectorAll(&quot;body:nth-last-child(1) div:nth-last-child(1) ul:nth-last-child(1) li:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1)&quot;).length is 0
+PASS document.querySelectorAll(&quot;body:nth-last-child(2) div:nth-last-child(2) ul:nth-last-child(2) li:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2)&quot;).length is 0
+PASS document.querySelectorAll(&quot;body:nth-last-child(2n) div:nth-last-child(2n) ul:nth-last-child(2n) li:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n)&quot;).length is 0
+PASS document.querySelectorAll(&quot;body:nth-last-child(2n+1) div:nth-last-child(2n+1) ul:nth-last-child(2n+1) li:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1)&quot;).length is 0
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsfastselectorsseveralnthlastchildhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/selectors/several-nth-last-child.html (0 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/selectors/several-nth-last-child.html                                (rev 0)
+++ trunk/LayoutTests/fast/selectors/several-nth-last-child.html        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -0,0 +1,35 @@
</span><ins>+&lt;!doctype html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;style&gt;
+body:nth-last-child(n) div:nth-last-child(n) ul:nth-last-child(n) li:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) {
+    background-color:rgb(1, 2, 3);
+}
+body:nth-last-child(n+1) div:nth-last-child(n+1) ul:nth-last-child(n+1) li:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) {
+    color:rgb(4, 5, 6);
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+    &lt;div style=&quot;display:none&quot;&gt;
+        &lt;ul&gt;
+            &lt;li&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span id=target&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
+        &lt;/ul&gt;
+    &lt;/div&gt;
+&lt;/body&gt;
+&lt;script&gt;
+description('Verify the nth-last-child() pseudo class does not leak registers.');
+
+shouldBe('document.querySelectorAll(&quot;body:nth-last-child(n) div:nth-last-child(n) ul:nth-last-child(n) li:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n) span:nth-last-child(n)&quot;).length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById(&quot;target&quot;)).backgroundColor', 'rgb(1, 2, 3)');
+shouldBe('document.querySelectorAll(&quot;body:nth-last-child(n+1) div:nth-last-child(n+1) ul:nth-last-child(n+1) li:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1) span:nth-last-child(n+1)&quot;).length', '1');
+shouldBeEqualToString('getComputedStyle(document.getElementById(&quot;target&quot;)).color', 'rgb(4, 5, 6)');
+
+shouldBe('document.querySelectorAll(&quot;body:nth-last-child(1) div:nth-last-child(1) ul:nth-last-child(1) li:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1) span:nth-last-child(1)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;body:nth-last-child(2) div:nth-last-child(2) ul:nth-last-child(2) li:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2) span:nth-last-child(2)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;body:nth-last-child(2n) div:nth-last-child(2n) ul:nth-last-child(2n) li:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n) span:nth-last-child(2n)&quot;).length', '0');
+shouldBe('document.querySelectorAll(&quot;body:nth-last-child(2n+1) div:nth-last-child(2n+1) ul:nth-last-child(2n+1) li:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1) span:nth-last-child(2n+1)&quot;).length', '0');
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (179534 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-02-03 03:08:33 UTC (rev 179534)
+++ trunk/Source/WebCore/ChangeLog        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -1,3 +1,39 @@
</span><ins>+2015-02-02  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
+
+        JIT Compile simple cases of :nth-last-child()
+        https://bugs.webkit.org/show_bug.cgi?id=141053
+
+        Reviewed by Andreas Kling.
+
+        This patch adds the code generator for :nth-last-child(), skipping
+        any :nth-last-child(An+B of selector list).
+
+        The code generator is boring here, nothing fancy.
+        There is no optimization opportunity here so it is basically the same
+        speed as the code generated by Clang when the simple selector is alone.
+
+        The only reason to JIT compile this is to avoid going to slow-path
+        for every selector that contain :nth-last-child().
+
+        * cssjit/SelectorCompiler.cpp:
+        (WebCore::SelectorCompiler::addNthChildType):
+        The code creating the intermediate representation of :nth-child() is exactly
+        the same as what we need for :nth-last-child(). I extracted the code from addPseudoClassType()
+        and share it for both simple selectors.
+
+        (WebCore::SelectorCompiler::addPseudoClassType):
+        I fail :nth-last-child(An+B of selector list). Let's add it later.
+
+        (WebCore::SelectorCompiler::minimumRegisterRequirements):
+        Oops, there was a bug with nthChildOfFilters.
+
+        (WebCore::SelectorCompiler::hasAnyCombinators):
+        (WebCore::SelectorCompiler::computeBacktrackingMemoryRequirements):
+        (WebCore::SelectorCompiler::computeBacktrackingInformation):
+        (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementMatching):
+        (WebCore::SelectorCompiler::setChildrenAffectedByBackwardPositionalRules):
+        (WebCore::SelectorCompiler::SelectorCodeGenerator::generateElementIsNthLastChild):
+
</ins><span class="cx"> 2015-02-02  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Simple line layout: Rename FlowContentsIterator to TextFragmentIterator.
</span></span></pre></div>
<a id="trunkSourceWebCorecssjitSelectorCompilercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/cssjit/SelectorCompiler.cpp (179534 => 179535)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/cssjit/SelectorCompiler.cpp        2015-02-03 03:08:33 UTC (rev 179534)
+++ trunk/Source/WebCore/cssjit/SelectorCompiler.cpp        2015-02-03 04:11:42 UTC (rev 179535)
</span><span class="lines">@@ -177,6 +177,8 @@
</span><span class="cx">     Vector&lt;AttributeMatchingInfo, 4&gt; attributes;
</span><span class="cx">     Vector&lt;std::pair&lt;int, int&gt;, 2&gt; nthChildFilters;
</span><span class="cx">     Vector&lt;NthChildOfSelectorInfo&gt; nthChildOfFilters;
</span><ins>+    Vector&lt;std::pair&lt;int, int&gt;, 2&gt; nthLastChildFilters;
+    Vector&lt;NthChildOfSelectorInfo&gt; nthLastChildOfFilters;
</ins><span class="cx">     SelectorList notFilters;
</span><span class="cx">     Vector&lt;SelectorList&gt; matchesFilters;
</span><span class="cx">     Vector&lt;Vector&lt;SelectorFragment&gt;&gt; anyFilters;
</span><span class="lines">@@ -284,6 +286,7 @@
</span><span class="cx">     void generateElementIsLink(Assembler::JumpList&amp; failureCases);
</span><span class="cx">     void generateElementIsNthChild(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp;);
</span><span class="cx">     void generateElementIsNthChildOf(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp;);
</span><ins>+    void generateElementIsNthLastChild(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp;);
</ins><span class="cx">     void generateElementMatchesNotPseudoClass(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp;);
</span><span class="cx">     void generateElementMatchesAnyPseudoClass(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp;);
</span><span class="cx">     void generateElementMatchesMatchesPseudoClass(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp;);
</span><span class="lines">@@ -440,6 +443,82 @@
</span><span class="cx">     return FunctionType::CannotMatchAnything;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// Handle the forward :nth-child() and backward :nth-last-child().
+static FunctionType addNthChildType(const CSSSelector&amp; selector, SelectorContext selectorContext, FragmentPositionInRootFragments positionInRootFragments, bool visitedMatchEnabled, Vector&lt;std::pair&lt;int, int&gt;, 2&gt;&amp; simpleCases, Vector&lt;NthChildOfSelectorInfo&gt;&amp; filteredCases, unsigned&amp; internalSpecificity)
+{
+    if (!selector.parseNth())
+        return FunctionType::CannotMatchAnything;
+
+    int a = selector.nthA();
+    int b = selector.nthB();
+
+    // The element count is always positive.
+    if (a &lt;= 0 &amp;&amp; b &lt; 1)
+        return FunctionType::CannotMatchAnything;
+
+    if (const CSSSelectorList* selectorList = selector.selectorList()) {
+        NthChildOfSelectorInfo nthChildOfSelectorInfo;
+        nthChildOfSelectorInfo.a = a;
+        nthChildOfSelectorInfo.b = b;
+
+        FunctionType globalFunctionType = FunctionType::SimpleSelectorChecker;
+        if (selectorContext != SelectorContext::QuerySelector)
+            globalFunctionType = FunctionType::SelectorCheckerWithCheckingContext;
+
+        unsigned firstFragmentListSpecificity = 0;
+        bool firstFragmentListSpecificitySet = false;
+
+        SelectorFragmentList* selectorFragments = nullptr;
+        for (const CSSSelector* subselector = selectorList-&gt;first(); subselector; subselector = CSSSelectorList::next(subselector)) {
+            if (!selectorFragments) {
+                nthChildOfSelectorInfo.selectorList.append(SelectorFragmentList());
+                selectorFragments = &amp;nthChildOfSelectorInfo.selectorList.last();
+            }
+
+            VisitedMode ignoreVisitedMode = VisitedMode::None;
+            FunctionType functionType = constructFragments(subselector, selectorContext, *selectorFragments, FragmentsLevel::InFunctionalPseudoType, positionInRootFragments, visitedMatchEnabled, ignoreVisitedMode, PseudoElementMatchingBehavior::NeverMatch);
+            ASSERT_WITH_MESSAGE(ignoreVisitedMode == VisitedMode::None, &quot;:visited is disabled in the functional pseudo classes&quot;);
+            switch (functionType) {
+            case FunctionType::SimpleSelectorChecker:
+            case FunctionType::SelectorCheckerWithCheckingContext:
+                break;
+            case FunctionType::CannotMatchAnything:
+                continue;
+            case FunctionType::CannotCompile:
+                return FunctionType::CannotCompile;
+            }
+
+            if (firstFragmentListSpecificitySet) {
+                // The CSS JIT does not handle dynamic specificity yet.
+                if (selectorContext == SelectorContext::RuleCollector &amp;&amp; selectorFragments-&gt;staticSpecificity != firstFragmentListSpecificity)
+                    return FunctionType::CannotCompile;
+            } else {
+                firstFragmentListSpecificitySet = true;
+                firstFragmentListSpecificity = selectorFragments-&gt;staticSpecificity;
+            }
+
+            globalFunctionType = mostRestrictiveFunctionType(globalFunctionType, functionType);
+            selectorFragments = nullptr;
+        }
+
+        // If there is still a SelectorFragmentList open, the last Fragment(s) cannot match anything,
+        // we have one FragmentList too many in our selector list.
+        if (selectorFragments)
+            nthChildOfSelectorInfo.selectorList.removeLast();
+
+        if (nthChildOfSelectorInfo.selectorList.isEmpty())
+            return FunctionType::CannotMatchAnything;
+
+        internalSpecificity = firstFragmentListSpecificity;
+        filteredCases.append(nthChildOfSelectorInfo);
+        return globalFunctionType;
+    }
+    simpleCases.append(std::pair&lt;int, int&gt;(a, b));
+    if (selectorContext == SelectorContext::QuerySelector)
+        return FunctionType::SimpleSelectorChecker;
+    return FunctionType::SelectorCheckerWithCheckingContext;
+}
+
</ins><span class="cx"> static inline FunctionType addPseudoClassType(const CSSSelector&amp; selector, SelectorFragment&amp; fragment, unsigned&amp; internalSpecificity, SelectorContext selectorContext, FragmentsLevel fragmentLevel, FragmentPositionInRootFragments positionInRootFragments, bool visitedMatchEnabled, VisitedMode&amp; visitedMode, PseudoElementMatchingBehavior pseudoElementMatchingBehavior)
</span><span class="cx"> {
</span><span class="cx">     CSSSelector::PseudoClassType type = selector.pseudoClassType();
</span><span class="lines">@@ -538,7 +617,6 @@
</span><span class="cx">     case CSSSelector::PseudoClassLastOfType:
</span><span class="cx">     case CSSSelector::PseudoClassOnlyOfType:
</span><span class="cx">     case CSSSelector::PseudoClassNthOfType:
</span><del>-    case CSSSelector::PseudoClassNthLastChild:
</del><span class="cx">     case CSSSelector::PseudoClassNthLastOfType:
</span><span class="cx">     case CSSSelector::PseudoClassDrag:
</span><span class="cx"> #if ENABLE(CSS_SELECTORS_LEVEL4)
</span><span class="lines">@@ -593,80 +671,15 @@
</span><span class="cx">         return FunctionType::SelectorCheckerWithCheckingContext;
</span><span class="cx"> 
</span><span class="cx">     case CSSSelector::PseudoClassNthChild:
</span><del>-        {
-            if (!selector.parseNth())
-                return FunctionType::CannotMatchAnything;
</del><ins>+        return addNthChildType(selector, selectorContext, positionInRootFragments, visitedMatchEnabled, fragment.nthChildFilters, fragment.nthChildOfFilters, internalSpecificity);
</ins><span class="cx"> 
</span><del>-            int a = selector.nthA();
-            int b = selector.nthB();
</del><ins>+    case CSSSelector::PseudoClassNthLastChild: {
+        FunctionType functionType = addNthChildType(selector, selectorContext, positionInRootFragments, visitedMatchEnabled, fragment.nthLastChildFilters, fragment.nthLastChildOfFilters, internalSpecificity);
+        if (!fragment.nthLastChildOfFilters.isEmpty())
+            return FunctionType::CannotCompile;
+        return functionType;
+    }
</ins><span class="cx"> 
</span><del>-            // The element count is always positive.
-            if (a &lt;= 0 &amp;&amp; b &lt; 1)
-                return FunctionType::CannotMatchAnything;
-
-            if (const CSSSelectorList* selectorList = selector.selectorList()) {
-                NthChildOfSelectorInfo nthChildOfSelectorInfo;
-                nthChildOfSelectorInfo.a = a;
-                nthChildOfSelectorInfo.b = b;
-
-                FunctionType globalFunctionType = FunctionType::SimpleSelectorChecker;
-                if (selectorContext != SelectorContext::QuerySelector)
-                    globalFunctionType = FunctionType::SelectorCheckerWithCheckingContext;
-
-                unsigned firstFragmentListSpecificity = 0;
-                bool firstFragmentListSpecificitySet = false;
-
-                SelectorFragmentList* selectorFragments = nullptr;
-                for (const CSSSelector* subselector = selectorList-&gt;first(); subselector; subselector = CSSSelectorList::next(subselector)) {
-                    if (!selectorFragments) {
-                        nthChildOfSelectorInfo.selectorList.append(SelectorFragmentList());
-                        selectorFragments = &amp;nthChildOfSelectorInfo.selectorList.last();
-                    }
-
-                    VisitedMode ignoreVisitedMode = VisitedMode::None;
-                    FunctionType functionType = constructFragments(subselector, selectorContext, *selectorFragments, FragmentsLevel::InFunctionalPseudoType, positionInRootFragments, visitedMatchEnabled, ignoreVisitedMode, PseudoElementMatchingBehavior::NeverMatch);
-                    ASSERT_WITH_MESSAGE(ignoreVisitedMode == VisitedMode::None, &quot;:visited is disabled in the functional pseudo classes&quot;);
-                    switch (functionType) {
-                    case FunctionType::SimpleSelectorChecker:
-                    case FunctionType::SelectorCheckerWithCheckingContext:
-                        break;
-                    case FunctionType::CannotMatchAnything:
-                        continue;
-                    case FunctionType::CannotCompile:
-                        return FunctionType::CannotCompile;
-                    }
-
-                    if (firstFragmentListSpecificitySet) {
-                        // The CSS JIT does not handle dynamic specificity yet.
-                        if (selectorContext == SelectorContext::RuleCollector &amp;&amp; selectorFragments-&gt;staticSpecificity != firstFragmentListSpecificity)
-                            return FunctionType::CannotCompile;
-                    } else {
-                        firstFragmentListSpecificitySet = true;
-                        firstFragmentListSpecificity = selectorFragments-&gt;staticSpecificity;
-                    }
-
-                    globalFunctionType = mostRestrictiveFunctionType(globalFunctionType, functionType);
-                    selectorFragments = nullptr;
-                }
-
-                // If there is still a SelectorFragmentList open, the last Fragment(s) cannot match anything,
-                // we have one FragmentList too many in our selector list.
-                if (selectorFragments)
-                    nthChildOfSelectorInfo.selectorList.removeLast();
-
-                if (nthChildOfSelectorInfo.selectorList.isEmpty())
-                    return FunctionType::CannotMatchAnything;
-
-                internalSpecificity = firstFragmentListSpecificity;
-                fragment.nthChildOfFilters.append(nthChildOfSelectorInfo);
-                return globalFunctionType;
-            }
-            fragment.nthChildFilters.append(std::pair&lt;int, int&gt;(a, b));
-            if (selectorContext == SelectorContext::QuerySelector)
-                return FunctionType::SimpleSelectorChecker;
-            return FunctionType::SelectorCheckerWithCheckingContext;
-        }
-
</del><span class="cx">     case CSSSelector::PseudoClassNot:
</span><span class="cx">         {
</span><span class="cx">             const CSSSelectorList* selectorList = selector.selectorList();
</span><span class="lines">@@ -1081,7 +1094,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if CPU(X86_64)
</span><del>-    if (!selectorFragment.nthChildFilters.isEmpty() || selectorFragment.nthChildOfFilters.isEmpty())
</del><ins>+    if (!selectorFragment.nthChildFilters.isEmpty() || !selectorFragment.nthChildOfFilters.isEmpty() || !selectorFragment.nthLastChildFilters.isEmpty() || !selectorFragment.nthLastChildOfFilters.isEmpty())
</ins><span class="cx">         minimum = std::max(minimum, minimumRequiredRegisterCountForNthChildFilter);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -1126,6 +1139,10 @@
</span><span class="cx">         if (hasAnyCombinators(nthChildOfSelectorInfo.selectorList))
</span><span class="cx">             return true;
</span><span class="cx">     }
</span><ins>+    for (const NthChildOfSelectorInfo&amp; nthLastChildOfSelectorInfo : selectorFragmentList.first().nthLastChildOfFilters) {
+        if (hasAnyCombinators(nthLastChildOfSelectorInfo.selectorList))
+            return true;
+    }
</ins><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1176,6 +1193,9 @@
</span><span class="cx">         for (NthChildOfSelectorInfo&amp; nthChildOfSelectorInfo : selectorFragment.nthChildOfFilters)
</span><span class="cx">             computeBacktrackingMemoryRequirements(nthChildOfSelectorInfo.selectorList, fragmentRegisterRequirements, fragmentStackRequirements, backtrackingRegisterReservedForFragment);
</span><span class="cx"> 
</span><ins>+        for (NthChildOfSelectorInfo&amp; nthLastChildOfSelectorInfo : selectorFragment.nthLastChildOfFilters)
+            computeBacktrackingMemoryRequirements(nthLastChildOfSelectorInfo.selectorList, fragmentRegisterRequirements, fragmentStackRequirements, backtrackingRegisterReservedForFragment);
+
</ins><span class="cx">         if (selectorFragment.backtrackingFlags &amp; BacktrackingFlag::InChainWithDescendantTail) {
</span><span class="cx">             if (!backtrackingRegisterReserved)
</span><span class="cx">                 ++fragmentRegisterRequirements;
</span><span class="lines">@@ -1621,6 +1641,15 @@
</span><span class="cx">             for (SelectorFragmentList&amp; selectorList : nthChildOfSelectorInfo.selectorList)
</span><span class="cx">                 computeBacktrackingInformation(selectorList, level + 1);
</span><span class="cx">         }
</span><ins>+
+        for (NthChildOfSelectorInfo&amp; nthLastChildOfSelectorInfo : fragment.nthLastChildOfFilters) {
+#if CSS_SELECTOR_JIT_DEBUGGING
+            dataLogF(&quot;%*s  Subselectors for %dn+%d:\n&quot;, level * 4, &quot;&quot;, nthLastChildOfSelectorInfo.a, nthLastChildOfSelectorInfo.b);
+#endif
+
+            for (SelectorFragmentList&amp; selectorList : nthLastChildOfSelectorInfo.selectorList)
+                computeBacktrackingInformation(selectorList, level + 1);
+        }
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -2498,6 +2527,8 @@
</span><span class="cx">         generateElementIsLastChild(matchingPostTagNameFailureCases, fragment);
</span><span class="cx">     if (!fragment.nthChildFilters.isEmpty())
</span><span class="cx">         generateElementIsNthChild(matchingPostTagNameFailureCases, fragment);
</span><ins>+    if (!fragment.nthLastChildFilters.isEmpty())
+        generateElementIsNthLastChild(matchingPostTagNameFailureCases, fragment);
</ins><span class="cx">     if (!fragment.nthChildOfFilters.isEmpty())
</span><span class="cx">         generateElementIsNthChildOf(matchingPostTagNameFailureCases, fragment);
</span><span class="cx">     if (!fragment.notFilters.isEmpty())
</span><span class="lines">@@ -3621,6 +3652,65 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void setChildrenAffectedByBackwardPositionalRules(Element* element)
+{
+    element-&gt;setChildrenAffectedByBackwardPositionalRules();
+}
+
+void SelectorCodeGenerator::generateElementIsNthLastChild(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp; fragment)
+{
+    Vector&lt;std::pair&lt;int, int&gt;, 32&gt; validSubsetFilters;
+    validSubsetFilters.reserveInitialCapacity(fragment.nthLastChildFilters.size());
+    { // :nth-last-child() must have a parent to match. If there is a parent, do the invalidation marking.
+        LocalRegister parentElement(m_registerAllocator);
+        generateWalkToParentElement(failureCases, parentElement);
+
+        for (const auto&amp; slot : fragment.nthLastChildFilters) {
+            if (nthFilterIsAlwaysSatisified(slot.first, slot.second))
+                continue;
+            validSubsetFilters.uncheckedAppend(slot);
+        }
+        if (validSubsetFilters.isEmpty())
+            return;
+
+        if (m_selectorContext != SelectorContext::QuerySelector) {
+            Assembler::Jump skipMarking;
+            {
+                LocalRegister checkingContext(m_registerAllocator);
+                skipMarking = jumpIfNotResolvingStyle(checkingContext);
+            }
+
+            FunctionCall functionCall(m_assembler, m_registerAllocator, m_stackAllocator, m_functionCalls);
+            functionCall.setFunctionAddress(setChildrenAffectedByBackwardPositionalRules);
+            functionCall.setOneArgument(parentElement);
+            functionCall.call();
+
+            skipMarking.link(&amp;m_assembler);
+        }
+    }
+
+    LocalRegister elementCounter(m_registerAllocator);
+    { // Loop over the following sibling elements and increment the counter.
+        LocalRegister nextSibling(m_registerAllocator);
+        m_assembler.move(elementAddressRegister, nextSibling);
+        // Setup the counter at 1.
+        m_assembler.move(Assembler::TrustedImm32(1), elementCounter);
+
+        Assembler::JumpList noMoreSiblingsCases;
+
+        generateWalkToNextAdjacentElement(noMoreSiblingsCases, nextSibling);
+
+        Assembler::Label loopStart = m_assembler.label();
+        m_assembler.add32(Assembler::TrustedImm32(1), elementCounter);
+        generateWalkToNextAdjacentElement(noMoreSiblingsCases, nextSibling);
+        m_assembler.jump().linkTo(loopStart, &amp;m_assembler);
+        noMoreSiblingsCases.link(&amp;m_assembler);
+    }
+
+    for (const auto&amp; slot : validSubsetFilters)
+        generateNthFilterTest(failureCases, elementCounter, slot.first, slot.second);
+}
+
</ins><span class="cx"> void SelectorCodeGenerator::generateElementMatchesNotPseudoClass(Assembler::JumpList&amp; failureCases, const SelectorFragment&amp; fragment)
</span><span class="cx"> {
</span><span class="cx">     Assembler::JumpList localFailureCases;
</span></span></pre>
</div>
</div>

</body>
</html>