diff --git a/common/modules/contexts.jsm b/common/modules/contexts.jsm index 7c3b72e3..f04968b3 100644 --- a/common/modules/contexts.jsm +++ b/common/modules/contexts.jsm @@ -151,9 +151,13 @@ var Contexts = Module("contexts", { for each (let hive in values(this.groupList.slice())) util.trapErrors("destroy", hive, "shutdown"); - for (let [name, plugin] in iter(this.modules.plugins.contexts)) + for each (let plugin in this.modules.plugins.contexts) { if (plugin && "onUnload" in plugin && callable(plugin.onUnload)) util.trapErrors("onUnload", plugin); + + if (isinstance(plugin, ["Sandbox"])) + util.trapErrors("nukeSandbox", Cu, plugin); + } }, signals: { diff --git a/common/modules/main.jsm b/common/modules/main.jsm index 7d9c8731..0547bda6 100644 --- a/common/modules/main.jsm +++ b/common/modules/main.jsm @@ -89,12 +89,30 @@ var Modules = function Modules(window) { Module.list = []; Module.constructors = {}; - const create = window.Object.create.bind(window.Object); + function newContext(proto, normal, name) { + if (normal) + return create(proto); + + sandbox = Components.utils.Sandbox(window, { sandboxPrototype: proto || modules, + sandboxName: name || ("Dactyl Sandbox " + ++_id), + wantXrays: false }); + + // Hack: + // sandbox.Object = jsmodules.Object; + sandbox.File = jsmodules.File; + sandbox.Math = jsmodules.Math; + sandbox.Set = jsmodules.Set; + return sandbox; + }; + const BASES = [BASE, "resource://dactyl-local-content/"]; - jsmodules = Cu.createObjectIn(window); + jsmodules = newContext(window, false, "Dactyl `jsmodules`"); jsmodules.NAME = "jsmodules"; + + const create = bind("create", jsmodules.Object); + const modules = update(create(jsmodules), { yes_i_know_i_should_not_report_errors_in_these_branches_thanks: [], @@ -130,21 +148,7 @@ var Modules = function Modules(window) { } }, - newContext: function newContext(proto, normal, name) { - if (normal) - return create(proto); - - sandbox = Components.utils.Sandbox(window, { sandboxPrototype: proto || modules, - sandboxName: name || ("Dactyl Sandbox " + ++_id), - wantXrays: false }); - - // Hack: - // sandbox.Object = jsmodules.Object; - sandbox.File = jsmodules.File; - sandbox.Math = jsmodules.Math; - sandbox.Set = jsmodules.Set; - return sandbox; - }, + newContext: newContext, get ownPropertyValues() array.compact( Object.getOwnPropertyNames(this) @@ -166,6 +170,7 @@ overlay.overlayWindow(Object.keys(config.overlays), const modules = Modules(window); modules.moduleManager = this; this.modules = modules; + this.jsmodules = modules.jsmodules; window.dactyl = { modules: modules }; @@ -225,6 +230,8 @@ overlay.overlayWindow(Object.keys(config.overlays), cleanup: function cleanup(window) { overlay.windows = overlay.windows.filter(w => w != window); + + Cu.nukeSandbox(this.jsmodules); }, unload: function unload(window) { diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index 057d6d5f..30bebda7 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -247,6 +247,11 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef if (!("value" in prop) || !callable(prop.value) && !(k in item)) Object.defineProperty(item, k, prop); + function getWindow(obj) { + obj = Class.objectGlobal(obj); + return obj.window || obj; + } + let names = RealSet([name].concat(params.contains || []).map(e => "clear-" + e)); if (params.action) storage.addObserver("sanitizer", @@ -254,7 +259,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef if (names.has(event)) params.action.apply(params, arg); }, - Class.objectGlobal(params.action)); + getWindow(params.action)); if (params.privateEnter || params.privateLeave) storage.addObserver("private-mode", @@ -263,7 +268,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef if (meth) meth.call(params); }, - Class.objectGlobal(params.action)); + getWindow(params.privateEnter || params.privateLeave)); }, observers: { diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 6cc704f0..b488a244 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -1,4 +1,4 @@ -// Copyright (c) 2008-2013 Kris Maglione +// Copyright (c) 2008-2014 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file.