Bug 606357 - Make jsd values not compartment mismatch. r=gal
authorBlake Kaplan <mrbkap@gmail.com>
Mon, 25 Oct 2010 12:12:32 -0700
changeset 56450 dd34396ba8d892701e43074e4b559dbf5938a055
parent 56449 4e8cfc63fbc351847d968310587356dd6a75eb21
child 56451 78d13ca88dd2f01e9f4ce8e921c5ea0e542c7be3
push idunknown
push userunknown
push dateunknown
reviewersgal
bugs606357
milestone2.0b8pre
Bug 606357 - Make jsd values not compartment mismatch. r=gal
js/jsd/jsd_val.c
--- a/js/jsd/jsd_val.c
+++ b/js/jsd/jsd_val.c
@@ -154,17 +154,17 @@ jsd_IsValueNative(JSDContext* jsdc, JSDV
     JSFunction* fun;
     JSExceptionState* exceptionState;
     JSCrossCompartmentCall *call = NULL;
 
     if(jsd_IsValueFunction(jsdc, jsdval))
     {
         JSBool ok = JS_FALSE;
         JS_BeginRequest(cx);
-        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
+        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, JSVAL_TO_OBJECT(val));
         if(!call) {
             JS_EndRequest(cx);
 
             return JS_FALSE;
         }
 
         exceptionState = JS_SaveExceptionState(cx);
         fun = JS_ValueToFunction(cx, val);
@@ -217,17 +217,19 @@ jsd_GetValueString(JSDContext* jsdc, JSD
     if(!jsdval->string)
     {
         /* if the jsval is a string, then we don't need to double root it */
         if(JSVAL_IS_STRING(jsdval->val))
             jsdval->string = JSVAL_TO_STRING(jsdval->val);
         else
         {
             JS_BeginRequest(cx);
-            call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
+            call = JSVAL_IS_PRIMITIVE(jsdval->val)
+                   ? NULL
+                   : JS_EnterCrossCompartmentCall(jsdc->dumbContext, JSVAL_TO_OBJECT(jsdval->val));
             if(!call) {
                 JS_EndRequest(cx);
 
                 return NULL;
             }
 
             exceptionState = JS_SaveExceptionState(cx);
             jsdval->string = JS_ValueToString(cx, jsdval->val);
@@ -251,17 +253,17 @@ jsd_GetValueFunctionName(JSDContext* jsd
     JSFunction* fun;
     JSExceptionState* exceptionState;
     JSCrossCompartmentCall *call = NULL;
 
     if(!jsdval->funName && jsd_IsValueFunction(jsdc, jsdval))
     {
         JS_BeginRequest(cx);
 
-        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
+        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, JSVAL_TO_OBJECT(jsdval->val));
         if(!call) {
             JS_EndRequest(cx);
 
             return NULL;
         }
 
         exceptionState = JS_SaveExceptionState(cx);
         fun = JS_ValueToFunction(cx, jsdval->val);
@@ -403,36 +405,39 @@ static void _freeProps(JSDContext* jsdc,
     }
     JS_ASSERT(JS_CLIST_IS_EMPTY(&jsdval->props));
     CLEAR_BIT_FLAG(jsdval->flags, GOT_PROPS);
 }
 
 static JSBool _buildProps(JSDContext* jsdc, JSDValue* jsdval)
 {
     JSContext* cx = jsdc->dumbContext;
+    JSObject *obj;
     JSPropertyDescArray pda;
     uintN i;
     JSCrossCompartmentCall *call = NULL;
 
     JS_ASSERT(JS_CLIST_IS_EMPTY(&jsdval->props));
     JS_ASSERT(!(CHECK_BIT_FLAG(jsdval->flags, GOT_PROPS)));
     JS_ASSERT(JSVAL_IS_OBJECT(jsdval->val));
 
-    if(!JSVAL_IS_OBJECT(jsdval->val) || JSVAL_IS_NULL(jsdval->val))
+    if(JSVAL_IS_PRIMITIVE(jsdval->val))
         return JS_FALSE;
 
+    obj = JSVAL_TO_OBJECT(jsdval->val);
+
     JS_BeginRequest(cx);
-    call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
-    if(!call) {
+    call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
+    if(!call)
+    {
         JS_EndRequest(jsdc->dumbContext);
-
         return JS_FALSE;
     }
 
-    if(!JS_GetPropertyDescArray(cx, JSVAL_TO_OBJECT(jsdval->val), &pda))
+    if(!JS_GetPropertyDescArray(cx, obj, &pda))
     {
         JS_EndRequest(cx);
         JS_LeaveCrossCompartmentCall(call);
         return JS_FALSE;
     }
 
     for(i = 0; i < pda.length; i++)
     {
@@ -563,17 +568,17 @@ jsd_GetValueProperty(JSDContext* jsdc, J
 
     if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
         return NULL;
 
     nameChars = JS_GetStringChars(name);
     nameLen   = JS_GetStringLength(name);
 
     JS_BeginRequest(cx);
-    call = JS_EnterCrossCompartmentCall(cx, jsdc->glob);
+    call = JS_EnterCrossCompartmentCall(cx, obj);
     if(!call) {
         JS_EndRequest(cx);
 
         return NULL;
     }
 
     JS_GetUCPropertyAttributes(cx, obj, nameChars, nameLen, &attrs, &found);
     if (!found)
@@ -638,17 +643,17 @@ jsd_GetValuePrototype(JSDContext* jsdc, 
         JSObject* proto;
         JS_ASSERT(!jsdval->proto);
         SET_BIT_FLAG(jsdval->flags, GOT_PROTO);
         if(!JSVAL_IS_OBJECT(jsdval->val))
             return NULL;
         if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
             return NULL;
         JS_BeginRequest(jsdc->dumbContext);
-        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
+        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
         if(!call) {
             JS_EndRequest(jsdc->dumbContext);
 
             return NULL;
         }
         proto = JS_GetPrototype(jsdc->dumbContext, obj);
         JS_LeaveCrossCompartmentCall(call);
         JS_EndRequest(jsdc->dumbContext);
@@ -672,20 +677,20 @@ jsd_GetValueParent(JSDContext* jsdc, JSD
         JSObject* parent;
         JS_ASSERT(!jsdval->parent);
         SET_BIT_FLAG(jsdval->flags, GOT_PARENT);
         if(!JSVAL_IS_OBJECT(jsdval->val))
             return NULL;
         if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
             return NULL;
         JS_BeginRequest(jsdc->dumbContext);
-        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext,obj);
+        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
         if(!call) {
             JS_EndRequest(jsdc->dumbContext);
-            
+
             return NULL;
         }
         parent = JS_GetParent(jsdc->dumbContext,obj);
         JS_LeaveCrossCompartmentCall(call);
         JS_EndRequest(jsdc->dumbContext);
         if(!parent)
             return NULL;
         jsdval->parent = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(parent));
@@ -707,17 +712,17 @@ jsd_GetValueConstructor(JSDContext* jsdc
         JSObject* ctor;
         JS_ASSERT(!jsdval->ctor);
         SET_BIT_FLAG(jsdval->flags, GOT_CTOR);
         if(!JSVAL_IS_OBJECT(jsdval->val))
             return NULL;
         if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
             return NULL;
         JS_BeginRequest(jsdc->dumbContext);
-        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
+        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
         if(!call) {
             JS_EndRequest(jsdc->dumbContext);
 
             return NULL;
         }
         proto = JS_GetPrototype(jsdc->dumbContext,obj);
         if(!proto)
         {
@@ -744,17 +749,17 @@ jsd_GetValueClassName(JSDContext* jsdc, 
     JSCrossCompartmentCall *call = NULL;
 
     if(!jsdval->className && JSVAL_IS_OBJECT(val))
     {
         JSObject* obj;
         if(!(obj = JSVAL_TO_OBJECT(val)))
             return NULL;
         JS_BeginRequest(jsdc->dumbContext);
-        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, jsdc->glob);
+        call = JS_EnterCrossCompartmentCall(jsdc->dumbContext, obj);
         if(!call) {
             JS_EndRequest(jsdc->dumbContext);
 
             return NULL;
         }
         if(JS_GET_CLASS(jsdc->dumbContext, obj))
             jsdval->className = JS_GET_CLASS(jsdc->dumbContext, obj)->name;
         JS_LeaveCrossCompartmentCall(call);