Bug 1397711 - Null-check widget of keyboard event before invoking its PostHandleKeyEvent. r?masayuki draft
authorXidorn Quan <me@upsuper.org>
Thu, 07 Sep 2017 22:07:34 +1000
changeset 660749 c74bdaf74aefbf6a0d3529b9587efffca13fdd2a
parent 660748 fcd616f73e6c305e4f68b11324f2b4c36f38ed83
child 730338 1104ab52b8757d8c41159c649f82e994aaeb1718
push id78508
push userxquan@mozilla.com
push dateThu, 07 Sep 2017 12:08:20 +0000
reviewersmasayuki
bugs1397711
milestone57.0a1
Bug 1397711 - Null-check widget of keyboard event before invoking its PostHandleKeyEvent. r?masayuki MozReview-Commit-ID: KTniEBMvw9q
dom/events/EventStateManager.cpp
dom/events/crashtests/1397711.html
dom/events/crashtests/crashtests.list
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -2891,17 +2891,19 @@ EventStateManager::PostHandleKeyboardEve
           return;
         }
       }
     }
     // The widget expects a reply for every keyboard event. If the event wasn't
     // dispatched to a content process (non-e10s or no content process
     // running), we need to short-circuit here. Otherwise, we need to wait for
     // the content process to handle the event.
-    aKeyboardEvent->mWidget->PostHandleKeyEvent(aKeyboardEvent);
+    if (aKeyboardEvent->mWidget) {
+      aKeyboardEvent->mWidget->PostHandleKeyEvent(aKeyboardEvent);
+    }
     if (aKeyboardEvent->DefaultPrevented()) {
       aStatus = nsEventStatus_eConsumeNoDefault;
       return;
     }
   }
 
   // XXX Currently, our automated tests don't support mKeyNameIndex.
   //     Therefore, we still need to handle this with keyCode.
new file mode 100644
--- /dev/null
+++ b/dom/events/crashtests/1397711.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<script>
+  let code = "x".charCodeAt(0);
+  let e = new KeyboardEvent("keypress", {
+    keyCode: code,
+    charCode: code,
+    bubbles: true
+  });
+  let utils = SpecialPowers.getDOMWindowUtils(window);
+  utils.dispatchDOMEventViaPresShell(document.documentElement, e, false);
+</script>
--- a/dom/events/crashtests/crashtests.list
+++ b/dom/events/crashtests/crashtests.list
@@ -11,8 +11,9 @@ load 1035654-1.html
 load 1035654-2.html
 needs-focus load 1072137-1.html
 load 1143972-1.html
 load 1190036-1.html
 load eventctor-nulldictionary.html
 load eventctor-nullstorage.html
 load recursive-DOMNodeInserted.html
 load recursive-onload.html
+load 1397711.html