Bug 1477432 - Part 5: Add a refreshCID method to JSCID objects, r=mccr8
authorNika Layzell <nika@thelayzells.com>
Wed, 18 Jul 2018 00:20:38 -0400
changeset 446900 c019316fcfd49d74775c9b458b3d611f8081ee7e
parent 446899 e3b4c9cdfbd7e118ada704337d1bffa5cae93676
child 446901 ab47ae5672ac00f6525f0d109af570a771d97add
push id35053
push userapavel@mozilla.com
push dateSat, 17 Nov 2018 11:27:54 +0000
treeherdermozilla-central@e4deec61fc8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1477432
milestone65.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 1477432 - Part 5: Add a refreshCID method to JSCID objects, r=mccr8 This lets us get rid of the method 'initalize', which currently needs the internal representation of JSCID. This particular method is removed entirely in Part 9, and only exists to keep intermediate states building & running. Differential Revision: https://phabricator.services.mozilla.com/D2282
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/idl/xpcjsid.idl
js/xpconnect/src/XPCComponents.cpp
js/xpconnect/src/XPCJSID.cpp
testing/modules/AppInfo.jsm
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -15,18 +15,16 @@ interface nsICommandParams;
 interface nsIComponentManager;
 interface nsICycleCollectorListener;
 interface nsIDocumentEncoder;
 interface nsIEditorSpellCheck;
 interface nsIFile;
 interface nsILoadContext;
 interface nsIPersistentProperties;
 interface nsIURI;
-interface nsIJSCID;
-interface nsIJSIID;
 interface nsIPrincipal;
 interface nsIStackFrame;
 webidl Element;
 
 /**
 * interface of Components.interfacesByID
 * (interesting stuff only reflected into JavaScript)
 */
@@ -46,18 +44,16 @@ interface nsIXPCComponents_Interfaces : 
 
 /**
 * interface of Components.classes
 * (interesting stuff only reflected into JavaScript)
 */
 [scriptable, builtinclass, uuid(978ff520-d26c-11d2-9842-006008962422)]
 interface nsIXPCComponents_Classes : nsISupports
 {
-  // Make it so that |cid| gets mapped to |idString|.
-  void initialize(in nsIJSCID cid, in string idString);
 };
 
 /**
 * interface of Components.classesByID
 * (interesting stuff only reflected into JavaScript)
 */
 [scriptable, builtinclass, uuid(336a9590-4d19-11d3-9893-006008962422)]
 interface nsIXPCComponents_ClassesByID : nsISupports
--- a/js/xpconnect/idl/xpcjsid.idl
+++ b/js/xpconnect/idl/xpcjsid.idl
@@ -27,12 +27,15 @@ interface nsIJSID : nsISupports
 [builtinclass, scriptable, uuid(e76ec564-a080-4705-8609-384c755ec91e)]
 interface nsIJSIID : nsIJSID
 {
 };
 
 [builtinclass, scriptable, uuid(bf5eb086-9eaa-4694-aec3-fe4aac6119bd)]
 interface nsIJSCID : nsIJSID
 {
+    // re-generate the internal CID value from this nsIJSID's ContractID.
+    void refreshCID();
+
     [implicit_jscontext,optional_argc] jsval createInstance([optional] in jsval iid);
     [implicit_jscontext,optional_argc] jsval getService([optional] in jsval iid);
 };
 
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -672,23 +672,16 @@ nsXPCComponents_Classes::Resolve(nsIXPCo
                                                      JSPROP_RESOLVING);
                 }
             }
         }
     }
     return NS_OK;
 }
 
-NS_IMETHODIMP
-nsXPCComponents_Classes::Initialize(nsIJSCID* cid,
-                                    const char* str)
-{
-    return cid->Initialize(str);
-}
-
 
 /***************************************************************************/
 /***************************************************************************/
 /***************************************************************************/
 
 class nsXPCComponents_ClassesByID final :
   public nsIXPCComponents_ClassesByID,
   public nsIXPCScriptable,
--- a/js/xpconnect/src/XPCJSID.cpp
+++ b/js/xpconnect/src/XPCJSID.cpp
@@ -613,16 +613,28 @@ nsJSCID::NewID(const char* str)
 
     RefPtr<nsJSCID> idObj = new nsJSCID();
     if (NS_FAILED(idObj->Initialize(str))) {
         return nullptr;
     }
     return idObj.forget();
 }
 
+NS_IMETHODIMP
+nsJSCID::RefreshCID()
+{
+    char* name = nullptr;
+    nsresult rv = mDetails->GetName(&name);
+    if (NS_SUCCEEDED(rv)) {
+        rv = *name ? Initialize(name) : NS_ERROR_UNEXPECTED;
+    }
+    free(name);
+    return rv;
+}
+
 static Maybe<nsID>
 GetIIDArg(uint32_t argc, JS::HandleValue val, JSContext* cx)
 {
     // If an IID was passed in then use it
     if (argc) {
         return xpc::JSValue2ID(cx, val);
     }
     return Some(NS_GET_IID(nsISupports));
--- a/testing/modules/AppInfo.jsm
+++ b/testing/modules/AppInfo.jsm
@@ -107,34 +107,34 @@ var getAppInfo = function() { return cur
  *
  * To change the current XULAppInfo, simply call this function. If there was
  * a previously registered app info object, it will be unloaded and replaced.
  */
 var updateAppInfo = function(options) {
   currentAppInfo = newAppInfo(options);
 
   let id = Components.ID("{fbfae60b-64a4-44ef-a911-08ceb70b9f31}");
-  let cid = "@mozilla.org/xre/app-info;1";
+  let contractid = "@mozilla.org/xre/app-info;1";
   let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
 
   // Unregister an existing factory if one exists.
   try {
-    let existing = Components.manager.getClassObjectByContractID(cid, Ci.nsIFactory);
+    let existing = Components.manager.getClassObjectByContractID(contractid, Ci.nsIFactory);
     registrar.unregisterFactory(id, existing);
   } catch (ex) {}
 
   let factory = {
     createInstance(outer, iid) {
       if (outer != null) {
         throw Cr.NS_ERROR_NO_AGGREGATION;
       }
 
       return currentAppInfo.QueryInterface(iid);
     },
   };
 
-  registrar.registerFactory(id, "XULAppInfo", cid, factory);
+  registrar.registerFactory(id, "XULAppInfo", contractid, factory);
 
-  // Ensure that Cc actually maps cid to the new shim AppInfo. This is
-  // needed when JSM global sharing is enabled, because some prior
-  // code may already have looked up |Cc[cid]|.
-  Cc.initialize(Cc[cid], cid);
+  // Ensure that Cc actually maps contractid to the new shim AppInfo. This is
+  // needed when JSM global sharing is enabled, because some prior code may
+  // already have looked up |Cc[contractid]|.
+  Cc[contractid].refreshCID();
 };