CIDCreateInstanceScriptable::Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval, nsIXPConnectWrappedNative* wrapper, nsIXPCScriptable* arbitrary, JSBool* retval)
CIDCreateInstance::Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval, nsIXPConnectWrappedNative* wrapper, nsIXPCScriptable* arbitrary, JSBool* retval)
CIDCreateInstanceScriptable::Call(JSContext *cx, JSObject *obj,                                  uintN argc, jsval *argv,                                  jsval *rval,                                  nsIXPConnectWrappedNative* wrapper,                                  nsIXPCScriptable* arbitrary,                                  JSBool* retval){    CIDCreateInstance* self;    nsJSCID* cidObj;    nsCID*  cid;    PRBool valid;    if(NS_FAILED(wrapper->GetNative((nsISupports**)&self)))        return NS_ERROR_FAILURE;    if(!(cidObj = self->GetCID()) ||       NS_FAILED(cidObj->GetValid(&valid)) ||       !valid ||       NS_FAILED(cidObj->GetId(&cid)) ||       !cid)    {        ThrowException(XPCJSError::BAD_CID, cx);        *retval = JS_FALSE;        return NS_OK;    }    // Do the security check if necessary    XPCContext* xpcc;    if(NULL != (xpcc = nsXPConnect::GetContext(cx)))    {        nsIXPCSecurityManager* sm;        if(NULL != (sm = xpcc->GetSecurityManager()) &&           (xpcc->GetSecurityManagerFlags() &             nsIXPCSecurityManager::HOOK_CREATE_INSTANCE) &&           NS_OK != sm->CanCreateInstance(cx, *cid))        {            // the security manager vetoed. It should have set an exception.            nsAllocator::Free(cid);            *rval = JSVAL_NULL;            *retval = JS_TRUE;            return NS_OK;        }    }    // If an IID was passed in then use it    // XXX should it be JS error to pass something that is *not* and JSID?    const nsID* piid = NULL;    if(argc)    {        JSObject* iidobj;        jsval val = *argv;        if(!JSVAL_IS_VOID(val) && !JSVAL_IS_NULL(val) &&            JSVAL_IS_OBJECT(val) && NULL != (iidobj = JSVAL_TO_OBJECT(val)))        {            piid = xpc_JSObjectToID(cx, iidobj);        }    }    if(!piid)        piid = &(nsCOMTypeInfo<nsISupports>::GetIID());    nsISupports* inst;    nsresult rv;    rv = nsComponentManager::CreateInstance(*cid, NULL, *piid, (void**) &inst);    NS_ASSERTION(NS_FAILED(rv) || inst, "component manager returned success, but instance is null!");    nsAllocator::Free(cid);    if(NS_FAILED(rv) || !inst)    {        ThrowBadResultException(XPCJSError::CI_RETURNED_FAILURE, cx, rv);        *retval = JS_FALSE;        return NS_OK;    }    nsIXPConnectWrappedNative* instWrapper = NULL;    nsIXPConnect* xpc = nsXPConnect::GetXPConnect();    if(xpc)    {        rv = xpc->WrapNative(cx, inst, *piid, &instWrapper);        NS_RELEASE(xpc);    }    NS_RELEASE(inst);    if(NS_FAILED(rv) || !instWrapper)    {        ThrowException(XPCJSError::CANT_CREATE_WN, cx);        *retval = JS_FALSE;        return NS_OK;    }    JSObject* instJSObj;    instWrapper->GetJSObject(&instJSObj);    *rval = OBJECT_TO_JSVAL(instJSObj);    *retval = JS_TRUE;    NS_RELEASE(instWrapper);    return NS_OK;}