Bug 1060933 - Prevent jQuery Live event bubbles from throwing on invalid selector r=bgrins
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Tue, 02 Sep 2014 16:26:32 +0100
changeset 203238 72d19d0827dec0c850d1b0180aeb8e6816e42f74
parent 203237 4d07ea9dab6e7673cd121317c6c9a0ea47fcde39
child 203239 c4c2474a4f75729a3571fe88629b6833446ce614
push id27424
push userryanvm@gmail.com
push dateWed, 03 Sep 2014 19:35:53 +0000
treeherdermozilla-central@bfef88becbba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1060933
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1060933 - Prevent jQuery Live event bubbles from throwing on invalid selector r=bgrins
browser/devtools/markupview/test/browser_markupview_events_jquery_1.0.js
browser/devtools/markupview/test/browser_markupview_events_jquery_1.1.js
browser/devtools/markupview/test/browser_markupview_events_jquery_1.11.1.js
browser/devtools/markupview/test/browser_markupview_events_jquery_1.2.js
browser/devtools/markupview/test/browser_markupview_events_jquery_1.3.js
browser/devtools/markupview/test/browser_markupview_events_jquery_1.4.js
browser/devtools/markupview/test/browser_markupview_events_jquery_1.6.js
browser/devtools/markupview/test/browser_markupview_events_jquery_1.7.js
browser/devtools/markupview/test/browser_markupview_events_jquery_2.1.1.js
browser/devtools/markupview/test/doc_markup_events_jquery.html
toolkit/devtools/event-parsers.js
toolkit/devtools/server/actors/inspector.js
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_1.0.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_1.0.js
@@ -71,30 +71,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       },
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_1.1.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_1.1.js
@@ -75,30 +75,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       },
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_1.11.1.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_1.11.1.js
@@ -46,30 +46,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       }
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_1.2.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_1.2.js
@@ -46,30 +46,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       },
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_1.3.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_1.3.js
@@ -76,30 +76,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       },
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_1.4.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_1.4.js
@@ -46,30 +46,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       },
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_1.6.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_1.6.js
@@ -46,30 +46,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       },
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_1.7.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_1.7.js
@@ -46,30 +46,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       },
--- a/browser/devtools/markupview/test/browser_markupview_events_jquery_2.1.1.js
+++ b/browser/devtools/markupview/test/browser_markupview_events_jquery_2.1.1.js
@@ -46,30 +46,34 @@ const TEST_DATA = [
                  "    alert(7);\n" +
                  "  };\n" +
                  "  var handler8 = function divClick2() {\n" +
                  "    alert(8);\n" +
                  "  };\n" +
                  "  var handler9 = function divKeyDown() {\n" +
                  "    alert(9);\n" +
                  "  };\n" +
+                 "  var handler10 = function divDragOut() {\n" +
+                 "    alert(10);\n" +
+                 "  };\n" +
                  "\n" +
                  "  if ($(\"#livediv\").live) {\n" +
                  "    $(\"#livediv\").live(\"dblclick\", handler1);\n" +
                  "    $(\"#livediv\").live(\"dragstart\", handler2);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").delegate) {\n" +
                  "    $(document).delegate(\"#livediv\", \"dragleave\", handler3);\n" +
                  "    $(document).delegate(\"#livediv\", \"dragend\", handler4);\n" +
                  "  }\n" +
                  "\n" +
                  "  if ($(\"#livediv\").on) {\n" +
                  "    $(document).on(\"drop\", \"#livediv\", handler5);\n" +
                  "    $(document).on(\"dragover\", \"#livediv\", handler6);\n" +
+                 "    $(document).on(\"dragout\", \"#livediv:xxxxx\", handler10);\n" +
                  "  }\n" +
                  "\n" +
                  "  var div = $(\"div\")[0];\n" +
                  "  $(div).click(handler7);\n" +
                  "  $(div).click(handler8);\n" +
                  "  $(div).keydown(handler9);\n" +
                  "}"
       }
