Bug 1381919 - Remove most of the xpcIJSModuleLoader interface. r=kmag
authorAndrew McCreight <continuation@gmail.com>
Mon, 17 Jul 2017 17:11:06 -0700
changeset 418470 edca2b43880708121a7a4a5930ed4feee77de5a2
parent 418469 7eb11c4b0159a321d2f4b06b57336c507daea216
child 418471 5dbf26e7d92dff72f58a6cc8863d6f2dd8ba22de
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1381919
milestone56.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 1381919 - Remove most of the xpcIJSModuleLoader interface. r=kmag People only use these methods via Cu, so remove them from this interface. Also, ban anybody from implementing this interface in JS (though I can't imagine anybody trying), and eliminate a variant of mozJSComponentLoader::ImportInto that is never called. MozReview-Commit-ID: Kok5ksXiK5a
js/xpconnect/idl/xpcIJSModuleLoader.idl
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/loader/mozJSComponentLoader.cpp
js/xpconnect/loader/mozJSComponentLoader.h
js/xpconnect/src/XPCComponents.cpp
--- a/js/xpconnect/idl/xpcIJSModuleLoader.idl
+++ b/js/xpconnect/idl/xpcIJSModuleLoader.idl
@@ -1,90 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
-[ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext);
-
-%{C++
-#include "js/TypeDecls.h"
-
-class nsAXPCNativeCallContext;
-%}
-
-[ptr] native JSObjectPtr(JSObject);
-
-[scriptable, uuid(4f94b21f-2920-4bd9-8251-5fb60fb054b2)]
+[scriptable, builtinclass, uuid(4f94b21f-2920-4bd9-8251-5fb60fb054b2)]
 interface xpcIJSModuleLoader : nsISupports
 {
-  /**
-   * To be called from JavaScript only.
-   *
-   * Synchronously loads and evaluates the js file located at
-   * aResourceURI with a new, fully privileged global object.
-   *
-   * If 'targetObj' is specified and equal to null, returns the
-   * module's global object. Otherwise (if 'targetObj' is not
-   * specified, or 'targetObj' is != null) looks for a property
-   * 'EXPORTED_SYMBOLS' on the new global object. 'EXPORTED_SYMBOLS'
-   * is expected to be an array of strings identifying properties on
-   * the global object.  These properties will be installed as
-   * properties on 'targetObj', or, if 'targetObj' is not specified,
-   * on the caller's global object. If 'EXPORTED_SYMBOLS' is not
-   * found, an error is thrown.
-   *
-   * @param resourceURI A resource:// URI string to load the module from.
-   * @param targetObj  the object to install the exported properties on.
-   *        If this parameter is a primitive value, this method throws
-   *        an exception.
-   * @returns the module code's global object.
-   *
-   * The implementation maintains a hash of registryLocation->global obj.
-   * Subsequent invocations of importModule with 'registryLocation'
-   * pointing to the same file will not cause the module to be re-evaluated,
-   * but the symbols in EXPORTED_SYMBOLS will be exported into the
-   * specified target object and the global object returned as above.
-   *
-   * (This comment is duplicated to nsIXPCComponents_Utils.)
-   */
-  [implicit_jscontext,optional_argc]
-  jsval import(in AUTF8String aResourceURI, [optional] in jsval targetObj);
-
-  /**
-   * Imports the JS module at aResourceURI to the JS object
-   * 'targetObj' (if != null) as described for importModule() and
-   * returns the module's global object.
-   */
-  [noscript] JSObjectPtr importInto(in AUTF8String aResourceURI,
-                                    in JSObjectPtr targetObj,
-                                    in nsAXPCNativeCallContextPtr cc);
-
-  /**
-   * Unloads the JS module at aResourceURI. Existing references to the module
-   * will continue to work but any subsequent import of the module will
-   * reload it and give new reference. If the JS module hasn't yet been imported
-   * then this method will do nothing.
-   */
-  void unload(in AUTF8String aResourceURI);
-
-  /**
-   * Returns true if the js file located at 'registryLocation' location has
-   * been loaded previously via the import method above. Returns false
-   * otherwise.
-   *
-   * @param resourceURI A resource:// URI string representing the location of
-   *        the js file to be checked if it is already loaded or not.
-   * @returns boolean, true if the js file has been loaded via import. false
-   *          otherwise
-   */
-  boolean isModuleLoaded(in AUTF8String aResourceURI);
-
   // These 2 functions are for startup testing purposes. They are not expected
   // to be used for production code.
   void loadedModules([optional] out unsigned long length,
                      [retval, array, size_is(length)] out string aModules);
 
   void loadedComponents([optional] out unsigned long length,
                         [retval, array, size_is(length)] out string aComponents);
 };
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -221,18 +221,16 @@ interface nsIXPCComponents_Utils : nsISu
      *        an exception.
      * @returns the module code's global object.
      *
      * The implementation maintains a hash of registryLocation->global obj.
      * Subsequent invocations of importModule with 'registryLocation'
      * pointing to the same file will not cause the module to be re-evaluated,
      * but the symbols in EXPORTED_SYMBOLS will be exported into the
      * specified target object and the global object returned as above.
-     *
-     * (This comment is duplicated from xpcIJSModuleLoader.)
      */
     [implicit_jscontext,optional_argc]
     jsval import(in AUTF8String aResourceURI, [optional] in jsval targetObj);
 
     /**
      * Returns true if the js file located at 'registryLocation' location has
      * been loaded previously via the import method above. Returns false
      * otherwise.
--- a/js/xpconnect/loader/mozJSComponentLoader.cpp
+++ b/js/xpconnect/loader/mozJSComponentLoader.cpp
@@ -763,17 +763,17 @@ mozJSComponentLoader::UnloadModules()
     mImports.Clear();
 
     for (auto iter = mModules.Iter(); !iter.Done(); iter.Next()) {
         iter.Data()->Clear();
         iter.Remove();
     }
 }
 
-NS_IMETHODIMP
+nsresult
 mozJSComponentLoader::Import(const nsACString& registryLocation,
                              HandleValue targetValArg,
                              JSContext* cx,
                              uint8_t optionalArgc,
                              MutableHandleValue retval)
 {
     MOZ_ASSERT(nsContentUtils::IsCallerChrome());
 
@@ -818,35 +818,17 @@ mozJSComponentLoader::Import(const nsACS
             return NS_ERROR_FAILURE;
         }
 
         retval.setObject(*global);
     }
     return rv;
 }
 
-NS_IMETHODIMP
-mozJSComponentLoader::ImportInto(const nsACString& aLocation,
-                                 JSObject* aTargetObj,
-                                 nsAXPCNativeCallContext* cc,
-                                 JSObject** _retval)
-{
-    JSContext* callercx;
-    nsresult rv = cc->GetJSContext(&callercx);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    RootedObject targetObject(callercx, aTargetObj);
-    RootedObject global(callercx);
-    rv = ImportInto(aLocation, targetObject, callercx, &global);
-    NS_ENSURE_SUCCESS(rv, rv);
-    *_retval = global;
-    return NS_OK;
-}
-
-NS_IMETHODIMP
+nsresult
 mozJSComponentLoader::IsModuleLoaded(const nsACString& aLocation,
                                      bool* retval)
 {
     MOZ_ASSERT(nsContentUtils::IsCallerChrome());
 
     nsresult rv;
     if (!mInitialized) {
         rv = ReallyInit();
@@ -1111,17 +1093,17 @@ mozJSComponentLoader::ImportInto(const n
     if (newEntry) {
         mImports.Put(info.Key(), newEntry);
         newEntry.forget();
     }
 
     return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 mozJSComponentLoader::Unload(const nsACString & aLocation)
 {
     nsresult rv;
 
     if (!mInitialized) {
         return NS_OK;
     }
 
--- a/js/xpconnect/loader/mozJSComponentLoader.h
+++ b/js/xpconnect/loader/mozJSComponentLoader.h
@@ -47,16 +47,21 @@ class mozJSComponentLoader : public mozi
     // ModuleLoader
     const mozilla::Module* LoadModule(mozilla::FileLocation& aFile) override;
 
     void FindTargetObject(JSContext* aCx,
                           JS::MutableHandleObject aTargetObject);
 
     static mozJSComponentLoader* Get() { return sSelf; }
 
+    nsresult Import(const nsACString& aResourceURI, JS::HandleValue aTargetObj,
+                    JSContext* aCx, uint8_t aArgc, JS::MutableHandleValue aRetval);
+    nsresult Unload(const nsACString& aResourceURI);
+    nsresult IsModuleLoaded(const nsACString& aResourceURI, bool* aRetval);
+
     size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
 
  protected:
     virtual ~mozJSComponentLoader();
 
     static mozJSComponentLoader* sSelf;
 
     nsresult ReallyInit();
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3,17 +3,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* The "Components" xpcom objects for JavaScript. */
 
 #include "xpcprivate.h"
 #include "xpc_make_class.h"
-#include "xpcIJSModuleLoader.h"
 #include "XPCJSWeakReference.h"
 #include "WrapperFactory.h"
 #include "nsJSUtils.h"
 #include "mozJSComponentLoader.h"
 #include "nsContentUtils.h"
 #include "nsCycleCollector.h"
 #include "jsfriendapi.h"
 #include "js/StructuredClone.h"
@@ -2491,45 +2490,39 @@ nsXPCComponents_Utils::SetSandboxMetadat
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::Import(const nsACString& registryLocation,
                               HandleValue targetObj,
                               JSContext* cx,
                               uint8_t optionalArgc,
                               MutableHandleValue retval)
 {
-    nsCOMPtr<xpcIJSModuleLoader> moduleloader =
-        do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
-    if (!moduleloader)
-        return NS_ERROR_FAILURE;
+    RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
+    MOZ_ASSERT(moduleloader);
 
     const nsCString& flatLocation = PromiseFlatCString(registryLocation);
     AUTO_PROFILER_LABEL_DYNAMIC("nsXPCComponents_Utils::Import", OTHER,
                                 flatLocation.get());
 
     return moduleloader->Import(registryLocation, targetObj, cx, optionalArgc, retval);
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::IsModuleLoaded(const nsACString& registryLocation, bool* retval)
 {
-    nsCOMPtr<xpcIJSModuleLoader> moduleloader =
-        do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
-    if (!moduleloader)
-        return NS_ERROR_FAILURE;
+    RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
+    MOZ_ASSERT(moduleloader);
     return moduleloader->IsModuleLoaded(registryLocation, retval);
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::Unload(const nsACString & registryLocation)
 {
-    nsCOMPtr<xpcIJSModuleLoader> moduleloader =
-        do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
-    if (!moduleloader)
-        return NS_ERROR_FAILURE;
+    RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
+    MOZ_ASSERT(moduleloader);
     return moduleloader->Unload(registryLocation);
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::ImportGlobalProperties(HandleValue aPropertyList,
                                               JSContext* cx)
 {
     RootedObject global(cx, CurrentGlobalOrNull(cx));