Bug 705333 - Use IDL for nsJSCID::{CreateInstance,GetService}; r=bholley
authorMs2ger <ms2ger@gmail.com>
Sat, 03 Dec 2011 22:50:16 +0100
changeset 82999 f7c8894bbdaee63f1aa9f4746a20fef1d7c9400a
parent 82998 09f69613e8ebdb012efae5553182857c0874b128
child 83000 1e8ebd4a8389044d32e037120538069e4aada28e
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs705333
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 705333 - Use IDL for nsJSCID::{CreateInstance,GetService}; r=bholley
js/xpconnect/idl/xpcjsid.idl
js/xpconnect/src/XPCJSID.cpp
--- a/js/xpconnect/idl/xpcjsid.idl
+++ b/js/xpconnect/idl/xpcjsid.idl
@@ -1,11 +1,10 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- *
- * ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -60,21 +59,21 @@ interface nsIJSID : nsISupports
     [notxpcom] const_nsID_ptr getID();
 };
 
 [scriptable, uuid(e76ec564-a080-4705-8609-384c755ec91e)]
 interface nsIJSIID : nsIJSID
 {
 };
 
-[scriptable, uuid(26b2a374-6eaf-46d4-acaf-1c6be152d36b)]
+[scriptable, uuid(bf5eb086-9eaa-4694-aec3-fe4aac6119bd)]
 interface nsIJSCID : nsIJSID
 {
-    nsISupports createInstance();
-    nsISupports getService();
+    [implicit_jscontext,optional_argc] jsval createInstance([optional] in jsval iid);
+    [implicit_jscontext,optional_argc] jsval getService([optional] in jsval iid);
 };
 
 /* this goes into the C++ header verbatim. */
 %{ C++
 /********************************************************/
 // {F24A14F0-4FA1-11d3-9894-006008962422}
 #define NS_JS_ID_CID  \
 { 0xf24a14f0, 0x4fa1, 0x11d3, \
--- a/js/xpconnect/src/XPCJSID.cpp
+++ b/js/xpconnect/src/XPCJSID.cpp
@@ -674,168 +674,146 @@ nsJSCID::NewID(const char* str)
         }
         if (!success)
             NS_RELEASE(idObj);
     }
     return idObj;
 }
 
 static const nsID*
-GetIIDArg(PRUint32 argc, jsval* argv, JSContext* cx)
+GetIIDArg(PRUint32 argc, const JS::Value& val, JSContext* cx)
 {
     const nsID* iid;
 
     // If an IID was passed in then use it
     if (argc) {
         JSObject* iidobj;
-        jsval val = *argv;
         if (JSVAL_IS_PRIMITIVE(val) ||
             !(iidobj = JSVAL_TO_OBJECT(val)) ||
             !(iid = xpc_JSObjectToID(cx, iidobj))) {
             return nsnull;
         }
     } else
         iid = &NS_GET_IID(nsISupports);
 
     return iid;
 }
 
+static JSObject*
+GetWrapperObject()
+{
+    nsXPConnect* xpc = nsXPConnect::GetXPConnect();
+    if (!xpc)
+        return NULL;
+
+    nsAXPCNativeCallContext *ccxp = NULL;
+    xpc->GetCurrentNativeCallContext(&ccxp);
+    if (!ccxp)
+        return NULL;
+
+    nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
+    ccxp->GetCalleeWrapper(getter_AddRefs(wrapper));
+    JSObject* obj;
+    wrapper->GetJSObject(&obj);
+    return obj;
+}
+
 /* nsISupports createInstance (); */
 NS_IMETHODIMP
-nsJSCID::CreateInstance(nsISupports **_retval)
+nsJSCID::CreateInstance(const JS::Value& iidval, JSContext* cx,
+                        PRUint8 optionalArgc, JS::Value* retval)
 {
     if (!mDetails.IsValid())
         return NS_ERROR_XPC_BAD_CID;
 
-    nsXPConnect* xpc = nsXPConnect::GetXPConnect();
-    if (!xpc)
-        return NS_ERROR_UNEXPECTED;
-
-    nsAXPCNativeCallContext *ccxp = nsnull;
-    xpc->GetCurrentNativeCallContext(&ccxp);
-    if (!ccxp)
+    JSObject* obj = GetWrapperObject();
+    if (!obj) {
         return NS_ERROR_UNEXPECTED;
-
-    PRUint32 argc;
-    jsval * argv;
-    jsval * vp;
-    JSContext* cx;
-    JSObject* obj;
-
-    ccxp->GetJSContext(&cx);
-    ccxp->GetArgc(&argc);
-    ccxp->GetArgvPtr(&argv);
-    ccxp->GetRetValPtr(&vp);
-
-    nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
-    ccxp->GetCalleeWrapper(getter_AddRefs(wrapper));
-    wrapper->GetJSObject(&obj);
+    }
 
     // Do the security check if necessary
-
     XPCContext* xpcc = XPCContext::GetXPCContext(cx);
 
     nsIXPCSecurityManager* sm;
     sm = xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_CREATE_INSTANCE);
     if (sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID()))) {
         NS_ERROR("how are we not being called from chrome here?");
         return NS_OK;
     }
 
     // If an IID was passed in then use it
