Skip to content

Instantly share code, notes, and snippets.

@ochameau
Created November 15, 2018 18:22
Show Gist options
  • Save ochameau/cc7ed92883115ab868e141c1d10001d5 to your computer and use it in GitHub Desktop.
Save ochameau/cc7ed92883115ab868e141c1d10001d5 to your computer and use it in GitHub Desktop.
use document global/compartment for browser loader modules
diff --git a/devtools/shared/base-loader.js b/devtools/shared/base-loader.js
index 4fde5d7d7fa1..455e86ee2f42 100644
--- a/devtools/shared/base-loader.js
+++ b/devtools/shared/base-loader.js
@@ -198,23 +198,15 @@ function load(loader, module) {
configurable: true,
value: lazyRequireModule.bind(sandbox),
};
+ Object.defineProperties(sandbox, descriptors);
- if ("console" in globals) {
- descriptors.console = {
- configurable: true,
- get() {
- return globals.console;
- },
- };
- }
- const define = Object.getOwnPropertyDescriptor(globals, "define");
- if (define && define.value) {
- descriptors.define = define;
- }
- if ("DOMParser" in globals) {
- descriptors.DOMParser = Object.getOwnPropertyDescriptor(globals, "DOMParser");
+ // I don't know why, but we no longer inherit globals from the global object
:
+ // if sharedGlobalSandbox is a window object instead of a Sandbox.
+ // So ensure that we do expose all devtools global to the sandbo
+ for (const name of getOwnIdentifiers(globals)) {
+ Object.defineProperty(sandbox, name,
+ Object.getOwnPropertyDescriptor(globals, name));
}
- Object.defineProperties(sandbox, descriptors);
} else {
sandbox = Sandbox({
name: module.uri,
@@ -639,20 +631,16 @@ function Loader(options) {
// so that we prevent creating a new compartment per module.
// The side effect is that all modules will share the same
// global objects.
- const sharedGlobalSandbox = Sandbox({
+ let sharedGlobalSandbox = Sandbox({
name: options.sandboxName || "DevTools",
invisibleToDebugger: options.invisibleToDebugger || false,
prototype: options.sandboxPrototype || globals,
});
if (options.sandboxPrototype) {
- // If we were given a sandboxPrototype, we have to define the globals on
- // the sandbox directly. Note that this will not work for callers who
- // depend on being able to add globals after the loader was created.
- for (const name of getOwnIdentifiers(globals)) {
- Object.defineProperty(sharedGlobalSandbox, name,
- Object.getOwnPropertyDescriptor(globals, name));
- }
+ // sandboxPrototype is the window object per browser-loader.js
+ // this is only used by browser-loader
+ sharedGlobalSandbox = options.sandboxPrototype;
}
// Loader object is just a representation of a environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment