Backed out changeset 3b275d92b419 (bug 1381919) for 32-bit windows build bustage a=backout CLOSED TREE
authorWes Kocher <wkocher@mozilla.com>
Tue, 18 Jul 2017 22:37:01 -0700
changeset 418252 a4e7af47aa3a1de0d2c79dec6512963ee37c177a
parent 418251 085578e7f1a3d34e32729673a10c3c1aad991ecf
child 418253 1aa1c1bd2a658856e1a906e789f9d771730e1070
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)
reviewersbackout
bugs1381919
milestone56.0a1
backs out3b275d92b419ae94add9552542d674ab0b309d0b
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
Backed out changeset 3b275d92b419 (bug 1381919) for 32-bit windows build bustage a=backout CLOSED TREE MozReview-Commit-ID: AeocWzkRyan
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,18 +1,90 @@
 /* -*- 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"
 
-[scriptable, builtinclass, uuid(4f94b21f-2920-4bd9-8251-5fb60fb054b2)]
+[ptr] native nsAXPCNativeCallContextPtr(nsAXPCNativeCallContext);
+
+%{C++
+#include "js/TypeDecls.h"
+
+class nsAXPCNativeCallContext;
+%}
+
+[ptr] native JSObjectPtr(JSObject);
+
+[scriptable, 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,16 +221,18 @@ 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
@@ -819,16 +819,34 @@ mozJSComponentLoader::Import(const nsACS
         }
 
         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
 mozJSComponentLoader::IsModuleLoaded(const nsACString& aLocation,
                                      bool* retval)
 {
     MOZ_ASSERT(nsContentUtils::IsCallerChrome());
 
     nsresult rv;
     if (!mInitialized) {
         rv = ReallyInit();
--- a/js/xpconnect/loader/mozJSComponentLoader.h
+++ b/js/xpconnect/loader/mozJSComponentLoader.h
@@ -47,21 +47,16 @@ 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,16 +3,17 @@
 /* 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"
@@ -2490,39 +2491,45 @@ nsXPCComponents_Utils::SetSandboxMetadat
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::Import(const nsACString& registryLocation,
                               HandleValue targetObj,
                               JSContext* cx,
                               uint8_t optionalArgc,
                               MutableHandleValue retval)
 {
-    RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
-    MOZ_ASSERT(moduleloader);
+    nsCOMPtr<xpcIJSModuleLoader> moduleloader =
+        do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
+    if (!moduleloader)
+        return NS_ERROR_FAILURE;
 
     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)
 {
-    RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
-    MOZ_ASSERT(moduleloader);
+    nsCOMPtr<xpcIJSModuleLoader> moduleloader =
+        do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
+    if (!moduleloader)
+        return NS_ERROR_FAILURE;
     return moduleloader->IsModuleLoaded(registryLocation, retval);
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::Unload(const nsACString & registryLocation)
 {
-    RefPtr<mozJSComponentLoader> moduleloader = mozJSComponentLoader::Get();
-    MOZ_ASSERT(moduleloader);
+    nsCOMPtr<xpcIJSModuleLoader> moduleloader =
+        do_GetService(MOZJSCOMPONENTLOADER_CONTRACTID);
+    if (!moduleloader)
+        return NS_ERROR_FAILURE;
     return moduleloader->Unload(registryLocation);
 }
 
 NS_IMETHODIMP
 nsXPCComponents_Utils::ImportGlobalProperties(HandleValue aPropertyList,
                                               JSContext* cx)
 {
     RootedObject global(cx, CurrentGlobalOrNull(cx));