]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/io.jsm
Imported Upstream version 1.1+hg7904
[dactyl.git] / common / modules / io.jsm
index 4a61d67313b74d7e1c3a2092a44ef7ea027c1125..9de045500a4f2a7b9202335847ed0bce541faa35 100644 (file)
@@ -1,7 +1,6 @@
 // Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
 // Copyright (c) 2007-2012 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
-// Some code based on Venkman
+// Copyright (c) 2008-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.
@@ -16,6 +15,7 @@ defineModule("io", {
 
 lazyRequire("config", ["config"]);
 lazyRequire("contexts", ["Contexts", "contexts"]);
+lazyRequire("promises", ["Promise"]);
 lazyRequire("storage", ["File", "storage"]);
 lazyRequire("styles", ["styles"]);
 lazyRequire("template", ["template"]);
@@ -42,7 +42,7 @@ var IO = Module("io", {
             this._oldcwd = null;
 
             this._lastRunCommand = ""; // updated whenever the users runs a command with :!
-            this._scriptNames = [];
+            this._scriptNames = RealSet();
         },
 
         CommandFileMode: Class("CommandFileMode", modules.CommandMode, {
@@ -156,7 +156,7 @@ var IO = Module("io", {
                     else if (/\.js$/.test(filename)) {
                         try {
                             var context = contexts.Script(file, params.group);
-                            if (Set.has(this._scriptNames, file.path))
+                            if (this._scriptNames.has(file.path))
                                 util.flushCache();
 
                             dactyl.loadScript(uri.spec, context);
@@ -196,7 +196,7 @@ var IO = Module("io", {
                         dactyl.triggerObserver("io.source", context, file, file.lastModifiedTime);
                     }
 
-                    Set.add(this._scriptNames, file.path);
+                    this._scriptNames.add(file.path);
 
                     dactyl.echomsg(_("io.sourcingEnd", filename.quote()), 2);
                     dactyl.log(_("dactyl.sourced", filename), 3);
@@ -319,7 +319,7 @@ var IO = Module("io", {
      *     @default ""
      * @returns {File}
      */
-    createTempFile: function createTempFile(ext = "txt", label = "") {
+    createTempFile: function createTempFile(ext="txt", label="") {
         let file = services.directory.get("TmpD", Ci.nsIFile);
         file.append(config.name + label + "." + ext);
         file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
@@ -447,26 +447,29 @@ var IO = Module("io", {
 
         let process = services.Process(file.file);
         process.run(false, args.map(String), args.length);
-        try {
-            if (callable(blocking))
-                var timer = services.Timer(
-                    function () {
-                        if (!process.isRunning) {
-                            timer.cancel();
-                            util.trapErrors(blocking, self, process.exitValue);
-                        }
-                    },
-                    100, services.Timer.TYPE_REPEATING_SLACK);
-            else if (blocking)
-                while (process.isRunning)
-                    util.threadYield(false, true);
-        }
-        catch (e) {
-            process.kill();
-            throw e;
+
+        let deferred = Promise.defer();
+
+        if (callable(blocking))
+            // Deprecated.
+            deferred.promise.then(blocking);
+        else if (blocking) {
+            // Deprecated?
+            while (process.isRunning)
+                util.threadYield(false, true);
+            return process.exitValue;
         }
 
-        return process.exitValue;
+        let timer = services.Timer(
+            function () {
+                if (!process.isRunning) {
+                    timer.cancel();
+                    deferred.resolve(process.exitValue);
+                }
+            },
+            100, services.Timer.TYPE_REPEATING_SLACK);
+
+        return deferred.promise;
     },
 
     // TODO: when https://bugzilla.mozilla.org/show_bug.cgi?id=68702 is
@@ -486,7 +489,7 @@ var IO = Module("io", {
     system: function system(command, input, callback) {
         util.dactyl.echomsg(_("io.callingShell", command), 4);
 
-        let { shellEscape } = util.closure;
+        let { shellEscape } = util.bound;
 
         return this.withTempFiles(function (stdin, stdout, cmd) {
             if (input instanceof File)
@@ -865,7 +868,7 @@ unlet s:cpo_save
         commands.add(["scrip[tnames]"],
             "List all sourced script names",
             function () {
-                let names = Object.keys(io._scriptNames);
+                let names = [k for (k of io._scriptNames)];
                 if (!names.length)
                     dactyl.echomsg(_("command.scriptnames.none"));
                 else