summaryrefslogtreecommitdiff
path: root/common/content
diff options
context:
space:
mode:
authorKris Maglione <maglione.k@gmail.com>2015-03-02 18:12:57 -0800
committerKris Maglione <maglione.k@gmail.com>2015-03-02 18:12:57 -0800
commit7b2f821e0430661efc62afb07a31219e14dda4e6 (patch)
tree042fa7ed21248d0c73d9f98b30d947f2e7e1b060 /common/content
parentc84c657d27f2a600702adc1f5fc8c44607ba1b75 (diff)
downloadpentadactyl-7b2f821e0430661efc62afb07a31219e14dda4e6.tar.gz
Promises cleanup.
Diffstat (limited to 'common/content')
-rw-r--r--common/content/bookmarks.js31
-rw-r--r--common/content/commandline.js62
2 files changed, 48 insertions, 45 deletions
diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js
index c755a6bf..fbbe3172 100644
--- a/common/content/bookmarks.js
+++ b/common/content/bookmarks.js
@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-2015 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.
@@ -302,23 +302,22 @@ var Bookmarks = Module("bookmarks", {
* @returns {Promise<Array>}
*/
makeSuggestions: function makeSuggestions(url, parser) {
- let deferred = Promise.defer();
+ return new CancelablePromise((resolve, reject, canceled) => {
+ let req = util.fetchUrl(url);
+ req.then(function process(req) {
+ let results = [];
+ try {
+ results = parser(req);
+ }
+ catch (e) {
+ reject(e);
+ return;
+ }
+ resolve(results);
+ });
- let req = util.fetchUrl(url);
- req.then(function process(req) {
- let results = [];
- try {
- results = parser(req);
- }
- catch (e) {
- deferred.reject(e);
- return;
- }
- deferred.resolve(results);
+ canceled.then(req.cancel);
});
-
- promises.oncancel(deferred, reason => promises.cancel(req, reason));
- return deferred.promise;
},
suggestionProviders: {},
diff --git a/common/content/commandline.js b/common/content/commandline.js
index 958d466f..1104a5db 100644
--- a/common/content/commandline.js
+++ b/common/content/commandline.js
@@ -855,13 +855,15 @@ var CommandLine = Module("commandline", {
* @... {string} default - The initial value that will be returned
* if the user presses <CR> straightaway. @default ""
*/
- input: promises.withCallbacks(function _input([callback, reject], prompt, extra={}, thing={}) {
- if (callable(extra))
- // Deprecated.
- [callback, extra] = [extra, thing];
+ input: function _input(prompt, extra={}, thing={}) {
+ return new Promise((resolve, reject) => {
+ if (callable(extra))
+ // Deprecated.
+ [resolve, extra] = [extra, thing];
- CommandPromptMode(prompt, update({ onSubmit: callback, onCancel: reject }, extra)).open();
- }),
+ CommandPromptMode(prompt, update({ onSubmit: resolve, onCancel: reject }, extra)).open();
+ });
+ },
readHeredoc: function readHeredoc(end) {
return util.waitFor(commandline.inputMultiline(end));
@@ -876,33 +878,35 @@ var CommandLine = Module("commandline", {
* @returns {Promise<string>}
*/
// FIXME: Buggy, especially when pasting.
- inputMultiline: promises.withCallbacks(function inputMultiline([callback], end) {
- let cmd = this.command;
- let self = {
- end: "\n" + end + "\n",
- callback: callback
- };
-
- modes.push(modes.INPUT_MULTILINE, null, {
- holdFocus: true,
- leave: function leave() {
- if (!self.done)
- self.callback(null);
- },
- mappingSelf: self
- });
+ inputMultiline: function inputMultiline(end) {
+ return new Promise((resolve, reject) => {
+ let cmd = this.command;
+ let self = {
+ end: "\n" + end + "\n",
+ callback: resolve
+ };
- if (cmd != false)
- this._echoLine(cmd, this.HL_NORMAL);
+ modes.push(modes.INPUT_MULTILINE, null, {
+ holdFocus: true,
+ leave: function leave() {
+ if (!self.done)
+ self.callback(null);
+ },
+ mappingSelf: self
+ });
- // save the arguments, they are needed in the event handler onKeyPress
+ if (cmd != false)
+ this._echoLine(cmd, this.HL_NORMAL);
- this.multilineInputVisible = true;
- this.widgets.multilineInput.value = "";
- this._autosizeMultilineInputWidget();
+ // save the arguments, they are needed in the event handler onKeyPress
- this.timeout(function () { dactyl.focus(this.widgets.multilineInput); }, 10);
- }),
+ this.multilineInputVisible = true;
+ this.widgets.multilineInput.value = "";
+ this._autosizeMultilineInputWidget();
+
+ this.timeout(function () { dactyl.focus(this.widgets.multilineInput); }, 10);
+ });
+ },
get commandMode() this.commandSession && isinstance(modes.main, modes.COMMAND_LINE),