1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 10:57:58 +01:00

Merge changes from bootstrapped.

This commit is contained in:
Kris Maglione
2010-12-25 13:45:05 -05:00
parent 7e712dae0f
commit 617a37db1e
14 changed files with 124 additions and 73 deletions

View File

@@ -4,14 +4,17 @@
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
"use strict"; "use strict";
const Ci = Components.interfaces, Cc = Components.classes; var global = this;
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService) var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService)
.getBranch("extensions.dactyl."); .getBranch("extensions.dactyl.");
const appName = prefs.getComplexValue("appName", Ci.nsISupportsString).data; var appName = prefs.getComplexValue("appName", Ci.nsISupportsString).data;
const name = prefs.getComplexValue("name", Ci.nsISupportsString).data; var name = prefs.getComplexValue("name", Ci.nsISupportsString).data;
function CommandLineHandler() { function CommandLineHandler() {
this.wrappedJSObject = this; this.wrappedJSObject = this;
@@ -45,9 +48,9 @@ CommandLineHandler.prototype = {
}; };
if (XPCOMUtils.generateNSGetFactory) if (XPCOMUtils.generateNSGetFactory)
const NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]); var NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]);
else else
const NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]); var NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]);
var EXPORTED_SYMBOLS = ["NSGetFactory"]; var EXPORTED_SYMBOLS = ["NSGetFactory", "global"];
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -12,14 +12,18 @@
* By Kris Maglione, ideas from Ed Anuff's nsChromeExtensionHandler. * By Kris Maglione, ideas from Ed Anuff's nsChromeExtensionHandler.
*/ */
const Ci = Components.interfaces, Cc = Components.classes; var NAME = "protocols";
var global = this;
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService) var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService)
.getBranch("extensions.dactyl."); .getBranch("extensions.dactyl.");
const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal); var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
function dataURL(type, data) "data:" + (type || "application/xml;encoding=UTF-8") + "," + escape(data); function dataURL(type, data) "data:" + (type || "application/xml;encoding=UTF-8") + "," + escape(data);
function makeChannel(url, orig) { function makeChannel(url, orig) {
@@ -199,9 +203,9 @@ Shim.prototype = {
}; };
if (XPCOMUtils.generateNSGetFactory) if (XPCOMUtils.generateNSGetFactory)
const NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutHandler, ChromeData, Dactyl, Shim]); var NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutHandler, ChromeData, Dactyl, Shim]);
else else
const NSGetModule = XPCOMUtils.generateNSGetModule([AboutHandler, ChromeData, Dactyl, Shim]); var NSGetModule = XPCOMUtils.generateNSGetModule([AboutHandler, ChromeData, Dactyl, Shim]);
var EXPORTED_SYMBOLS = ["NSGetFactory"]; var EXPORTED_SYMBOLS = ["NSGetFactory", "global"];
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -539,6 +539,8 @@ const CommandLine = Module("commandline", {
this.widgets.message = null; this.widgets.message = null;
if (modes.main != modes.COMMAND_LINE) if (modes.main != modes.COMMAND_LINE)
this.widgets.command = null; this.widgets.command = null;
if ((modes.extended & modes.OUTPUT_MULTILINE) && this.widgets.multilineOutput.atEnd)
modes.pop();
if (modes.extended != modes.OUTPUT_MULTILINE) if (modes.extended != modes.OUTPUT_MULTILINE)
this.multilineOutputVisible = false; this.multilineOutputVisible = false;
}, },

View File