--- a/browser/devtools/markupview/test/doc_markup_events_jquery.html
+++ b/browser/devtools/markupview/test/doc_markup_events_jquery.html
@@ -29,30 +29,32 @@
         var handler2 = function liveDivDragStart() { alert(2); };
         var handler3 = function liveDivDragLeave() { alert(3); };
         var handler4 = function liveDivDragEnd() { alert(4); };
         var handler5 = function liveDivDrop() { alert(5); };
         var handler6 = function liveDivDragOver() { alert(6); };
         var handler7 = function divClick1() { alert(7); };
         var handler8 = function divClick2() { alert(8); };
         var handler9 = function divKeyDown() { alert(9); };
+        var handler10 = function divDragOut() { alert(10); };
 
         if ($("#livediv").live) {
           $("#livediv").live( "dblclick", handler1);
           $("#livediv").live( "dragstart", handler2);
         }
 
         if ($("#livediv").delegate) {
           $(document).delegate( "#livediv", "dragleave", handler3);
           $(document).delegate( "#livediv", "dragend", handler4);
         }
 
         if ($("#livediv").on) {
           $(document).on( "drop", "#livediv", handler5);
           $(document).on( "dragover", "#livediv", handler6);
+          $(document).on( "dragout", "#livediv:xxxxx", handler10);
         }
 
         var div = $("div")[0];
         $(div).click(handler7);
         $(div).click(handler8);
         $(div).keydown(handler9);
       });
     </script>
--- a/toolkit/devtools/event-parsers.js
+++ b/toolkit/devtools/event-parsers.js
@@ -215,17 +215,23 @@ function jQueryLiveGetListeners(node, bo
         if (!selector && event.data) {
           selector = event.data.selector || event.data || event.selector;
         }
 
         if (!selector || !node.ownerDocument) {
           continue;
         }
 
-        let matches = node.matches && node.matches(selector);
+        let matches;
+        try {
+          matches = node.matches && node.matches(selector);
+        } catch(e) {
+          // Invalid selector, do nothing.
+        }
+
         if (boolOnEventFound && matches) {
           return true;
         }
 
         if (!matches) {
           continue;
         }
 
--- a/toolkit/devtools/server/actors/inspector.js
+++ b/toolkit/devtools/server/actors/inspector.js
@@ -295,18 +295,23 @@ var NodeActor = exports.NodeActor = prot
   /**
    * Are there event listeners that are listening on this node? This method
    * uses all parsers registered via event-parsers.js.registerEventParser() to
    * check if there are any event listeners.
    */
   get _hasEventListeners() {
     let parsers = this._eventParsers;
     for (let [,{hasListeners}] of parsers) {
-      if (hasListeners && hasListeners(this.rawNode)) {
-        return true;
+      try {
+        if (hasListeners && hasListeners(this.rawNode)) {
+          return true;
+        }
+      } catch(e) {
+        // An object attached to the node looked like a listener but wasn't...
+        // do nothing.
       }
     }
     return false;
   },
 
   writeAttrs: function() {
     if (!this.rawNode.attributes) {
       return undefined;
@@ -336,28 +341,33 @@ var NodeActor = exports.NodeActor = prot
    *         Node for which we are to get listeners.
    */
   getEventListeners: function(node) {
     let parsers = this._eventParsers;
     let dbg = this.parent().tabActor.makeDebugger();
     let events = [];
 
     for (let [,{getListeners, normalizeHandler}] of parsers) {
-      let eventInfos = getListeners(node);
-
-      if (!eventInfos) {
-        continue;
-      }
-
-      for (let eventInfo of eventInfos) {
-        if (normalizeHandler) {
-          eventInfo.normalizeHandler = normalizeHandler;
+      try {
+        let eventInfos = getListeners(node);
+
+        if (!eventInfos) {
+          continue;
         }
 
-        this.processHandlerForEvent(node, events, dbg, eventInfo);
+        for (let eventInfo of eventInfos) {
+          if (normalizeHandler) {
+            eventInfo.normalizeHandler = normalizeHandler;
+          }
+
+          this.processHandlerForEvent(node, events, dbg, eventInfo);
+        }
+      } catch(e) {
+        // An object attached to the node looked like a listener but wasn't...
+        // do nothing.
       }
     }
 
     return events;
   },
 
   /**
    * Process a handler