XPCCallContext ccx(JS_CALLER, cx, obj);
XPCCallContext ccx(JS_CALLER, cx, JS_GetGlobalObject(cx));
CommonConstructor(JSContext *cx, int name, JSObject *obj, uintN argc,                  jsval *argv, jsval *rval, PRBool enforceSecurity){    XPCCallContext ccx(JS_CALLER, cx, obj);    XPCJSRuntime *rt = ccx.GetRuntime();    if (!rt)    {        XPCThrower::Throw(NS_ERROR_UNEXPECTED, ccx);        return JS_FALSE;    }     nsIXPCSecurityManager* sm = ccx.GetXPCContext()        ->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_CALL_METHOD);    XPCWrappedNative * wrapper = ccx.GetWrapper();    if(!sm || NS_FAILED(sm->CanAccess(nsIXPCSecurityManager::ACCESS_CALL_METHOD,                                      &ccx, ccx, ccx.GetFlattenedJSObject(),                                      wrapper->GetIdentityObject(),                                      wrapper->GetClassInfo(),                                      rt->GetStringJSVal(name),                                      wrapper->GetSecurityInfoAddr())))    {        // Security manager will have set an exception        return JS_FALSE;    }    // Check if IDispatch is enabled, fail if not    if(!nsXPConnect::IsIDispatchEnabled())    {        XPCThrower::Throw(NS_ERROR_XPC_IDISPATCH_NOT_ENABLED, ccx);        return JS_FALSE;    }    // Make sure we were called with one string parameter    if(argc != 1 || (argc == 1 && !JSVAL_IS_STRING(argv[0])))    {        XPCThrower::Throw(NS_ERROR_XPC_COM_INVALID_CLASS_ID, ccx);        return JS_FALSE;    }    PRUint32 len;    jschar * className = xpc_JSString2String(ccx, argv[0], &len);    CComBSTR bstrClassName(len, className);    if(!className)    {        XPCThrower::Throw(NS_ERROR_XPC_COM_INVALID_CLASS_ID, ccx);        return JS_FALSE;    }    // Instantiate the desired COM object    CComPtr<IDispatch> pDispatch;    HRESULT rv = XPCDispObject::COMCreateInstance(ccx, bstrClassName,                                                  enforceSecurity, &pDispatch);    if(FAILED(rv))    {        XPCThrower::ThrowCOMError(ccx, rv, NS_ERROR_XPC_COM_CREATE_FAILED);        return JS_FALSE;    }    // Get a wrapper for our object    nsCOMPtr<nsIXPConnectJSObjectHolder> holder;    nsresult nsrv = ccx.GetXPConnect()->WrapNative(        ccx, obj, NS_REINTERPRET_CAST(nsISupports*, pDispatch.p), NSID_IDISPATCH,        getter_AddRefs(holder));    if(NS_FAILED(nsrv))    {        XPCThrower::Throw(nsrv, ccx);        return JS_FALSE;    }    // get and return the JS object wrapper    JSObject * jsobj;    nsrv = holder->GetJSObject(&jsobj);    if(NS_FAILED(nsrv))    {        XPCThrower::Throw(nsrv, ccx);        return JS_FALSE;    }    *rval = OBJECT_TO_JSVAL(jsobj);    return JS_TRUE;}