Check for more accurate exceptions in npruntime, part 1. b=474157 r/sr=jst
authorJosh Aas <joshmoz@gmail.com>
Fri, 08 May 2009 09:55:04 -0400
changeset 28128 c7b717f0a4043d0da5c44ffd344a80da89af908a
parent 28127 515054a2dc431c86f588eb676aec1597be81805b
child 28130 0e7adf7b300cd6d3a79600b4db2bda28a945a95d
push id6903
push userjosh@mozilla.com
push dateFri, 08 May 2009 13:53:20 +0000
treeherdermozilla-central@c7b717f0a404 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs474157
milestone1.9.2a1pre
Check for more accurate exceptions in npruntime, part 1. b=474157 r/sr=jst
modules/plugin/base/src/nsJSNPRuntime.cpp
--- a/modules/plugin/base/src/nsJSNPRuntime.cpp
+++ b/modules/plugin/base/src/nsJSNPRuntime.cpp
@@ -1131,58 +1131,74 @@ GetNPObject(JSContext *cx, JSObject *obj
 
   if (!obj) {
     return nsnull;
   }
 
   return (NPObject *)::JS_GetPrivate(cx, obj);
 }
 
+
+// Does not actually add a property because this is always followed by a
+// SetProperty call.
 static JSBool
 NPObjWrapper_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
 {
   NPObject *npobj = GetNPObject(cx, obj);
 
   if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
       !npobj->_class->hasMethod) {
     ThrowJSException(cx, "Bad NPObject as private data!");
 
     return JS_FALSE;
   }
 
   PluginDestructionGuard pdg(LookupNPP(npobj));
 
+  JSBool hasProperty = npobj->_class->hasProperty(npobj, (NPIdentifier)id);
+  if (!ReportExceptionIfPending(cx))
+    return JS_FALSE;
+
+  if (hasProperty)
+    return JS_TRUE;
+
   // We must permit methods here since JS_DefineUCFunction() will add
   // the function as a property
-  if (!npobj->_class->hasProperty(npobj, (NPIdentifier)id) &&
-      !npobj->_class->hasMethod(npobj, (NPIdentifier)id)) {
-    ThrowJSException(cx, "Trying to add unsupported property on scriptable "
-                     "plugin object!");
+  JSBool hasMethod = npobj->_class->hasMethod(npobj, (NPIdentifier)id);
+  if (!ReportExceptionIfPending(cx))
+    return JS_FALSE;
+
+  if (!hasMethod) {
+    ThrowJSException(cx, "Trying to add unsupported property on NPObject!");
 
     return JS_FALSE;
   }
 
-  return ReportExceptionIfPending(cx);
+  return JS_TRUE;
 }
 
 static JSBool
 NPObjWrapper_DelProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
 {
   NPObject *npobj = GetNPObject(cx, obj);
 
   if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
       !npobj->_class->removeProperty) {
     ThrowJSException(cx, "Bad NPObject as private data!");
 
     return JS_FALSE;
   }
 
   PluginDestructionGuard pdg(LookupNPP(npobj));
 
-  if (!npobj->_class->hasProperty(npobj, (NPIdentifier)id))
+  JSBool hasProperty = npobj->_class->hasProperty(npobj, (NPIdentifier)id);
+  if (!ReportExceptionIfPending(cx))
+    return JS_FALSE;
+
+  if (!hasProperty)
     return JS_TRUE;
 
   if (!npobj->_class->removeProperty(npobj, (NPIdentifier)id))
     *vp = JSVAL_FALSE;
 
   return ReportExceptionIfPending(cx);
 }
 
@@ -1205,43 +1221,45 @@ NPObjWrapper_SetProperty(JSContext *cx, 
   if (!npp) {
     ThrowJSException(cx, "No NPP found for NPObject!");
 
     return JS_FALSE;
   }
 
   PluginDestructionGuard pdg(npp);
 
-  if (!npobj->_class->hasProperty(npobj, (NPIdentifier)id)) {
-    ThrowJSException(cx, "Trying to set unsupported property on scriptable "
-                     "plugin object!");
+  JSBool hasProperty = !npobj->_class->hasProperty(npobj, (NPIdentifier)id);
+  if (!ReportExceptionIfPending(cx))
+    return JS_FALSE;
+
+  if (!hasProperty) {
+    ThrowJSException(cx, "Trying to set unsupported property on NPObject!");
 
     return JS_FALSE;
   }
 
   NPVariant npv;
   if (!JSValToNPVariant(npp, cx, *vp, &npv)) {
     ThrowJSException(cx, "Error converting jsval to NPVariant!");
 
     return JS_FALSE;
   }
 
   JSBool ok = npobj->_class->setProperty(npobj, (NPIdentifier)id, &npv);
-
-  // Release the variant
-  _releasevariantvalue(&npv);
+  _releasevariantvalue(&npv); // Release the variant
+  if (!ReportExceptionIfPending(cx))
+    return JS_FALSE;
 
   if (!ok) {
-    ThrowJSException(cx, "Error setting property on scriptable plugin "
-                     "object!");
+    ThrowJSException(cx, "Error setting property on NPObject!");
 
     return JS_FALSE;
   }
 
-  return ReportExceptionIfPending(cx);
+  return JS_TRUE;
 }
 
 static JSBool
 NPObjWrapper_GetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
 {
   NPObject *npobj = GetNPObject(cx, obj);
 
   if (!npobj || !npobj->_class || !npobj->_class->hasProperty ||
@@ -1258,42 +1276,41 @@ NPObjWrapper_GetProperty(JSContext *cx, 
     ThrowJSException(cx, "No NPP found for NPObject!");
 
     return JS_FALSE;
   }
 
   PluginDestructionGuard pdg(npp);
 
   PRBool hasProperty = npobj->_class->hasProperty(npobj, (NPIdentifier)id);
+  if (!ReportExceptionIfPending(cx))
+    return JS_FALSE;
+
   PRBool hasMethod = npobj->_class->hasMethod(npobj, (NPIdentifier)id);
-
-  // To support ambiguous members, we return NPObject Member class here.
+  if (!ReportExceptionIfPending(cx))
+    return JS_FALSE;
+
+  // We return NPObject Member class here to support ambiguous members.
   if (hasProperty && hasMethod)
     return CreateNPObjectMember(npp, cx, obj, npobj, id, vp);
 
   if (hasProperty) {
     NPVariant npv;
     VOID_TO_NPVARIANT(npv);
 
-    if (!npobj->_class->getProperty(npobj, (NPIdentifier)id, &npv)) {
-      ThrowJSException(cx, "Error setting property on scriptable plugin "
-                       "object!");
-
+    if (npobj->_class->getProperty(npobj, (NPIdentifier)id, &npv))
+      *vp = NPVariantToJSVal(npp, cx, &npv);
+
+    _releasevariantvalue(&npv);
+
+    if (!ReportExceptionIfPending(cx))
       return JS_FALSE;
-    }
-
-    *vp = NPVariantToJSVal(npp, cx, &npv);
-
-    // *vp now owns the value, release our reference.
-    _releasevariantvalue(&npv);
-
-    return JS_TRUE;
   }
 
-  return ReportExceptionIfPending(cx);
+  return JS_TRUE;
 }
 
 static JSBool
 CallNPMethodInternal(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
                      jsval *rval, PRBool ctorCall)
 {
   while (obj && JS_GET_CLASS(cx, obj) != &sNPObjectJSWrapperClass) {
     obj = ::JS_GetPrototype(cx, obj);