@@ -1844,8 +1844,7 @@ const Dactyl = Module("dactyl", {
commands.add(["res[tart]"], commands.add(["res[tart]"],
"Force " + config.appName + " to restart", "Force " + config.appName + " to restart",
function () { dactyl.restart(); }, function () { dactyl.restart(); });
{ argCount: "0" });
var toolbox = document.getElementById("navigator-toolbox"); var toolbox = document.getElementById("navigator-toolbox");
if (toolbox) { if (toolbox) {
@@ -2070,14 +2069,16 @@ const Dactyl = Module("dactyl", {
if (!services.commandLineHandler) if (!services.commandLineHandler)
services.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=" + config.name); services.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=" + config.name);
let commandline = services.commandLineHandler.optionValue; if (services.commandlinehandler) {
if (commandline) { let commandline = services.commandLineHandler.optionValue;
let args = dactyl.parseCommandLine(commandline); if (commandline) {
dactyl.commandLineOptions.rcFile = args["+u"]; let args = dactyl.parseCommandLine(commandline);
dactyl.commandLineOptions.noPlugins = "++noplugin" in args; dactyl.commandLineOptions.rcFile = args["+u"];
dactyl.commandLineOptions.postCommands = args["+c"]; dactyl.commandLineOptions.noPlugins = "++noplugin" in args;
dactyl.commandLineOptions.preCommands = args["++cmd"]; dactyl.commandLineOptions.postCommands = args["+c"];
util.dump("Processing command-line option: " + commandline); dactyl.commandLineOptions.preCommands = args["++cmd"];
util.dump("Processing command-line option: " + commandline);
}
} }
dactyl.log("Command-line options: " + util.objectToString(dactyl.commandLineOptions), 3); dactyl.log("Command-line options: " + util.objectToString(dactyl.commandLineOptions), 3);

View File

@@ -4,10 +4,49 @@
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
"use strict"; "use strict";
const Cc = Components.classes; if (!JSMLoader)
const Ci = Components.interfaces; var JSMLoader = {
const Cr = Components.results; builtin: Components.utils.Sandbox(this),
const Cu = Components.utils; globals: {},
stale: {},
load: function load(url, target) {
dump("dactyl: load: " + url + "\n");
if (this.stale[url]) {
delete this.stale[url];
dump("dactyl: load stale\n");
let global = this.globals[url];
for each (let prop in Object.getOwnPropertyNames(global))
try {
if (!set.has(this.builtin, prop) && [this, set].indexOf(global[prop]) < 0)
delete global[prop];
}
catch (e) {}
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader)
.loadSubScript(url, this.globals[url]);
dump("dactyl: load reloaded: " + url + "\n");
}
Components.utils.import(url, target);
},
purge: function purge() {
for (let [url, global] in Iterator(this.globals))
this.stale[url] = true;
},
registerGlobal: function registerGlobal(uri, obj) {
if (Cu.getGlobalForObject)
this.globals[uri.replace(/.* -> /, "")] = Cu.getGlobalForObject(obj);
}
};
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var Cu = Components.utils;
Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication)
.storage.set("dactyl.JSMLoader", JSMLoader);
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
try { try {
@@ -98,7 +137,8 @@ let loaded = {};
let currentModule; let currentModule;
function defineModule(name, params) { function defineModule(name, params) {
let module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__; let module = Cu.getGlobalForObject ? Cu.getGlobalForObject(params) : params.__parent__;
defineModule.globals.push(module); JSMLoader.registerGlobal(Components.stack.caller.filename, module);
module.NAME = name; module.NAME = name;
module.EXPORTED_SYMBOLS = params.exports || []; module.EXPORTED_SYMBOLS = params.exports || [];
defineModule.loadLog.push("defineModule " + name); defineModule.loadLog.push("defineModule " + name);
@@ -115,7 +155,6 @@ function defineModule(name, params) {
currentModule = module; currentModule = module;
} }
defineModule.globals = [];
defineModule.loadLog = []; defineModule.loadLog = [];
Object.defineProperty(defineModule.loadLog, "push", { Object.defineProperty(defineModule.loadLog, "push", {
value: function (val) { defineModule.dump(val + "\n"); this[this.length] = val; } value: function (val) { defineModule.dump(val + "\n"); this[this.length] = val; }
@@ -162,7 +201,7 @@ function endModule() {
function require(obj, name, from) { function require(obj, name, from) {
try { try {
defineModule.loadLog.push((from || "require") + ": loading " + name + " into " + obj.NAME); defineModule.loadLog.push((from || "require") + ": loading " + name + " into " + obj.NAME);
Cu.import("resource://dactyl/" + name + ".jsm", obj); JSMLoader.load("resource://dactyl/" + name + ".jsm", obj);
} }
catch (e) { catch (e) {
defineModule.dump("loading " + String.quote("resource://dactyl/" + name + ".jsm") + "\n"); defineModule.dump("loading " + String.quote("resource://dactyl/" + name + ".jsm") + "\n");
@@ -176,7 +215,7 @@ function require(obj, name, from) {
defineModule("base", { defineModule("base", {
// sed -n 's/^(const|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt // sed -n 's/^(const|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt
exports: [ exports: [
"ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "Object", "Runnable", "ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "JSMLoader", "Object", "Runnable",
"Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "array", "Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "array",
"call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule", "call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
"deprecated", "endModule", "forEach", "isArray", "isGenerator", "deprecated", "endModule", "forEach", "isArray", "isGenerator",
@@ -478,7 +517,7 @@ function isSubclass(targ, src) {
* @param {object|string|[object|string]} src The types to check targ against. * @param {object|string|[object|string]} src The types to check targ against.
* @returns {boolean} * @returns {boolean}
*/ */
const isinstance_types = { var isinstance_types = {
boolean: Boolean, boolean: Boolean,
string: String, string: String,
function: Function, function: Function,
@@ -513,7 +552,7 @@ function isObject(obj) typeof obj === "object" && obj != null || obj instanceof
* any window, frame, namespace, or execution context, which * any window, frame, namespace, or execution context, which
* is not the case when using (obj instanceof Array). * is not the case when using (obj instanceof Array).
*/ */
const isArray = var isArray =
Array.isArray Array.isArray
// This is bloody stupid. // This is bloody stupid.
? function isArray(val) Array.isArray(val) || val && val.constructor && val.constructor.name === "Array" ? function isArray(val) Array.isArray(val) || val && val.constructor && val.constructor.name === "Array"
@@ -617,7 +656,7 @@ sandbox.__proto__ = this;
* is prepended to its arguments. * is prepended to its arguments.
*/ */
// Hack to get around lack of access to caller in strict mode. // Hack to get around lack of access to caller in strict mode.
const withCallerGlobal = Cu.evalInSandbox(<![CDATA[ var withCallerGlobal = Cu.evalInSandbox(<![CDATA[
(function withCallerGlobal(fn) (function withCallerGlobal(fn)
function withCallerGlobal_wrapped() function withCallerGlobal_wrapped()
fn.apply(this, fn.apply(this,
@@ -860,7 +899,7 @@ function XPCOM(interfaces, superClass) {
/** /**
* An abstract base class for classes that wish to inherit from Error. * An abstract base class for classes that wish to inherit from Error.
*/ */
const ErrorBase = Class("ErrorBase", Error, { var ErrorBase = Class("ErrorBase", Error, {
level: 2, level: 2,
init: function (message, level) { init: function (message, level) {
level = level || 0; level = level || 0;
@@ -980,7 +1019,7 @@ let StructBase = Class("StructBase", Array, {
} }
}); });
const Timer = Class("Timer", { var Timer = Class("Timer", {
init: function (minInterval, maxInterval, callback) { init: function (minInterval, maxInterval, callback) {
this._timer = services.Timer(); this._timer = services.Timer();
this.callback = callback; this.callback = callback;
@@ -1056,7 +1095,7 @@ function octal(decimal) parseInt(decimal, 8);
/** /**
* Array utility methods. * Array utility methods.
*/ */
const array = Class("array", Array, { var array = Class("array", Array, {
init: function (ary) { init: function (ary) {
if (isinstance(ary, ["Iterator", "Generator"]) || "__iterator__" in ary) if (isinstance(ary, ["Iterator", "Generator"]) || "__iterator__" in ary)
ary = [k for (k in ary)]; ary = [k for (k in ary)];

View File

@@ -10,8 +10,8 @@ defineModule("bookmarkcache", {
require: ["services", "storage", "util"] require: ["services", "storage", "util"]
}); });
const Bookmark = Struct("url", "title", "icon", "post", "keyword", "tags", "id"); var Bookmark = Struct("url", "title", "icon", "post", "keyword", "tags", "id");
const Keyword = Struct("keyword", "title", "icon", "url"); var Keyword = Struct("keyword", "title", "icon", "url");
Bookmark.defaultValue("icon", function () BookmarkCache.getFavicon(this.url)); Bookmark.defaultValue("icon", function () BookmarkCache.getFavicon(this.url));
Bookmark.setter = function (key, func) this.prototype.__defineSetter__(key, func); Bookmark.setter = function (key, func) this.prototype.__defineSetter__(key, func);
Bookmark.prototype.__defineGetter__("extra", function () [ Bookmark.prototype.__defineGetter__("extra", function () [
@@ -33,9 +33,9 @@ Bookmark.setter("tags", function (val) {
services.tagging.tagURI(this.uri, val); services.tagging.tagURI(this.uri, val);
}); });
const name = "bookmark-cache"; var name = "bookmark-cache";
const BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), { var BookmarkCache = Module("BookmarkCache", XPCOM(Ci.nsINavBookmarkObserver), {
POST: "bookmarkProperties/POSTData", POST: "bookmarkProperties/POSTData",
init: function init() { init: function init() {

View File

@@ -11,9 +11,9 @@ defineModule("highlight", {
use: ["template", "util"] use: ["template", "util"]
}); });
const Highlight = Struct("class", "selector", "sites", var Highlight = Struct("class", "selector", "sites",
"default", "value", "agent", "default", "value", "agent",
"base", "baseClass", "style"); "base", "baseClass", "style");
Highlight.liveProperty = function (name, prop) { Highlight.liveProperty = function (name, prop) {
let i = this.prototype.members[name]; let i = this.prototype.members[name];
this.prototype.__defineGetter__(name, function () this[i]); this.prototype.__defineGetter__(name, function () this[i]);
@@ -52,7 +52,7 @@ Highlight.prototype.toString = function ()
* *
* @author Kris Maglione <maglione.k@gmail.com> * @author Kris Maglione <maglione.k@gmail.com>
*/ */
const Highlights = Module("Highlight", { var Highlights = Module("Highlight", {
init: function () { init: function () {
this.highlight = {}; this.highlight = {};
this.loaded = {}; this.loaded = {};

View File

@@ -13,7 +13,7 @@ defineModule("prefs", {
use: ["template"] use: ["template"]
}); });
const Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), {
SAVED: "extensions.dactyl.saved.", SAVED: "extensions.dactyl.saved.",
RESTORE: "extensions.dactyl.restore.", RESTORE: "extensions.dactyl.restore.",

View File

@@ -24,7 +24,7 @@ let tmp = {};
services.subscriptLoader.loadSubScript("chrome://browser/content/sanitize.js", tmp); services.subscriptLoader.loadSubScript("chrome://browser/content/sanitize.js", tmp);
tmp.Sanitizer.prototype.__proto__ = Class.prototype; tmp.Sanitizer.prototype.__proto__ = Class.prototype;
const Range = Struct("min", "max"); var Range = Struct("min", "max");
Range.prototype.contains = function (date) Range.prototype.contains = function (date)
date == null || (this.min == null || date >= this.min) && (this.max == null || date <= this.max); date == null || (this.min == null || date >= this.min) && (this.max == null || date <= this.max);
Range.prototype.__defineGetter__("isEternity", function () this.max == null && this.min == null); Range.prototype.__defineGetter__("isEternity", function () this.max == null && this.min == null);
@@ -33,7 +33,7 @@ Range.prototype.__defineGetter__("native", function ()
this.isEternity ? null : [range.min || 0, range.max == null ? Number.MAX_VALUE : range.max]); this.isEternity ? null : [range.min || 0, range.max == null ? Number.MAX_VALUE : range.max]);
const Item = Class("Item", { var Item = Class("Item", {
init: function (name) { init: function (name) {
this.name = name; this.name = name;
}, },
@@ -55,7 +55,7 @@ const Item = Class("Item", {
SHUTDOWN_BRANCH: "privacy.clearOnShutdown." SHUTDOWN_BRANCH: "privacy.clearOnShutdown."
}); });
const Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference], tmp.Sanitizer), { var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference], tmp.Sanitizer), {
sessionStart: Date.now() * 1000, sessionStart: Date.now() * 1000,
init: function () { init: function () {

View File

@@ -14,7 +14,7 @@ defineModule("services", {
/** /**
* A lazily-instantiated XPCOM class and service cache. * A lazily-instantiated XPCOM class and service cache.
*/ */
const Services = Module("Services", { var Services = Module("Services", {
init: function () { init: function () {
this.classes = {}; this.classes = {};
this.services = {}; this.services = {};
@@ -36,6 +36,7 @@ const Services = Module("Services", {
this.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager); this.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager);
this.add("favicon", "@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService); this.add("favicon", "@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService);
this.add("focus", "@mozilla.org/focus-manager;1", Ci.nsIFocusManager); this.add("focus", "@mozilla.org/focus-manager;1", Ci.nsIFocusManager);
this.add("fuel", "@mozilla.org/fuel/application;1", Ci.fuelIApplication);
this.add("history", "@mozilla.org/browser/global-history;2", [Ci.nsIBrowserHistory, Ci.nsIGlobalHistory3, this.add("history", "@mozilla.org/browser/global-history;2", [Ci.nsIBrowserHistory, Ci.nsIGlobalHistory3,
Ci.nsINavHistoryService, Ci.nsPIPlacesDatabase]); Ci.nsINavHistoryService, Ci.nsPIPlacesDatabase]);
this.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService); this.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService);

View File

@@ -7,14 +7,14 @@
if (this.XPCSafeJSObjectWrapper == null) if (this.XPCSafeJSObjectWrapper == null)
this.XPCSafeJSObjectWrapper = XPCNativeWrapper; this.XPCSafeJSObjectWrapper = XPCNativeWrapper;
const myObject = Object; var myObject = Object;
Components.utils.import("resource://dactyl/base.jsm"); Components.utils.import("resource://dactyl/base.jsm");
defineModule("storage", { defineModule("storage", {
exports: ["File", "storage"], exports: ["File", "storage"],
require: ["services", "util"] require: ["services", "util"]
}); });
const win32 = /^win(32|nt)$/i.test(services.runtime.OS); var win32 = /^win(32|nt)$/i.test(services.runtime.OS);
function loadData(name, store, type) { function loadData(name, store, type) {
try { try {
@@ -33,7 +33,7 @@ function saveData(obj) {
storage.infoPath.child(obj.name).write(obj.serial); storage.infoPath.child(obj.name).write(obj.serial);
} }
const StoreBase = Class("StoreBase", { var StoreBase = Class("StoreBase", {
OPTIONS: ["privateData", "replacer"], OPTIONS: ["privateData", "replacer"],
fireEvent: function (event, arg) { storage.fireEvent(this.name, event, arg); }, fireEvent: function (event, arg) { storage.fireEvent(this.name, event, arg); },
@@ -61,7 +61,7 @@ const StoreBase = Class("StoreBase", {
save: function () { saveData(this); }, save: function () { saveData(this); },
}); });
const ArrayStore = Class("ArrayStore", StoreBase, { var ArrayStore = Class("ArrayStore", StoreBase, {
_constructor: Array, _constructor: Array,
get length() this._object.length, get length() this._object.length,
@@ -107,7 +107,7 @@ const ArrayStore = Class("ArrayStore", StoreBase, {
__iterator__: function () Iterator(this._object), __iterator__: function () Iterator(this._object),
}); });
const ObjectStore = Class("ObjectStore", StoreBase, { var ObjectStore = Class("ObjectStore", StoreBase, {
_constructor: myObject, _constructor: myObject,
clear: function () { clear: function () {
@@ -142,7 +142,7 @@ const ObjectStore = Class("ObjectStore", StoreBase, {
__iterator__: function () Iterator(this._object), __iterator__: function () Iterator(this._object),
}); });
const Storage = Module("Storage", { var Storage = Module("Storage", {
alwaysReload: {}, alwaysReload: {},
init: function () { init: function () {
@@ -269,7 +269,7 @@ const Storage = Module("Storage", {
* @param {boolean} checkPWD Whether to allow expansion relative to the * @param {boolean} checkPWD Whether to allow expansion relative to the
* current directory. @default true * current directory. @default true
*/ */
const File = Class("File", { var File = Class("File", {
init: function (path, checkPWD) { init: function (path, checkPWD) {
let file = services.File(); let file = services.File();

View File

@@ -12,11 +12,11 @@ defineModule("styles", {
}); });
function cssUri(css) "chrome-data:text/css," + encodeURI(css); function cssUri(css) "chrome-data:text/css," + encodeURI(css);
const namespace = "@namespace html " + XHTML.uri.quote() + ";\n" + var namespace = "@namespace html " + XHTML.uri.quote() + ";\n" +
"@namespace xul " + XUL.uri.quote() + ";\n" + "@namespace xul " + XUL.uri.quote() + ";\n" +
"@namespace dactyl " + NS.uri.quote() + ";\n"; "@namespace dactyl " + NS.uri.quote() + ";\n";
const Sheet = Struct("name", "id", "sites", "css", "hive", "agent"); var Sheet = Struct("name", "id", "sites", "css", "hive", "agent");
Sheet.liveProperty = function (name) { Sheet.liveProperty = function (name) {
let i = this.prototype.members[name]; let i = this.prototype.members[name];
this.prototype.__defineGetter__(name, function () this[i]); this.prototype.__defineGetter__(name, function () this[i]);
@@ -73,7 +73,7 @@ update(Sheet.prototype, {
} }
}); });
const Hive = Class("Hive", { var Hive = Class("Hive", {
init: function () { init: function () {
this.sheets = []; this.sheets = [];
this.names = {}; this.names = {};
@@ -212,7 +212,7 @@ const Hive = Class("Hive", {
* *
* @author Kris Maglione <maglione.k@gmail.com> * @author Kris Maglione <maglione.k@gmail.com>
*/ */
const Styles = Module("Styles", { var Styles = Module("Styles", {
init: function () { init: function () {
this._id = 0; this._id = 0;
this.user = Hive(); this.user = Hive();

View File

@@ -13,7 +13,7 @@ defineModule("template", {
default xml namespace = XHTML; default xml namespace = XHTML;
const Template = Module("Template", { var Template = Module("Template", {
add: function add(a, b) a + b, add: function add(a, b) a + b,
join: function join(c) function (a, b) a + c + b, join: function join(c) function (a, b) a + c + b,

View File

@@ -15,10 +15,10 @@ defineModule("util", {
use: ["highlight", "storage", "template"] use: ["highlight", "storage", "template"]
}); });
const XBL = Namespace("xbl", "http://www.mozilla.org/xbl"); var XBL = Namespace("xbl", "http://www.mozilla.org/xbl");
const XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); var XHTML = Namespace("html", "http://www.w3.org/1999/xhtml");
const XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); var XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
const NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator"); var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML; default xml namespace = XHTML;
memoize(this, "Commands", function () { memoize(this, "Commands", function () {
@@ -28,7 +28,7 @@ memoize(this, "Commands", function () {
return obj.Commands; return obj.Commands;
}); });
const FailedAssertion = Class("FailedAssertion", ErrorBase); var FailedAssertion = Class("FailedAssertion", ErrorBase);
function wrapCallback(fn) function wrapCallback(fn)
fn.wrapper = function wrappedCallback () { fn.wrapper = function wrappedCallback () {
@@ -41,7 +41,7 @@ function wrapCallback(fn)
} }
} }
const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), {
init: function () { init: function () {
this.Array = array; this.Array = array;
@@ -92,16 +92,17 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @param {object} obj * @param {object} obj
*/ */
addObserver: function (obj) { addObserver: function (obj) {
let observers = obj.observe; let observers = obj._observe || obj.observe;
obj._observe = observers;
function register(meth) { function register(meth) {
services.observer[meth](obj, "quit-application", true); services.observer[meth](obj, "quit-application", true);
services.observer[meth](obj, "dactyl-unload", true); services.observer[meth](obj, "dactyl-cleanup", true);
for (let target in keys(observers)) for (let target in keys(observers))
services.observer[meth](obj, target, true); services.observer[meth](obj, target, true);
} }
Class.replaceProperty(obj, "observe", Class.replaceProperty(obj, "observe",
function (subject, target, data) { function (subject, target, data) {
if (target == "quit-application" || target == "dactyl-unload") if (target == "quit-application" || target == "dactyl-cleanup")
register("removeObserver"); register("removeObserver");
if (observers[target]) if (observers[target])
observers[target].call(obj, subject, data); observers[target].call(obj, subject, data);
@@ -1402,7 +1403,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* Math utility methods. * Math utility methods.
* @singleton * @singleton
*/ */
const GlobalMath = Math; var GlobalMath = Math;
var Math = update(Object.create(GlobalMath), { var Math = update(Object.create(GlobalMath), {
/** /**
* Returns the specified *value* constrained to the range *min* - *max*. * Returns the specified *value* constrained to the range *min* - *max*.