Bug 957893 - RequireWakeLock should not crash when the param is an empty string, r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 24 Jan 2014 09:40:40 +0000
changeset 181069 b2b1b90f5082b31cf8280c7c1657f792ca9dc6b8
parent 181068 691a1d12372a9e3a0282561b5b2bda2a64df5216
child 181070 4c6d2381b451ae5530a7a65eb01d98e0fc9a8a04
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs957893
milestone29.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 957893 - RequireWakeLock should not crash when the param is an empty string, r=ehsan
dom/base/Navigator.cpp
dom/power/test/mochitest.ini
dom/power/test/test_bug957893.html
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1138,20 +1138,22 @@ Navigator::RequestWakeLock(const nsAStri
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
 
   nsRefPtr<power::PowerManagerService> pmService =
     power::PowerManagerService::GetInstance();
   // Maybe it went away for some reason... Or maybe we're just called
   // from our XPCOM method.
-  NS_ENSURE_TRUE(pmService, nullptr);
+  if (!pmService) {
+    aRv.Throw(NS_ERROR_UNEXPECTED);
+    return nullptr;
+  }
 
-  ErrorResult rv;
-  return pmService->NewWakeLock(aTopic, mWindow, rv);
+  return pmService->NewWakeLock(aTopic, mWindow, aRv);
 }
 
 nsIDOMMozMobileMessageManager*
 Navigator::GetMozMobileMessage()
 {
   if (!mMobileMessageManager) {
     // Check that our window has not gone away
     NS_ENSURE_TRUE(mWindow, nullptr);
--- a/dom/power/test/mochitest.ini
+++ b/dom/power/test/mochitest.ini
@@ -1,7 +1,8 @@
 [DEFAULT]
 
+[test_bug957893.html]
 [test_bug957899.html]
 [test_power_basics.html]
 [test_power_set_cpusleepallowed.html]
 [test_power_set_screen_brightness.html]
 [test_power_set_screen_enabled.html]
new file mode 100644
--- /dev/null
+++ b/dom/power/test/test_bug957893.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test bug 957893 - Crash in WakeLock</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <script type="application/javascript">
+ try {
+   var wl = navigator.requestWakeLock('');
+   ok(false, "RequestWakeLock throws an exception!");
+ } catch(e) {
+   ok(true, "RequestWakeLock throws an exception!");
+ }
+
+ info("Still alive!");
+
+ </script>
+</body>
+</html>