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

Death to E4X and stuff.

This commit is contained in:
Kris Maglione
2012-11-30 22:31:04 -08:00
parent da3785028d
commit 2274b0900a
14 changed files with 51 additions and 46 deletions

View File

@@ -418,7 +418,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (isObject(str) && "echoerr" in str) if (isObject(str) && "echoerr" in str)
str = str.echoerr; str = str.echoerr;
else if (isinstance(str, ["Error", FailedAssertion]) && str.fileName) else if (isinstance(str, ["Error", FailedAssertion]) && str.fileName)
str = <>{str.fileName.replace(/^.* -> /, "")}: {str.lineNumber}: {str}</>; str = util.Magic([str.fileName.replace(/^.* -> /, ""), ": ", str.lineNumber, ": ", str].join(""));
if (options["errorbells"]) if (options["errorbells"])
dactyl.beep(); dactyl.beep();

View File

@@ -279,8 +279,6 @@ var AddonList = Class("AddonList", {
}, },
message: Class.Memoize(function () { message: Class.Memoize(function () {
XML.ignoreWhitespace = true;
DOM.fromJSON(["table", { highlight: "Addons", key: "list" }, DOM.fromJSON(["table", { highlight: "Addons", key: "list" },
["tr", { highlight: "AddonHead" }, ["tr", { highlight: "AddonHead" },
["td", {}, _("title.Name")], ["td", {}, _("title.Name")],

View File

@@ -159,6 +159,9 @@ this.lazyRequire("util", ["FailedAssertion", "util"]);
function literal(/* comment */) { function literal(/* comment */) {
let { caller } = Components.stack; let { caller } = Components.stack;
while (caller && caller.language != 2)
caller = caller.caller;
let file = caller.filename.replace(/.* -> /, ""); let file = caller.filename.replace(/.* -> /, "");
let key = "literal:" + file + ":" + caller.line; let key = "literal:" + file + ":" + caller.line;

View File

@@ -17,7 +17,6 @@ var XBL = Namespace("xbl", "http://www.mozilla.org/xbl");
var XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); var XHTML = Namespace("html", "http://www.w3.org/1999/xhtml");
var 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");
var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator"); var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator");
default xml namespace = XHTML;
function BooleanAttribute(attr) ({ function BooleanAttribute(attr) ({
get: function (elem) elem.getAttribute(attr) == "true", get: function (elem) elem.getAttribute(attr) == "true",
@@ -117,7 +116,6 @@ var DOM = Class("DOM", {
}, },
eachDOM: function eachDOM(val, fn, self) { eachDOM: function eachDOM(val, fn, self) {
XML.prettyPrinting = XML.ignoreWhitespace = false;
if (isString(val)) if (isString(val))
val = XML(val); val = XML(val);

View File

@@ -223,8 +223,6 @@ var DownloadList = Class("DownloadList",
message: Class.Memoize(function () { message: Class.Memoize(function () {
XML.ignoreWhitespace = true;
XML.prettyPrinting = false;
DOM.fromJSON(["table", { highlight: "Downloads", key: "list" }, DOM.fromJSON(["table", { highlight: "Downloads", key: "list" },
["tr", { highlight: "DownloadHead", key: "head" }, ["tr", { highlight: "DownloadHead", key: "head" },
["span", {}, _("title.Title")], ["span", {}, _("title.Title")],

View File

@@ -119,7 +119,8 @@ var JavaScript = Module("javascript", {
context[JavaScript.EVAL_TMP] = tmp; context[JavaScript.EVAL_TMP] = tmp;
try { try {
cache[key] = this.modules.dactyl.userEval(arg, context, /*L*/"[Command Line Completion]", 1); cache[key] = this.modules.dactyl.userEval(arg, context,
/*L*/"[Command Line Completion]", 1);
return cache[key]; return cache[key];
} }

View File

@@ -90,20 +90,13 @@ var Modules = function Modules(window) {
Module.list = []; Module.list = [];
Module.constructors = {}; Module.constructors = {};
const create = window.Object.create || (function () { const create = window.Object.create.bind(window.Object);
window.__dactyl_eval_string = "(function (proto) ({ __proto__: proto }))";
JSMLoader.loadSubScript(BASE + "eval.js", window);
let res = window.__dactyl_eval_result;
delete window.__dactyl_eval_string;
delete window.__dactyl_eval_result;
return res;
})();
const BASES = [BASE, "resource://dactyl-local-content/"]; const BASES = [BASE, "resource://dactyl-local-content/"];
const jsmodules = { NAME: "jsmodules" }; jsmodules = Cu.createObjectIn(window);
jsmodules.NAME = "jsmodules";
const modules = update(create(jsmodules), { const modules = update(create(jsmodules), {
yes_i_know_i_should_not_report_errors_in_these_branches_thanks: [], yes_i_know_i_should_not_report_errors_in_these_branches_thanks: [],

View File

@@ -1295,24 +1295,7 @@ var Options = Module("options", {
function fmt(value) (typeof value == "number" ? "#" : function fmt(value) (typeof value == "number" ? "#" :
typeof value == "function" ? "*" : typeof value == "function" ? "*" :
" ") + value; " ") + value;
if (!args || args == "g:") { util.assert(!(!args || args == "g:"));
let str =
<table>
{
template.map(globalVariables, function ([i, value]) {
return <tr>
<td style="width: 200px;">{i}</td>
<td>{fmt(value)}</td>
</tr>;
})
}
</table>;
if (str.text().length() == str.*.length())
dactyl.echomsg(_("variable.none"));
else
dactyl.echo(str, modules.commandline.FORCE_MULTILINE);
return;
}
let matches = args.match(/^([a-z]:)?([\w]+)(?:\s*([-+.])?=\s*(.*)?)?$/); let matches = args.match(/^([a-z]:)?([\w]+)(?:\s*([-+.])?=\s*(.*)?)?$/);
if (matches) { if (matches) {

View File

@@ -157,9 +157,20 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
getData: function getData(obj, key, constructor) { getData: function getData(obj, key, constructor) {
if (!this.weakMap.has(obj)) if (!this.weakMap.has(obj))
try {
this.weakMap.set(obj, {}); this.weakMap.set(obj, {});
}
catch (e if e instanceof TypeError) {
// util.dump("Bad WeakMap key: " + obj + " " + Components.stack.caller);
let { id } = this;
let data = this.weakMap.get(obj); if (!(id in obj && obj[id]))
obj[id] = {};
var data = obj[id];
}
data = data || this.weakMap.get(obj);
if (arguments.length == 1) if (arguments.length == 1)
return data; return data;

View File

@@ -359,6 +359,8 @@ var File = Class("File", {
return File.DoesNotExist(path, e); return File.DoesNotExist(path, e);
} }
} }
this.file = file;
let self = XPCSafeJSObjectWrapper(file.QueryInterface(Ci.nsILocalFile)); let self = XPCSafeJSObjectWrapper(file.QueryInterface(Ci.nsILocalFile));
self.__proto__ = this; self.__proto__ = this;
return self; return self;

View File

@@ -35,9 +35,9 @@ Sheet.liveProperty("css");
Sheet.liveProperty("sites"); Sheet.liveProperty("sites");
update(Sheet.prototype, { update(Sheet.prototype, {
formatSites: function (uris) formatSites: function (uris)
template.map(this.sites, template_.map(this.sites,
function (filter) <span highlight={uris.some(Styles.matchFilter(filter)) ? "Filter" : ""}>{filter}</span>, function (filter) ["span", { highlight: uris.some(Styles.matchFilter(filter)) ? "Filter" : "" }, filter],
<>,</>), ","),
remove: function () { this.hive.remove(this); }, remove: function () { this.hive.remove(this); },

View File

@@ -317,6 +317,8 @@ var Template = Module("Template", {
case "object": case "object":
if (arg instanceof Ci.nsIDOMElement) if (arg instanceof Ci.nsIDOMElement)
return util.objectToString(arg, !bw); return util.objectToString(arg, !bw);
if (arg instanceof util.Magic)
return <>{arg}</>;
// for java packages value.toString() would crash so badly // for java packages value.toString() would crash so badly
// that we cannot even try/catch it // that we cannot even try/catch it
@@ -718,6 +720,8 @@ var Template_ = Module("Template_", {
case "object": case "object":
if (arg instanceof Ci.nsIDOMElement) if (arg instanceof Ci.nsIDOMElement)
return util.objectToString(arg, !bw); return util.objectToString(arg, !bw);
if (arg instanceof Magic)
return String(arg);
if (processStrings && false) if (processStrings && false)
str = template._highlightFilter(str, "\n", str = template._highlightFilter(str, "\n",

View File

@@ -17,6 +17,14 @@ lazyRequire("overlay", ["overlay"]);
lazyRequire("storage", ["File", "storage"]); lazyRequire("storage", ["File", "storage"]);
lazyRequire("template", ["template"]); lazyRequire("template", ["template"]);
var Magic = Class("Magic", {
init: function init(str) {
this.str = str;
},
toString: function () this.str
});
var FailedAssertion = Class("FailedAssertion", ErrorBase, { var FailedAssertion = Class("FailedAssertion", ErrorBase, {
init: function init(message, level, noTrace) { init: function init(message, level, noTrace) {
if (noTrace !== undefined) if (noTrace !== undefined)
@@ -52,6 +60,8 @@ var wrapCallback = function wrapCallback(fn, isEvent) {
} }
var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), {
Magic: Magic,
init: function () { init: function () {
this.Array = array; this.Array = array;
@@ -997,7 +1007,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
keyIter = keys(object) keyIter = keys(object)
for (let i in keyIter) { for (let i in keyIter) {
let value = <![CDATA[<no value>]]>; let value = Magic("<no value>");
try { try {
value = object[i]; value = object[i];
} }
@@ -1204,7 +1214,11 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
// Replace replacement <tokens>. // Replace replacement <tokens>.
if (tokens) if (tokens)
expr = String.replace(expr, /(\(?P)?<(\w+)>/g, function (m, n1, n2) !n1 && Set.has(tokens, n2) ? tokens[n2].dactylSource || tokens[n2].source || tokens[n2] : m); expr = String.replace(expr, /(\(?P)?<(\w+)>/g,
function (m, n1, n2) !n1 && Set.has(tokens, n2) ? tokens[n2].dactylSource
|| tokens[n2].source
|| tokens[n2]
: m);
// Strip comments and white space. // Strip comments and white space.
if (/x/.test(flags)) if (/x/.test(flags))
@@ -1322,7 +1336,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
let obj = update({}, error, { let obj = update({}, error, {
toString: function () String(error), toString: function () String(error),
stack: <>{util.stackLines(String(error.stack || Error().stack)).join("\n").replace(/^/mg, "\t")}</> stack: Magic(util.stackLines(String(error.stack || Error().stack)).join("\n").replace(/^/mg, "\t"))
}); });
services.console.logStringMessage(obj.stack); services.console.logStringMessage(obj.stack);

View File

@@ -31,8 +31,8 @@
<em:targetApplication> <em:targetApplication>
<Description <Description
em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}" em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
em:minVersion="6.0" em:minVersion="8.0"
em:maxVersion="14.*"/> em:maxVersion="17.*"/>
</em:targetApplication> </em:targetApplication>
</Description> </Description>
</RDF> </RDF>