1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-06 18:54:12 +01:00

Some minor cleanup and fixes.

This commit is contained in:
Kris Maglione
2010-12-09 20:46:35 -05:00
parent a0335cb437
commit e339032fd2
7 changed files with 92 additions and 58 deletions

View File

@@ -3,7 +3,9 @@
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";
try {
Components.utils.import("resource://dactyl/base.jsm");
defineModule("services", {
exports: ["Services", "services"],
@@ -58,7 +60,7 @@ const Services = Module("Services", {
this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher);
this.addClass("File", "@mozilla.org/file/local;1", Ci.nsILocalFile);
this.addClass("File:", "@mozilla.org/network/protocol;1?name=file", Ci.nsIFileProtocolHandler);
this.addClass("file:", "@mozilla.org/network/protocol;1?name=file", Ci.nsIFileProtocolHandler);
this.addClass("Find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);
this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", Ci.nsIFormatConverter);
this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", Ci.nsIDocumentEncoder);
@@ -71,21 +73,13 @@ const Services = Module("Services", {
_create: function (classes, ifaces, meth) {
try {
for (let i = 0; !res && i < 15; i++) // FIXME: Hack.
try {
var res = Cc[classes][meth || "getService"]();
}
catch (e if e.result === Cr.NS_ERROR_XPC_BAD_OP_ON_WN_PROTO) {
util.dump(String(e));
}
let res = Cc[classes][meth || "getService"]();
if (!ifaces)
return res.wrappedJSObject;
Array.concat(ifaces).forEach(function (iface) res.QueryInterface(iface));
return res;
}
catch (e) {
// dactyl.log() is not defined at this time, so just dump any error
util.dump("Service creation failed for '" + classes + "': " + e + "\n");
return null;
}
@@ -103,7 +97,7 @@ const Services = Module("Services", {
*/
add: function (name, class_, ifaces, meth) {
const self = this;
if (name in this && !this.__lookupGetter__(name) && !(this[name] instanceof Ci.nsISupports))
if (name in this && ifaces && !this.__lookupGetter__(name) && !(this[name] instanceof Ci.nsISupports))
throw TypeError();
this.__defineGetter__(name, function () {
delete this[name];

View File

@@ -264,7 +264,7 @@ const File = Class("File", {
if (path instanceof Ci.nsIFile)
file = path.QueryInterface(Ci.nsIFile).clone();
else if (/file:\/\//.test(path))
file = services["File:"]().getFileFromURLSpec(path);
file = services["file:"]().getFileFromURLSpec(path);
else {
try {
let expandedPath = File.expandPath(path);

View File

@@ -20,6 +20,13 @@ const XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.
const NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML;
memoize(this, "Commands", function () {
// FIXME
let obj = {};
services.subscriptLoader.loadSubScript("chrome://dactyl/content/commands.js", obj);
return obj.Commands;
});
const FailedAssertion = Class("FailedAssertion", Error, {
init: function (message) {
this.message = message;
@@ -135,6 +142,56 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
compareIgnoreCase: function compareIgnoreCase(a, b) String.localeCompare(a.toLowerCase(), b.toLowerCase()),
compileFormat: function compileFormat(format) {
let stack = [frame()];
stack.__defineGetter__("top", function () this[this.length - 1]);
function frame() update(
function _frame(obj)
_frame === stack.top || _frame.valid(obj) ?
_frame.elements.map(function (e) callable(e) ? e(obj) : e).join("") : "",
{
elements: [],
seen: {},
valid: function (obj) this.elements.every(function (e) !e.test || e.test(obj))
});
let match, end = 0, re = /(.*?)%(.)/gy;
while (match = re.exec(format)) {
let [, prefix, char] = match;
end += match[0].length;
if (prefix)
stack.top.elements.push(prefix);
if (char === "%")
stack.top.elements.push("%");
else if (char === "[") {
let f = frame();
stack.top.elements.push(f);
stack.push(f);
}
else if (char === "]") {
stack.pop();
util.assert(stack.length, "Unmatched %] in format");
}
else {
let quote = function quote(obj, char) obj[char];
if (char !== char.toLowerCase())
quote = function quote(obj, char) Commands.quote(obj[char]);
char = char.toLowerCase();
stack.top.elements.push(update(
function (obj) obj[char] != null ? quote(obj, char) : "",
{ test: function (obj) obj[char] != null }));
}
for (let elem in array.iterValues(stack))
elem.seen[char] = true;
}
if (end < format.length)
stack.top.elements.push(format.substr(end));
util.assert(stack.length === 1, "Unmatched %[ in format");
return stack.top;
},
/**