Bug 631615: suppress CSS parser diagnostics in ParseSelectorString. r=dbaron a2.0=dbaron
authorZack Weinberg <zackw@panix.com>
Fri, 04 Feb 2011 14:17:00 -0800
changeset 61985 9d810f5ea61c88ed1a9b38c971a70f01424bd6a3
parent 61984 7cb3e9795d040dc8ef9718a09735bd2f4fe322da
child 61986 68881eaeeebb69f1085793714589468c72d2f0f6
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs631615
milestone2.0b12pre
Bug 631615: suppress CSS parser diagnostics in ParseSelectorString. r=dbaron a2.0=dbaron
content/base/test/Makefile.in
content/base/test/test_bug631615.html
layout/style/nsCSSParser.cpp
--- a/content/base/test/Makefile.in
+++ b/content/base/test/Makefile.in
@@ -454,16 +454,17 @@ include $(topsrcdir)/config/rules.mk
 		test_bug614058.html \
 		test_bug590771.html \
 		test_bug622117.html \
 		test_bug622246.html \
 		test_bug484396.html \
 		test_bug466080.html \
 		bug466080.sjs \
 		test_bug625722.html \
+		test_bug631615.html \
 		$(NULL)
 
 # This test fails on the Mac for some reason
 ifneq (,$(filter gtk2 windows,$(MOZ_WIDGET_TOOLKIT)))
 _TEST_FILES2 += 	test_copyimage.html \
 		$(NULL)
 endif
 
new file mode 100644
--- /dev/null
+++ b/content/base/test/test_bug631615.html
@@ -0,0 +1,95 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=631615
+-->
+<head>
+  <title>Test for Bug 631615</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=631615">Mozilla Bug 631615</a>
+<pre id="monitor">
+</pre>
+<script type="application/javascript">
+
+netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cr = Components.results;
+
+var consoleService =
+  Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
+
+var messageCount = 0;
+var monitor = document.getElementById("monitor");
+
+var listener = {
+  observe: function(message) {
+    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+    if (message.message === "sentinel") {
+      is(messageCount, 0, "should have been no console messages");
+      removeListener();
+      SimpleTest.finish();
+    } else {
+      messageCount++;
+      var err = "" + messageCount + ": " + message.message + "\n";
+      monitor.appendChild(document.createTextNode(err));
+    }
+  },
+
+  QueryInterface: function(iid) {
+    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+    if (iid.equals(Ci.nsIConsoleListener) ||
+        iid.equals(Ci.nsISupports)) {
+      return this;
+    }
+    throw Cr.NS_NOINTERFACE;
+  }
+};
+
+function addListener() {
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+  consoleService.reset();
+  consoleService.registerListener(listener);
+}
+
+function removeListener() {
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+  consoleService.unregisterListener(listener);
+}
+
+function postSentinel() {
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+  consoleService.logStringMessage("sentinel");
+}
+
+SimpleTest.waitForExplicitFinish();
+
+function doTest() {
+  var html = document.documentElement;
+  var results;
+  var matches = html.matchesSelector || html.mozMatchesSelector;
+
+  addListener();
+  try {
+    results = "return: " +
+      matches.call(html, "[test!='']:sizzle") + "\n";
+  } catch (e) {
+    results = "throws: " + e + "\n";
+  }
+
+  monitor.appendChild(document.createTextNode(results));
+  is(results.slice(0, 6), "throws", "looking for an exception");
+
+  postSentinel();
+}
+doTest();
+
+</script>
+</body>
+</html>
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -1254,17 +1254,25 @@ CSSParserImpl::ParseSelectorString(const
 
   // This is the only place that cares about mFoundUnresolvablePrefix,
   // so this is the only place that bothers clearing it.
   mFoundUnresolvablePrefix = PR_FALSE;
 
   PRBool success = ParseSelectorList(*aSelectorList, PRUnichar(0));
   PRBool prefixErr = mFoundUnresolvablePrefix;
 
-  OUTPUT_ERROR();
+  // We deliberately do not call OUTPUT_ERROR here, because all our
+  // callers map a failure return to a JS exception, and if that JS
+  // exception is caught, people don't want to see parser diagnostics;
+  // see e.g. http://bugs.jquery.com/ticket/7535
+  // It would be nice to be able to save the parser diagnostics into
+  // the exception, so that if it _isn't_ caught we can report them
+  // along with the usual uncaught-exception message, but we don't
+  // have any way to do that at present; see bug 631621.
+  CLEAR_ERROR();
   ReleaseScanner();
 
   if (success) {
     NS_ASSERTION(*aSelectorList, "Should have list!");
     return NS_OK;
   }
 
   NS_ASSERTION(!*aSelectorList, "Shouldn't have list!");