else
        {
            /*
-            * If the two values were of the same container type, then there'd
-            * have been a chance to observe the variation in the number of
-            * elements/pairs (when processing WJB_BEGIN_OBJECT, say). They're
-            * either two heterogeneously-typed containers, or a container and
-            * some scalar type.
-            *
-            * We don't have to consider the WJB_END_ARRAY and WJB_END_OBJECT
-            * cases here, because we would have seen the corresponding
-            * WJB_BEGIN_ARRAY and WJB_BEGIN_OBJECT tokens first, and
-            * concluded that they don't match.
+            * It's not possible for one iterator to report end of array or
+            * object while the other one reports something else, because we
+            * would have detected a length mismatch when we processed the
+            * container-start tokens above.  Likewise we can't see WJB_DONE
+            * from one but not the other.  So we have two different-type
+            * containers, or a container and some scalar type, or two
+            * different scalar types.  Sort on the basis of the type code.
             */
-           Assert(ra != WJB_END_ARRAY && ra != WJB_END_OBJECT);
-           Assert(rb != WJB_END_ARRAY && rb != WJB_END_OBJECT);
+           Assert(ra != WJB_DONE && ra != WJB_END_ARRAY && ra != WJB_END_OBJECT);
+           Assert(rb != WJB_DONE && rb != WJB_END_ARRAY && rb != WJB_END_OBJECT);
 
            Assert(va.type != vb.type);
            Assert(va.type != jbvBinary);