Bug 1220688 - catch and ignore JS exceptions when working with nsAutoJSString. r=bz
authorDave Huseby <dhuseby@mozilla.com>
Thu, 12 Nov 2015 13:12:00 +0100
changeset 308725 22d372a893d764554af0edb7e47f817af93b2114
parent 308724 7c22b95c0e297ce2e9e3d548760482cb98e495a5
child 308726 aeb7ece8cbd40280f27ec3631f4f9e5b8b52c5a9
push id7515
push usermjzffr@gmail.com
push dateFri, 13 Nov 2015 14:42:42 +0000
reviewersbz
bugs1220688
milestone45.0a1
Bug 1220688 - catch and ignore JS exceptions when working with nsAutoJSString. r=bz
dom/geolocation/nsGeolocationSettings.cpp
--- a/dom/geolocation/nsGeolocationSettings.cpp
+++ b/dom/geolocation/nsGeolocationSettings.cpp
@@ -255,50 +255,58 @@ nsGeolocationSettings::HandleGeolocation
   // go through all of the objects in the exceptions dictionary
   for (size_t i = 0; i < ids.length(); i++) {
     JS::RootedId id(cx);
     id = ids[i];
 
     // if it is an app that is always precise, skip it
     nsAutoJSString origin;
     if (!origin.init(cx, id)) {
+      JS_ClearPendingException(cx); // catch and ignore any exceptions
       continue;
     }
     if (mAlwaysPreciseApps.Contains(origin)) {
       continue;
     }
 
     // get the app setting object
     JS::RootedValue propertyValue(cx);
-    if (!JS_GetPropertyById(cx, obj, id, &propertyValue) || !propertyValue.isObject()) {
+    if (!JS_GetPropertyById(cx, obj, id, &propertyValue)) {
+      JS_ClearPendingException(cx); // catch and ignore any exceptions
       continue;
     }
     JS::RootedObject settingObj(cx, &propertyValue.toObject());
 
     GeolocationSetting *settings = new GeolocationSetting(origin);
     GPSLOG("adding exception for %s", NS_ConvertUTF16toUTF8(origin).get());
 
     // get the geolocation type
     JS::RootedValue fm(cx);
     if (JS_GetProperty(cx, settingObj, "type", &fm)) {
       settings->HandleTypeChange(fm);
+    } else {
+      JS_ClearPendingException(cx); // catch and ignore any exceptions
     }
 
 #ifdef MOZ_APPROX_LOCATION
     // get the approximate distance if there is one
     JS::RootedValue distance(cx);
     if (JS_GetProperty(cx, settingObj, "distance", &distance)) {
       settings->HandleApproxDistanceChange(distance);
+    } else {
+      JS_ClearPendingException(cx); // catch and ignore any exceptions
     }
 #endif
 
     // get and parse the coords, if any
     JS::RootedValue coords(cx);
     if (JS_GetProperty(cx, settingObj, "coords", &coords)) {
       settings->HandleFixedCoordsChange(coords);
+    } else {
+      JS_ClearPendingException(cx); // catch and ignore any exceptions
     }
 
     // add the per-app setting object to the hashtable
     mPerOriginSettings.Put(origin, settings);
   }
 }
 
 void
@@ -332,21 +340,23 @@ nsGeolocationSettings::HandleGeolocation
     return;
   }
 
   // process the list of apps...
   for (uint32_t i = 0; i < length; ++i) {
     JS::RootedValue value(cx);
 
     if (!JS_GetElement(cx, obj, i, &value) || !value.isString()) {
+      JS_ClearPendingException(cx); // catch and ignore any exceptions
       continue;
     }
 
     nsAutoJSString origin;
     if (!origin.init(cx, value)) {
+      JS_ClearPendingException(cx); // catch and ignore any exceptions
       continue;
     }
 
     GPSLOG("adding always precise for %s", NS_ConvertUTF16toUTF8(origin).get());
 
     // add the origin to the list of apps that will always receive
     // precise location information
     mAlwaysPreciseApps.AppendElement(origin);