Bug 1220688 - catch and ignore JS exceptions when working with nsAutoJSString. r=bz
--- 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);