Bug 1206822 - Handle JS exceptions in NativeJSContainer; r=snorp

Clear any JS exceptions in appropriate places in NativeJSContainer, so
the exceptions don't affect subsequent JS API calls. We don't actually
"handle" the exceptions because we throw a Java exception instead or it
is safe to ignore the JS exception.
This commit is contained in:
Jim Chen 2016-04-18 08:46:31 -04:00
parent 80156aa1ad
commit 5f8eefe278

View File

@ -39,16 +39,6 @@ bool CheckThread()
return true;
}
bool
CheckJSCall(bool result)
{
if (!result) {
jni::ThrowException("java/lang/UnsupportedOperationException",
"JSAPI call failed");
}
return result;
}
template<class C, typename T> bool
CheckJNIArgument(const jni::Ref<C, T>& arg)
{
@ -129,6 +119,16 @@ class NativeJSContainerImpl final
return !!mJSObject;
}
bool CheckJSCall(bool result) const
{
if (!result) {
JS_ClearPendingException(mJSContext);
jni::ThrowException("java/lang/UnsupportedOperationException",
"JSAPI call failed");
}
return result;
}
// Check that a JS Value contains a particular property type as indicaed by
// the property's InValue method (e.g. StringProperty::InValue).
bool CheckProperty(bool (Self::*InValue)(JS::HandleValue) const,
@ -435,6 +435,7 @@ class NativeJSContainerImpl final
if (!JS_IsArrayObject(mJSContext, obj, &isArray) ||
!isArray ||
!JS_GetArrayLength(mJSContext, obj, &length)) {
JS_ClearPendingException(mJSContext);
return false;
}
if (!length) {
@ -444,8 +445,11 @@ class NativeJSContainerImpl final
// We only check to see the first element is the target type. If the
// array has mixed types, we'll throw an error during actual conversion.
JS::RootedValue element(mJSContext);
return JS_GetElement(mJSContext, obj, 0, &element) &&
(this->*Prop::InValue)(element);
if (!JS_GetElement(mJSContext, obj, 0, &element)) {
JS_ClearPendingException(mJSContext);
return false;
}
return (this->*Prop::InValue)(element);
}
template<class Prop> typename Prop::NativeArray