// 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.
lazyRequire("config", ["config"]);
lazyRequire("contexts", ["Contexts", "contexts"]);
+lazyRequire("promises", ["Promise"]);
lazyRequire("storage", ["File", "storage"]);
lazyRequire("styles", ["styles"]);
lazyRequire("template", ["template"]);
this._oldcwd = null;
this._lastRunCommand = ""; // updated whenever the users runs a command with :!
- this._scriptNames = [];
+ this._scriptNames = RealSet();
},
CommandFileMode: Class("CommandFileMode", modules.CommandMode, {
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);
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);
* @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));
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
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)
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