diff options
author | Kris Maglione <maglione.k@gmail.com> | 2011-08-10 00:00:39 -0400 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2011-08-10 00:00:39 -0400 |
commit | f58f70fd9822403e2fc096cfb38758172ac47544 (patch) | |
tree | a31bb58ba4e09761cb9dcc9f29ad82a2df3427e9 | |
parent | 9bdb4411af9a82be50e5fe6edcb1358ed0a26041 (diff) | |
download | pentadactyl-f58f70fd9822403e2fc096cfb38758172ac47544.tar.gz |
Allow asynchronous io.system() calls. Fix :help intro.
-rw-r--r-- | common/content/dactyl.js | 2 | ||||
-rw-r--r-- | common/modules/base.jsm | 2 | ||||
-rw-r--r-- | common/modules/io.jsm | 42 |
3 files changed, 29 insertions, 17 deletions
diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 7e338642..0b4c5d38 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -2170,7 +2170,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { if (localPrefs.get("first-run", true)) dactyl.timeout(function () { - localPrefs.set("first-run", config.version); + localPrefs.set("first-run", false); this.withSavedValues(["forceNewTab"], function () { this.forceNewTab = true; this.help(); diff --git a/common/modules/base.jsm b/common/modules/base.jsm index ae8db7d1..30988035 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -616,6 +616,8 @@ function memoize(obj, key, getter) { let get = __lookupGetter__.call(obj, prop); if (get) memoize(res, prop, get); + else if (obj[prop] instanceof Class.Property) + Object.defineProperty(res, prop, obj[prop].init(prop, obj) || obj[prop]); } return res; } diff --git a/common/modules/io.jsm b/common/modules/io.jsm index 9b22b528..59eb8d98 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -427,7 +427,7 @@ var IO = Module("io", { * @param {File|string} program The program to run. * @param {[string]} args An array of arguments to pass to *program*. */ - run: function (program, args, blocking) { + run: function (program, args, blocking, self) { args = args || []; let file = this.pathSearch(program); @@ -447,7 +447,7 @@ var IO = Module("io", { function () { if (!process.isRunning) { timer.cancel(); - util.trapErrors(blocking); + util.trapErrors(blocking, self, process.exitValue); } }, 100, services.Timer.TYPE_REPEATING_SLACK); @@ -471,12 +471,14 @@ var IO = Module("io", { * * @param {string} command The command to run. * @param {string} input Any input to be provided to the command on stdin. - * @returns {object} + * @param {function(object)} callback A callback to be called when + * the command completes. @optional + * @returns {object|null} */ - system: function (command, input) { + system: function (command, input, callback) { util.dactyl.echomsg(_("io.callingShell", command), 4); - function escape(str) '"' + str.replace(/[\\"$]/g, "\\$&") + '"'; + function escape(str) '"' + String.replace(str, /[\\"$]/g, "\\$&") + '"'; return this.withTempFiles(function (stdin, stdout, cmd) { if (input instanceof File) @@ -484,6 +486,20 @@ var IO = Module("io", { else if (input) stdin.write(input); + function result(status, output) ({ + __noSuchMethod__: function (meth, args) this.output[meth].apply(this.output, args), + valueOf: function () this.output, + output: output.replace(/^(.*)\n$/, "$1"), + returnValue: status, + toString: function () this.output + }); + + function async(status) { + let output = stdout.read(); + [stdin, stdout, cmd].forEach(function (f) f.exists() && f.remove(false)); + callback(result(status, output)); + } + let shell = io.pathSearch(storage["options"].get("shell").value); let shcf = storage["options"].get("shellcmdflag").value; util.assert(shell, _("error.invalid", "'shell'")); @@ -494,23 +510,17 @@ var IO = Module("io", { // TODO: implement 'shellredir' if (util.OS.isWindows && !/sh/.test(shell.leafName)) { command = "cd /D " + this.cwd.path + " && " + command + " > " + stdout.path + " 2>&1" + " < " + stdin.path; - var res = this.run(shell, shcf.split(/\s+/).concat(command), true); + var res = this.run(shell, shcf.split(/\s+/).concat(command), callback ? async : true); } else { cmd.write("cd " + escape(this.cwd.path) + "\n" + ["exec", ">" + escape(stdout.path), "2>&1", "<" + escape(stdin.path), escape(shell.path), shcf, escape(command)].join(" ")); - res = this.run("/bin/sh", ["-e", cmd.path], true); + res = this.run("/bin/sh", ["-e", cmd.path], callback ? async : true); } - return { - __noSuchMethod__: function (meth, args) this.output[meth].apply(this.output, args), - valueOf: function () this.output, - output: stdout.read().replace(/^(.*)\n$/, "$1"), - returnValue: res, - toString: function () this.output - }; - }) || ""; + return callback ? true : result(res, stdout.read()); + }, this, true); }, /** @@ -533,7 +543,7 @@ var IO = Module("io", { } finally { if (!checked || res !== true) - args.forEach(function (f) f && f.remove(false)); + args.forEach(function (f) f.remove(false)); } return res; } |