Bug 1357503 - Some additional CX exception checks in Console API code, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 18 Apr 2017 22:22:55 +0200
changeset 353739 bbd8e6ecf4a00d33736f1df5f906a6331467d966
parent 353738 603563fad0fe1e2d2fe4238cb0b251cae371b2c2
child 353740 255057a14c43736b2b0a9f42a077ba5f1fb0b2eb
push id31676
push usercbook@mozilla.com
push dateWed, 19 Apr 2017 08:33:26 +0000
treeherdermozilla-central@a1b682b9b39d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1357503
milestone55.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 1357503 - Some additional CX exception checks in Console API code, r=smaug
dom/console/Console.cpp
--- a/dom/console/Console.cpp
+++ b/dom/console/Console.cpp
@@ -727,16 +727,19 @@ private:
     mClonedData.mParent = nullptr;
 
     if (!ok) {
       return;
     }
 
     MOZ_ASSERT(argumentsValue.isObject());
     JS::Rooted<JSObject*> argumentsObj(aCx, &argumentsValue.toObject());
+    if (NS_WARN_IF(!argumentsObj)) {
+      return;
+    }
 
     uint32_t length;
     if (!JS_GetArrayLength(aCx, argumentsObj, &length)) {
       return;
     }
 
     Sequence<JS::Value> arguments;
 
@@ -1005,16 +1008,18 @@ Console::TimeEnd(const GlobalObject& aGl
 }
 
 /* static */ void
 Console::TimeStamp(const GlobalObject& aGlobal,
                    const JS::Handle<JS::Value> aData)
 {
   JSContext* cx = aGlobal.Context();
 
+  ClearException ce(cx);
+
   Sequence<JS::Value> data;
   SequenceRooter<JS::Value> rooter(cx, &data);
 
   if (aData.isString() && !data.AppendElement(aData, fallible)) {
     return;
   }
 
   Method(aGlobal, MethodTimeStamp, NS_LITERAL_STRING("timeStamp"), data);
@@ -1301,39 +1306,45 @@ Console::MethodInternal(JSContext* aCx, 
 
       // The 'timeStamp' recordings do not need an argument; use empty string
       // if no arguments passed in.
       if (isTimelineRecording && aMethodName == MethodTimeStamp) {
         JS::Rooted<JS::Value> value(aCx, aData.Length() == 0
           ? JS_GetEmptyStringValue(aCx)
           : aData[0]);
         JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
+        if (!jsString) {
+          return;
+        }
 
         nsAutoJSString key;
-        if (jsString) {
-          key.init(aCx, jsString);
+        if (!key.init(aCx, jsString)) {
+          return;
         }
 
         timelines->AddMarkerForDocShell(docShell, Move(
           MakeUnique<TimestampTimelineMarker>(key)));
       }
       // For `console.time(foo)` and `console.timeEnd(foo)`.
       else if (isTimelineRecording && aData.Length() == 1) {
         JS::Rooted<JS::Value> value(aCx, aData[0]);
         JS::Rooted<JSString*> jsString(aCx, JS::ToString(aCx, value));
-
-        if (jsString) {
-          nsAutoJSString key;
-          if (key.init(aCx, jsString)) {
-            timelines->AddMarkerForDocShell(docShell, Move(
-              MakeUnique<ConsoleTimelineMarker>(
-                key, aMethodName == MethodTime ? MarkerTracingType::START
-                                               : MarkerTracingType::END)));
-          }
+        if (!jsString) {
+          return;
         }
+
+        nsAutoJSString key;
+        if (!key.init(aCx, jsString)) {
+          return;
+        }
+
+        timelines->AddMarkerForDocShell(docShell, Move(
+          MakeUnique<ConsoleTimelineMarker>(
+            key, aMethodName == MethodTime ? MarkerTracingType::START
+                                           : MarkerTracingType::END)));
       }
     } else {
       WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
       MOZ_ASSERT(workerPrivate);
 
       monotonicTimer = workerPrivate->TimeStampToDOMHighRes(TimeStamp::Now());
     }
   }