]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/contexts.jsm
Imported Upstream version 1.1+hg7904
[dactyl.git] / common / modules / contexts.jsm
index 3c0ca3a94c39ea4ee79ae07addef934043fe1862..2a6e46ddf9c257cf84065121047074928aa0e56d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (c) 2010-2013 Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2010-2014 Kris Maglione <maglione.k@gmail.com>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
@@ -43,14 +43,14 @@ var Group = Class("Group", {
             delete this[hive];
 
         if (reason != "shutdown")
-            this.children.splice(0).forEach(this.contexts.closure.removeGroup);
+            this.children.splice(0).forEach(this.contexts.bound.removeGroup);
     },
     destroy: function destroy(reason) {
         for (let hive in values(this.hives))
             util.trapErrors("destroy", hive);
 
         if (reason != "shutdown")
-            this.children.splice(0).forEach(this.contexts.closure.removeGroup);
+            this.children.splice(0).forEach(this.contexts.bound.removeGroup);
     },
 
     argsExtra: function argsExtra() ({}),
@@ -67,8 +67,9 @@ var Group = Class("Group", {
 }, {
     compileFilter: function (patterns, default_=false) {
         function siteFilter(uri)
-            let (match = array.nth(siteFilter.filters, f => f(uri), 0))
-                match ? match.result : default_;
+            let (match = siteFilter.filters.find(f => f(uri)))
+                match ? match.result
+                      : default_;
 
         return update(siteFilter, {
             toString: function () this.filters.join(","),
@@ -138,22 +139,26 @@ var Contexts = Module("contexts", {
                 completer: function (context) modules.completion.group(context)
             });
 
-            memoize(modules, "userContext",  () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, true]));
-            memoize(modules, "_userContext", () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules.userContext]));
+            memoize(modules, "userContext",  () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, false]));
+            memoize(modules, "_userContext", () => modules.userContext);
         },
 
         cleanup: function () {
-            for each (let hive in this.groupList.slice())
+            for (let hive of this.groupList.slice())
                 util.trapErrors("cleanup", hive, "shutdown");
         },
 
         destroy: function () {
-            for each (let hive in values(this.groupList.slice()))
+            for (let hive of 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: {
@@ -189,7 +194,9 @@ var Contexts = Module("contexts", {
                                                           { _hive: { value: name } })));
 
                 memoize(contexts.groupsProto, name,
-                        function () [group[name] for (group in values(this.groups)) if (Set.has(group, name))]);
+                        function () [group[name]
+                                     for (group in values(this.groups))
+                                     if (hasOwnProperty(group, name))]);
             },
 
             get toStringParams() [this.name, this.Hive]
@@ -199,25 +206,23 @@ var Contexts = Module("contexts", {
     Context: function Context(file, group, args) {
         const { contexts, io, newContext, plugins, userContext } = this.modules;
 
-        let isPlugin  = array.nth(io.getRuntimeDirectories("plugins"),
-                                  dir => dir.contains(file, true),
-                                  0);
-        let isRuntime = array.nth(io.getRuntimeDirectories(""),
-                                  dir => dir.contains(file, true),
-                                  0);
+        let isPlugin  = io.getRuntimeDirectories("plugins")
+                          .find(dir => dir.contains(file, true));
+        let isRuntime = io.getRuntimeDirectories("")
+                          .find(dir => dir.contains(file, true));
 
         let name = isPlugin ? file.getRelativeDescriptor(isPlugin).replace(File.PATH_SEP, "-")
                             : file.leafName;
         let id   = util.camelCase(name.replace(/\.[^.]*$/, ""));
 
         let contextPath = file.path;
-        let self = Set.has(plugins, contextPath) && plugins.contexts[contextPath];
+        let self = hasOwnProperty(plugins, contextPath) && plugins.contexts[contextPath];
 
         if (!self && isPlugin && false)
-            self = Set.has(plugins, id) && plugins[id];
+            self = hasOwnProperty(plugins, id) && plugins[id];
 
         if (self) {
-            if (Set.has(self, "onUnload"))
+            if (hasOwnProperty(self, "onUnload"))
                 util.trapErrors("onUnload", self);
         }
         else {
@@ -302,15 +307,14 @@ var Contexts = Module("contexts", {
         if (uri instanceof Ci.nsIFileURL)
             var file = File(uri.file);
 
-        let isPlugin = array.nth(io.getRuntimeDirectories("plugins"),
-                                 dir => dir.contains(file, true),
-                                 0);
+        let isPlugin = io.getRuntimeDirectories("plugins")
+                         .find(dir => dir.contains(file, true));
 
         let name = isPlugin && file && file.getRelativeDescriptor(isPlugin)
                                            .replace(File.PATH_SEP, "-");
         let id   = util.camelCase(name.replace(/\.[^.]*$/, ""));
 
-        let self = Set.has(this.pluginModules, canonical) && this.pluginModules[canonical];
+        let self = hasOwnProperty(this.pluginModules, canonical) && this.pluginModules[canonical];
 
         if (!self) {
             self = Object.create(jsmodules);
@@ -336,7 +340,7 @@ var Contexts = Module("contexts", {
                         delete contexts.pluginModules[canonical];
                     }
 
-                    for each (let { plugins } in overlay.modules)
+                    for (let { plugins } of overlay.modules)
                         if (plugins[this.NAME] == this)
                             delete plugins[this.name];
                 })
@@ -411,7 +415,7 @@ var Contexts = Module("contexts", {
 
     initializedGroups: function (hive)
         let (need = hive ? [hive] : Object.keys(this.hives))
-            this.groupList.filter(group => need.some(Set.has(group))),
+            this.groupList.filter(group => need.some(hasOwnProperty.bind(null, group))),
 
     addGroup: function addGroup(name, description, filter, persist, replace) {
         let group = this.getGroup(name);
@@ -468,7 +472,7 @@ var Contexts = Module("contexts", {
     getGroup: function getGroup(name, hive) {
         if (name === "default")
             var group = this.context && this.context.context && this.context.context.GROUP;
-        else if (Set.has(this.groupMap, name))
+        else if (hasOwnProperty(this.groupMap, name))
             group = this.groupMap[name];
 
         if (group && hive)
@@ -478,14 +482,8 @@ var Contexts = Module("contexts", {
 
     getDocs: function getDocs(context) {
         try {
-            if (isinstance(context, ["Sandbox"])) {
-                let info = "INFO" in context && Cu.evalInSandbox("this.INFO instanceof XML ? INFO.toXMLString() : this.INFO", context);
-                return /^</.test(info) ? XML(info) : info;
-            }
             if (DOM.isJSONXML(context.INFO))
                 return context.INFO;
-            if (typeof context.INFO == "xml" && config.haveGecko(null, "14.*"))
-                return context.INFO;
         }
         catch (e) {}
         return null;
@@ -644,7 +642,7 @@ var Contexts = Module("contexts", {
 
                 util.assert(!group.builtin ||
                                 !["-description", "-locations", "-nopersist"]
-                                    .some(Set.has(args.explicitOpts)),
+                                    .some(hasOwnProperty.bind(null, args.explicitOpts)),
                             _("group.cantModifyBuiltin"));
             },
             {