-    const nsID* iid = GetIIDArg(argc, argv, cx);
+    const nsID* iid = GetIIDArg(optionalArgc, iidval, cx);
     if (!iid)
         return NS_ERROR_XPC_BAD_IID;
 
     nsCOMPtr<nsIComponentManager> compMgr;
     nsresult rv = NS_GetComponentManager(getter_AddRefs(compMgr));
     if (NS_FAILED(rv))
         return NS_ERROR_UNEXPECTED;
 
     nsCOMPtr<nsISupports> inst;
     rv = compMgr->CreateInstance(mDetails.ID(), nsnull, *iid, getter_AddRefs(inst));
     NS_ASSERTION(NS_FAILED(rv) || inst, "component manager returned success, but instance is null!");
 
     if (NS_FAILED(rv) || !inst)
         return NS_ERROR_XPC_CI_RETURNED_FAILURE;
 
-    rv = xpc->WrapNativeToJSVal(cx, obj, inst, nsnull, iid, true, vp, nsnull);
-    if (NS_FAILED(rv) || JSVAL_IS_PRIMITIVE(*vp))
+    rv = nsXPConnect::GetXPConnect()->WrapNativeToJSVal(cx, obj, inst, nsnull, iid, true, retval, nsnull);
+    if (NS_FAILED(rv) || JSVAL_IS_PRIMITIVE(*retval))
         return NS_ERROR_XPC_CANT_CREATE_WN;
-    ccxp->SetReturnValueWasSet(true);
     return NS_OK;
 }
 
 /* nsISupports getService (); */
 NS_IMETHODIMP
-nsJSCID::GetService(nsISupports **_retval)
+nsJSCID::GetService(const JS::Value& iidval, JSContext* cx,
+                    PRUint8 optionalArgc, JS::Value* retval)
 {
     if (!mDetails.IsValid())
         return NS_ERROR_XPC_BAD_CID;
 
-    nsXPConnect* xpc = nsXPConnect::GetXPConnect();
-    if (!xpc)
-        return NS_ERROR_UNEXPECTED;
-
-    nsAXPCNativeCallContext *ccxp = nsnull;
-    xpc->GetCurrentNativeCallContext(&ccxp);
-    if (!ccxp)
+    JSObject* obj = GetWrapperObject();
+    if (!obj) {
         return NS_ERROR_UNEXPECTED;
-
-    PRUint32 argc;
-    jsval * argv;
-    jsval * vp;
-    JSContext* cx;
-    JSObject* obj;
-
-    ccxp->GetJSContext(&cx);
-    ccxp->GetArgc(&argc);
-    ccxp->GetArgvPtr(&argv);
-    ccxp->GetRetValPtr(&vp);
-
-    nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
-    ccxp->GetCalleeWrapper(getter_AddRefs(wrapper));
-    wrapper->GetJSObject(&obj);
+    }
 
     // Do the security check if necessary
-
     XPCContext* xpcc = XPCContext::GetXPCContext(cx);
 
     nsIXPCSecurityManager* sm;
     sm = xpcc->GetAppropriateSecurityManager(nsIXPCSecurityManager::HOOK_GET_SERVICE);
     if (sm && NS_FAILED(sm->CanCreateInstance(cx, mDetails.ID()))) {
         NS_ASSERTION(JS_IsExceptionPending(cx),
                      "security manager vetoed GetService without setting exception");
         return NS_OK;
     }
 
     // If an IID was passed in then use it
-    const nsID* iid = GetIIDArg(argc, argv, cx);
+    const nsID* iid = GetIIDArg(optionalArgc, iidval, cx);
     if (!iid)
         return NS_ERROR_XPC_BAD_IID;
 
     nsCOMPtr<nsIServiceManager> svcMgr;
     nsresult rv = NS_GetServiceManager(getter_AddRefs(svcMgr));
     if (NS_FAILED(rv))
         return rv;
 
     nsCOMPtr<nsISupports> srvc;
     rv = svcMgr->GetService(mDetails.ID(), *iid, getter_AddRefs(srvc));
     NS_ASSERTION(NS_FAILED(rv) || srvc, "service manager returned success, but service is null!");
     if (NS_FAILED(rv) || !srvc)
         return NS_ERROR_XPC_GS_RETURNED_FAILURE;
 
     JSObject* instJSObj;
     nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
-    rv = xpc->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(holder));
+    rv = nsXPConnect::GetXPConnect()->WrapNative(cx, obj, srvc, *iid, getter_AddRefs(holder));
     if (NS_FAILED(rv) || !holder || NS_FAILED(holder->GetJSObject(&instJSObj)))
         return NS_ERROR_XPC_CANT_CREATE_WN;
 
-    *vp = OBJECT_TO_JSVAL(instJSObj);
-    ccxp->SetReturnValueWasSet(true);
+    *retval = OBJECT_TO_JSVAL(instJSObj);
     return NS_OK;
 }
 
 /* bool construct (in nsIXPConnectWrappedNative wrapper, in JSContextPtr cx, in JSObjectPtr obj, in PRUint32 argc, in JSValPtr argv, in JSValPtr vp); */
 NS_IMETHODIMP
 nsJSCID::Construct(nsIXPConnectWrappedNative *wrapper,
                    JSContext * cx, JSObject * obj,
                    PRUint32 argc, jsval * argv, jsval * vp,