Bug 1392602 - Remove `override` helper in DevTools loader. r=jdescottes draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 28 Aug 2017 14:05:37 +0200
changeset 658608 74e9d76a9f3357033cafdac573a35dcac4144f6e
parent 658607 3ed4742d60de7d8911b21e3b094f1d3cc1ccf67e
child 658609 ac2966a54df65038223bd4860e4ab4e359064a06
push id77824
push userbmo:poirot.alex@gmail.com
push dateMon, 04 Sep 2017 12:19:59 +0000
reviewersjdescottes
bugs1392602
milestone57.0a1
Bug 1392602 - Remove `override` helper in DevTools loader. r=jdescottes MozReview-Commit-ID: E2dNIMoa2wz Also get rid of shared global blocklist as this isn't used by DevTools.
devtools/shared/Loader.jsm
devtools/shared/base-loader.js
--- a/devtools/shared/Loader.jsm
+++ b/devtools/shared/Loader.jsm
@@ -68,17 +68,16 @@ BuiltinProvider.prototype = {
     if (this.invisibleToDebugger) {
       paths.promise = "resource://gre/modules/Promise-backend.js";
     }
     this.loader = new Loader({
       id: "fx-devtools",
       paths,
       invisibleToDebugger: this.invisibleToDebugger,
       sharedGlobal: true,
-      sharedGlobalBlocklist: [],
       sandboxName: "DevTools (Module loader)",
       noSandboxAddonId: true,
       requireHook: (id, require) => {
         if (id.startsWith("raw!")) {
           return requireRawId(id, require);
         }
         return require(id);
       },
--- a/devtools/shared/base-loader.js
+++ b/devtools/shared/base-loader.js
@@ -48,30 +48,16 @@ const COMPONENT_ERROR = '`Components` is
 // Returns map of given `object`-s own property descriptors.
 const descriptor = function descriptor(object) {
   let value = {};
   for (let name of getOwnIdentifiers(object))
     value[name] = getOwnPropertyDescriptor(object, name)
   return value;
 };
 
-// Defines own properties of given `properties` object on the given
-// target object overriding any existing property with a conflicting name.
-// Returns `target` object. Note we only export this function because it's
-// useful during loader bootstrap when other util modules can't be used &
-// thats only case where this export should be used.
-const override = function override(target, source) {
-  let properties = descriptor(target);
-
-  for (let name of getOwnIdentifiers(source || {}))
-    properties[name] = getOwnPropertyDescriptor(source, name);
-
-  return Object.defineProperties({}, properties);
-};
-
 function sourceURI(uri) { return String(uri).split(" -> ").pop(); }
 
 function isntLoaderFrame(frame) { return frame.fileName !== __URI__ }
 
 function parseURI(uri) { return String(uri).split(" -> ").pop(); }
 
 function parseStack(stack) {
   let lines = String(stack).split("\n");
@@ -160,18 +146,16 @@ const Sandbox = function Sandbox(options
   // Normalize options and rename to match `Cu.Sandbox` expectations.
   options = {
     // Do not expose `Components` if you really need them (bad idea!) you
     // still can expose via prototype.
     wantComponents: false,
     sandboxName: options.name,
     principal: 'principal' in options ? options.principal : systemPrincipal,
     wantXrays: 'wantXrays' in options ? options.wantXrays : true,
-    wantGlobalProperties: 'wantGlobalProperties' in options ?
-                          options.wantGlobalProperties : [],
     sandboxPrototype: 'prototype' in options ? options.prototype : {},
     invisibleToDebugger: 'invisibleToDebugger' in options ?
                          options.invisibleToDebugger : false,
     metadata: 'metadata' in options ? options.metadata : {},
     waiveIntereposition: !!options.waiveIntereposition
   };
 
   if (options.metadata && options.metadata.addonID) {
@@ -207,18 +191,17 @@ const load = function load(loader, modul
     get Components() {
       // Expose `Components` property to throw error on usage with
       // additional information
       throw new ReferenceError(COMPONENT_ERROR);
     }
   });
 
   let sandbox;
-  if ((loader.useSharedGlobalSandbox || isSystemURI(module.uri)) &&
-      loader.sharedGlobalBlocklist.indexOf(module.id) == -1) {
+  if (loader.useSharedGlobalSandbox || isSystemURI(module.uri)) {
     // Create a new object in this sandbox, that will be used as
     // the scope object for this particular module
     sandbox = new loader.sharedGlobalSandbox.Object();
     descriptors.lazyRequire = {
       configurable: true,
       value: lazyRequire.bind(sandbox),
     };
     descriptors.lazyRequireModule = {
@@ -241,17 +224,16 @@ const load = function load(loader, modul
       descriptors.DOMParser = Object.getOwnPropertyDescriptor(globals, "DOMParser");
     Object.defineProperties(sandbox, descriptors);
   }
   else {
     sandbox = Sandbox({
       name: module.uri,
       prototype: Object.create(globals, descriptors),
       wantXrays: false,
-      wantGlobalProperties: module.id == "sdk/indexed-db" ? ["indexedDB"] : [],
       invisibleToDebugger: loader.invisibleToDebugger,
       metadata: {
         addonID: loader.id,
         URI: module.uri
       }
     });
   }
   sandboxes[module.uri] = sandbox;
@@ -622,78 +604,42 @@ const unload = function unload(loader, r
 //   module object (that has `uri` property) and `baseURI` of the loader.
 //   If `resolve` does not returns `uri` string exception will be thrown by
 //   an associated `require` call.
 function Loader(options) {
   function normalizeRootURI(uri) {
     return addTrailingSlash(join(uri));
   }
 
-  if (options.sharedGlobalBlacklist && !options.sharedGlobalBlocklist) {
-    options.sharedGlobalBlocklist = options.sharedGlobalBlacklist;
-  }
-  let {
-    modules, globals, resolve, paths, rootURI, manifest, isNative,
-    metadata, sharedGlobal, sharedGlobalBlocklist, checkCompatibility, waiveIntereposition
-  } = override({
-    paths: {},
-    modules: {},
-    globals: {
-      get console() {
-        // Import Console.jsm from here to prevent loading it until someone uses it
-        let { ConsoleAPI } = Cu.import("resource://gre/modules/Console.jsm");
-        let console = new ConsoleAPI({
-          consoleID: options.id ? "addon/" + options.id : ""
-        });
-        Object.defineProperty(this, "console", { value: console });
-        return this.console;
-      }
-    },
-    checkCompatibility: false,
-    resolve: options.isNative ?
-      // Make the returned resolve function have the same signature
-      (id, requirer) => nodeResolve(id, requirer, { rootURI: normalizeRootURI(rootURI) }) :
-      resolve,
-    sharedGlobalBlocklist: ["sdk/indexed-db"],
-    waiveIntereposition: false
-  }, options);
-
-  // Create overrides defaults, none at the moment
-  if (typeof manifest != "object" || !manifest) {
-    manifest = {};
-  }
-  if (typeof manifest.jetpack != "object" || !manifest.jetpack) {
-    manifest.jetpack = {
-      overrides: {}
-    };
-  }
-  if (typeof manifest.jetpack.overrides != "object" || !manifest.jetpack.overrides) {
-    manifest.jetpack.overrides = {};
+  let { paths, sharedGlobal, globals } = options;
+  let resolve = Loader.resolve;
+  if (!globals) {
+    globals = {};
   }
 
   // We create an identity object that will be dispatched on an unload
   // event as subject. This way unload listeners will be able to assert
   // which loader is unloaded. Please note that we intentionally don't
   // use `loader` as subject to prevent a loader access leakage through
   // observer notifications.
   let destructor = Object.create(null);
 
   let mapping = compileMapping(paths);
 
   // Define pseudo modules.
-  modules = override({
+  let modules = {
     '@loader/unload': destructor,
     '@loader/options': options,
     'chrome': { Cc: Cc, Ci: Ci, Cu: Cu, Cr: Cr, Cm: Cm,
                 CC: bind(CC, Components), components: Components,
                 // `ChromeWorker` has to be inject in loader global scope.
                 // It is done by bootstrap.js:loadSandbox for the SDK.
                 ChromeWorker: ChromeWorker
     }
-  }, modules);
+  };
 
   const builtinModuleExports = modules;
   modules = {};
   for (let id of Object.keys(builtinModuleExports)) {
     // We resolve `uri` from `id` since modules are cached by `uri`.
     let uri = resolveURI(id, mapping);
     let module = Module(id, uri);
 
@@ -711,17 +657,16 @@ function Loader(options) {
 
   // Create the unique sandbox we will be using for all modules,
   // so that we prevent creating a new comportment per module.
   // The side effect is that all modules will share the same
   // global objects.
   let sharedGlobalSandbox = Sandbox({
     name: options.sandboxName || "Addon-SDK",
     wantXrays: false,
-    wantGlobalProperties: [],
     invisibleToDebugger: options.invisibleToDebugger || false,
     metadata: {
       addonID: options.noSandboxAddonId ? undefined : options.id,
       URI: options.sandboxName || "Addon-SDK"
     },
     prototype: options.sandboxPrototype || globals,
   });
 
@@ -741,18 +686,16 @@ function Loader(options) {
     destructor: { enumerable: false, value: destructor },
     globals: { enumerable: false, value: globals },
     mapping: { enumerable: false, value: mapping },
     mappingCache: { enumerable: false, value: new Map() },
     // Map of module objects indexed by module URIs.
     modules: { enumerable: false, value: modules },
     useSharedGlobalSandbox: { enumerable: false, value: !!sharedGlobal },
     sharedGlobalSandbox: { enumerable: false, value: sharedGlobalSandbox },
-    sharedGlobalBlocklist: { enumerable: false, value: sharedGlobalBlocklist },
-    sharedGlobalBlacklist: { enumerable: false, value: sharedGlobalBlocklist },
     // Map of module sandboxes indexed by module URIs.
     sandboxes: { enumerable: false, value: {} },
     resolve: { enumerable: false, value: resolve },
     // ID of the addon, if provided.
     id: { enumerable: false, value: options.id },
     // Whether the modules loaded should be ignored by the debugger
     invisibleToDebugger: { enumerable: false,
                            value: options.invisibleToDebugger || false },