1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-08 10:04:12 +01:00

Remove compatiblity cruft.

This commit is contained in:
Kris Maglione
2014-02-16 16:10:08 -08:00
parent 6202e94cb7
commit dee8fc3bba
11 changed files with 83 additions and 217 deletions

View File

@@ -684,7 +684,7 @@ var CommandLine = Module("commandline", {
* Displays the multi-line output of a command, preceded by the last * Displays the multi-line output of a command, preceded by the last
* executed ex command string. * executed ex command string.
* *
* @param {XML} xml The output as an E4X XML object. * @param {object} xml The output as a JSON XML object.
*/ */
commandOutput: function commandOutput(xml) { commandOutput: function commandOutput(xml) {
if (!this.command) if (!this.command)

View File

@@ -216,22 +216,11 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
applyTriggerObserver: function triggerObserver(type, args) { applyTriggerObserver: function triggerObserver(type, args) {
if (type in this._observers) if (type in this._observers)
this._observers[type] = this._observers[type].filter(function (callback) { this._observers[type] = this._observers[type]
if (callback.get()) { .filter(callback => {
try { callback = callback.get();
try { if (callback)
callback.get().apply(null, args); util.trapErrors(() => callback.apply(null, args));
}
catch (e if e.message == "can't wrap XML objects") {
// Horrible kludge.
callback.get().apply(null, [String(args[0])].concat(args.slice(1)));
}
}
catch (e) {
dactyl.reportError(e);
}
return true;
}
}); });
}, },
@@ -1922,7 +1911,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
// dactyl.hideGUI(); // dactyl.hideGUI();
if (dactyl.userEval("typeof document", null, "test.js") === "undefined") if (dactyl.userEval("typeof document", null, "test.js") === "undefined")
jsmodules.__proto__ = XPCSafeJSObjectWrapper(window); jsmodules.__proto__ = window;
if (dactyl.commandLineOptions.preCommands) if (dactyl.commandLineOptions.preCommands)
dactyl.commandLineOptions.preCommands.forEach(function (cmd) { dactyl.commandLineOptions.preCommands.forEach(function (cmd) {

View File

@@ -1,6 +1,6 @@
// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org> // Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com> // Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com> // Copyright (c) 2008-2014 Kris Maglione <maglione.k@gmail.com>
// //
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.

View File

@@ -29,11 +29,6 @@ let { __lookupGetter__, __lookupSetter__, __defineGetter__, __defineSetter__,
hasOwnProperty = Function.call.bind(hasOwnProperty); hasOwnProperty = Function.call.bind(hasOwnProperty);
propertyIsEnumerable = Function.call.bind(propertyIsEnumerable); propertyIsEnumerable = Function.call.bind(propertyIsEnumerable);
if (typeof XPCSafeJSObjectWrapper === "undefined")
this.XPCSafeJSObjectWrapper = XPCNativeWrapper;
let getGlobalForObject = Cu.getGlobalForObject || (obj => obj.__parent__);
function require(module_, target) { function require(module_, target) {
if (/^[A-Za-z0-9]+:/.test(module_)) if (/^[A-Za-z0-9]+:/.test(module_))
return module(module_); return module(module_);
@@ -149,16 +144,55 @@ function require_(obj, name, from, targetName) {
defineModule("base", { defineModule("base", {
// sed -n 's/^(const|var|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt // sed -n 's/^(const|var|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt
exports: [ exports: [
"ErrorBase", "Cc", "Ci", "Class", "Cr", "Cs", "Cu", "Finished", "Cc",
"Module", "JSMLoader", "RealSet", "Set", "Struct", "StructBase", "Ci",
"Timer", "UTF8", "XPCOM", "XPCOMShim", "XPCOMUtils", "Class",
"XPCSafeJSObjectWrapper", "array", "bind", "call", "callable", "Cr",
"ctypes", "curry", "debuggerProperties", "defineModule", "Cs",
"deprecated", "endModule", "forEach", "hasOwnProperty", "Cu",
"isArray", "isGenerator", "isinstance", "isObject", "isString", "ErrorBase",
"isSubclass", "isXML", "iter", "iterAll", "iterOwnProperties", "Finished",
"keys", "literal", "memoize", "modujle", "octal", "properties", "JSMLoader",
"require", "set", "update", "values", "update_" "Module",
"RealSet",
"Set",
"Struct",
"StructBase",
"Timer",
"UTF8",
"XPCOM",
"XPCOMShim",
"XPCOMUtils",
"array",
"bind",
"call",
"callable",
"ctypes",
"curry",
"defineModule",
"deprecated",
"endModule",
"forEach",
"hasOwnProperty",
"isArray",
"isGenerator",
"isObject",
"isString",
"isSubclass",
"isinstance",
"iter",
"iterAll",
"iterOwnProperties",
"keys",
"literal",
"memoize",
"modujle",
"octal",
"properties",
"require",
"set",
"update",
"values",
] ]
}); });
@@ -200,25 +234,10 @@ function literal(/* comment */) {
}); });
} }
/**
* Returns a list of all of the top-level properties of an object, by
* way of the debugger.
*
* @param {object} obj
* @returns [jsdIProperty]
*/
function debuggerProperties(obj) {
if (loaded.services && services.debugger.isOn) {
let res = {};
services.debugger.wrapValue(obj).getProperties(res, {});
return res.value;
}
}
/** /**
* Iterates over the names of all of the top-level properties of an * Iterates over the names of all of the top-level properties of an
* object or, if prototypes is given, all of the properties in the * object or, if prototypes is given, all of the properties in the
* prototype chain below the top. Uses the debugger if possible. * prototype chain below the top.
* *
* @param {object} obj The object to inspect. * @param {object} obj The object to inspect.
* @param {boolean} properties Whether to inspect the prototype chain * @param {boolean} properties Whether to inspect the prototype chain
@@ -230,7 +249,7 @@ function prototype(obj)
XPCNativeWrapper.unwrap(obj).__proto__ || XPCNativeWrapper.unwrap(obj).__proto__ ||
Object.getPrototypeOf(XPCNativeWrapper.unwrap(obj)); Object.getPrototypeOf(XPCNativeWrapper.unwrap(obj));
function properties(obj, prototypes, debugger_) { function properties(obj, prototypes) {
let orig = obj; let orig = obj;
let seen = RealSet(["dactylPropertyNames"]); let seen = RealSet(["dactylPropertyNames"]);
@@ -277,13 +296,7 @@ function properties(obj, prototypes, debugger_) {
} }
for (; obj; obj = prototypes && prototype(obj)) { for (; obj; obj = prototypes && prototype(obj)) {
try { var iter = (v for each (v in props(obj)));
if (!debugger_ || !services.debugger.isOn)
var iter = (v for each (v in props(obj)));
}
catch (e) {}
if (!iter)
iter = (prop.name.stringValue for (prop in values(debuggerProperties(obj))));
for (let key in iter) for (let key in iter)
if (!prototypes || !seen.has(key) && obj != orig) { if (!prototypes || !seen.has(key) && obj != orig) {
@@ -602,23 +615,13 @@ function isinstance(object, interfaces) {
*/ */
function isObject(obj) typeof obj === "object" && obj != null || obj instanceof Ci.nsISupports; function isObject(obj) typeof obj === "object" && obj != null || obj instanceof Ci.nsISupports;
/**
* Returns true if obje is an E4X XML object.
* @deprecated
*/
function isXML(obj) typeof obj === "xml";
/** /**
* Returns true if and only if its sole argument is an * Returns true if and only if its sole argument is an
* instance of the builtin Array type. The array may come from * instance of the builtin Array type. The array may come from
* 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).
*/ */
var isArray = var { isArray } = Array;
Array.isArray
// This is bloody stupid.
? function isArray(val) Array.isArray(val) || val && val.constructor && val.constructor.name === "Array"
: function isArray(val) objproto.toString.call(val) == "[object Array]";
/** /**
* Returns true if and only if its sole argument is an * Returns true if and only if its sole argument is an
@@ -740,33 +743,6 @@ function update(target) {
} }
return target; return target;
} }
function update_(target) {
for (let i = 1; i < arguments.length; i++) {
let src = arguments[i];
Object.getOwnPropertyNames(src || {}).forEach(function (k) {
let desc = Object.getOwnPropertyDescriptor(src, k);
if (desc.value instanceof Class.Property)
desc = desc.value.init(k, target) || desc.value;
try {
if (typeof desc.value === "function" && target.__proto__ && !(desc.value instanceof Ci.nsIDOMElement /* wtf? */)) {
let func = desc.value.wrapped || desc.value;
if (!func.superapply) {
func.__defineGetter__("super", function get_super_() Object.getPrototypeOf(target)[k]);
func.superapply = function super_apply(self, args)
let (meth = Object.getPrototypeOf(target)[k])
meth && meth.apply(self, args);
func.supercall = function super_call(self, ...args)
func.superapply(self, args);
}
}
Object.defineProperty(target, k, desc);
}
catch (e) {}
});
}
return target;
}
/** /**
* @constructor Class * @constructor Class
@@ -812,8 +788,10 @@ function Class(...args) {
return res !== undefined ? res : self; \n\ return res !== undefined ? res : self; \n\
})', })',
"constructor", (name || superclass.className).replace(/\W/g, "_")) "constructor", (name || superclass.className).replace(/\W/g, "_"))
.replace("PARAMS", /^function .*?\((.*?)\)/.exec(args[0] && args[0].init || Class.prototype.init)[1] .replace("PARAMS",
.replace(/\b(self|res|Constructor)\b/g, "$1_"))); /^function .*?\((.*?)\)/
.exec(args[0] && args[0].init || Class.prototype.init)[1]
.replace(/\b(self|res|Constructor)\b/g, "$1_")));
Constructor.className = name || superclass.className || superclass.name; Constructor.className = name || superclass.className || superclass.name;
@@ -842,21 +820,14 @@ function Class(...args) {
return Constructor; return Constructor;
} }
if (Cu.getGlobalForObject) Class.objectGlobal = function (object) {
Class.objectGlobal = function (object) { try {
try { return Cu.getGlobalForObject(object);
return Cu.getGlobalForObject(object); }
} catch (e) {
catch (e) { return null;
return null; }
} };
};
else
Class.objectGlobal = function (object) {
while (object.__parent__)
object = object.__parent__;
return object;
};
/** /**
* @class Class.Property * @class Class.Property
@@ -1089,7 +1060,6 @@ Class.makeClosure = function makeClosure() {
return _closure; return _closure;
} }
let x = /commandline/i.test(this);
iter(properties(this), properties(this, true)).forEach(function (k) { iter(properties(this), properties(this, true)).forEach(function (k) {
if (!__lookupGetter__.call(this, k) && callable(this[k])) if (!__lookupGetter__.call(this, k) && callable(this[k]))
closure[k] = closure(this[k]); closure[k] = closure(this[k]);

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2011-2012 Kris Maglione <maglione.k@gmail.com> // Copyright (c) 2011-2014 Kris Maglione <maglione.k@gmail.com>
// //
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
@@ -6,8 +6,8 @@
var EXPORTED_SYMBOLS = ["require"]; var EXPORTED_SYMBOLS = ["require"];
// Deal with cross-compartment XML passing issues.
function create(proto) Object.create(proto); function create(proto) Object.create(proto);
this["import"] = function import_(obj) { this["import"] = function import_(obj) {
let res = {}; let res = {};
for each (let key in Object.getOwnPropertyNames(obj)) for each (let key in Object.getOwnPropertyNames(obj))

View File

@@ -480,14 +480,8 @@ var Contexts = Module("contexts", {
getDocs: function getDocs(context) { getDocs: function getDocs(context) {
try { try {
if (isinstance(context, ["Sandbox"])) {
let info = "INFO" in context && Cu.evalInSandbox("this.INFO instanceof XML ? INFO.toXMLString() : this.INFO", context);
return /^</.test(info) ? XML(info) : info;
}
if (DOM.isJSONXML(context.INFO)) if (DOM.isJSONXML(context.INFO))
return context.INFO; return context.INFO;
if (typeof context.INFO == "xml" && config.haveGecko(null, "14.*"))
return context.INFO;
} }
catch (e) {} catch (e) {}
return null; return null;

View File

@@ -1,54 +0,0 @@
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2012 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.
/* use strict */
defineModule("dom", {
exports: ["fromXML"]
});
lazyRequire("highlight", ["highlight"]);
var XBL = Namespace("xbl", "http://www.mozilla.org/xbl");
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 NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator");
function fromXML(node, doc, nodes) {
XML.ignoreWhitespace = XML.prettyPrinting = false;
if (typeof node === "string") // Sandboxes can't currently pass us XML objects.
node = XML(node);
if (node.length() != 1) {
let domnode = doc.createDocumentFragment();
for each (let child in node)
domnode.appendChild(fromXML(child, doc, nodes));
return domnode;
}
switch (node.nodeKind()) {
case "text":
return doc.createTextNode(String(node));
case "element":
let domnode = doc.createElementNS(node.namespace(), node.localName());
for each (let attr in node.@*::*)
if (attr.name() != "highlight")
domnode.setAttributeNS(attr.namespace(), attr.localName(), String(attr));
for each (let child in node.*::*)
domnode.appendChild(fromXML(child, doc, nodes));
if (nodes && node.@key)
nodes[node.@key] = domnode;
if ("@highlight" in node)
highlight.highlightNode(domnode, String(node.@highlight), nodes || true);
return domnode;
default:
return null;
}
}
// vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript:

View File

@@ -55,8 +55,6 @@ var DOM = Class("DOM", {
if (val == null) if (val == null)
; ;
else if (typeof val == "xml" && context instanceof Ci.nsIDOMDocument)
this[length++] = DOM.fromXML(val, context, this.nodes);
else if (DOM.isJSONXML(val)) { else if (DOM.isJSONXML(val)) {
if (context instanceof Ci.nsIDOMDocument) if (context instanceof Ci.nsIDOMDocument)
this[length++] = DOM.fromJSON(val, context, this.nodes); this[length++] = DOM.fromJSON(val, context, this.nodes);
@@ -1510,21 +1508,6 @@ var DOM = Class("DOM", {
return str.replace(regexp, m => map[m]); return str.replace(regexp, m => map[m]);
}, },
/**
* Converts an E4X XML literal to a DOM node. Any attribute named
* highlight is present, it is transformed into dactyl:highlight,
* and the named highlight groups are guaranteed to be loaded.
*
* @param {Node} node
* @param {Document} doc
* @param {Object} nodes If present, nodes with the "key" attribute are
* stored here, keyed to the value thereof.
* @returns {Node}
*/
fromXML: deprecated("DOM.fromJSON", { get: function fromXML()
prefs.get("javascript.options.xml.chrome") !== false
&& require("dom-e4x").fromXML }),
fromJSON: update(function fromJSON(xml, doc, nodes, namespaces) { fromJSON: update(function fromJSON(xml, doc, nodes, namespaces) {
if (!doc) if (!doc)
doc = document; doc = document;
@@ -1540,8 +1523,6 @@ var DOM = Class("DOM", {
if (isinstance(args, ["String", "Number", "Boolean", _])) if (isinstance(args, ["String", "Number", "Boolean", _]))
return doc.createTextNode(args); return doc.createTextNode(args);
if (isXML(args))
return DOM.fromXML(args, doc, nodes);
if (isObject(args) && "toDOM" in args) if (isObject(args) && "toDOM" in args)
return args.toDOM(doc, namespaces, nodes); return args.toDOM(doc, namespaces, nodes);
if (args instanceof Ci.nsIDOMNode) if (args instanceof Ci.nsIDOMNode)
@@ -1666,11 +1647,6 @@ var DOM = Class("DOM", {
return indent + return indent +
DOM.escapeHTML(String(args), true); DOM.escapeHTML(String(args), true);
if (isXML(args))
return indent +
args.toXMLString()
.replace(/^/m, indent);
if (isObject(args) && "toDOM" in args) if (isObject(args) && "toDOM" in args)
return indent + return indent +
services.XMLSerializer() services.XMLSerializer()

View File

@@ -81,7 +81,7 @@ var JavaScript = Module("javascript", {
yield "wrappedJSObject"; yield "wrappedJSObject";
} }
for (let key in iter(globals, properties(obj, !toplevel, true))) for (let key in iter(globals, properties(obj, !toplevel)))
if (!seen.has(key)) { if (!seen.has(key)) {
seen.add(key); seen.add(key);
yield key; yield key;
@@ -89,7 +89,8 @@ var JavaScript = Module("javascript", {
// Properties aren't visible in an XPCNativeWrapper until // Properties aren't visible in an XPCNativeWrapper until
// they're accessed. // they're accessed.
for (let key in properties(this.getKey(obj, "wrappedJSObject"), !toplevel, true)) for (let key in properties(this.getKey(obj, "wrappedJSObject"),
!toplevel))
try { try {
if (key in obj && !seen.has(key)) { if (key in obj && !seen.has(key)) {
seen.add(key); seen.add(key);
@@ -638,7 +639,7 @@ var JavaScript = Module("javascript", {
"ROCSSPrimitiveValue", "RangeError", "ReferenceError", "RegExp", "ROCSSPrimitiveValue", "RangeError", "ReferenceError", "RegExp",
"StopIteration", "String", "SyntaxError", "TypeError", "URIError", "StopIteration", "String", "SyntaxError", "TypeError", "URIError",
"Uint16Array", "Uint32Array", "Uint8Array", "XML", "XMLHttpProgressEvent", "Uint16Array", "Uint32Array", "Uint8Array", "XML", "XMLHttpProgressEvent",
"XMLList", "XMLSerializer", "XPCNativeWrapper", "XPCSafeJSWrapper", "XMLList", "XMLSerializer", "XPCNativeWrapper",
"XULControllers", "constructor", "decodeURI", "decodeURIComponent", "XULControllers", "constructor", "decodeURI", "decodeURIComponent",
"encodeURI", "encodeURIComponent", "escape", "eval", "isFinite", "isNaN", "encodeURI", "encodeURIComponent", "escape", "eval", "isFinite", "isNaN",
"isXMLName", "parseFloat", "parseInt", "undefined", "unescape", "uneval" "isXMLName", "parseFloat", "parseInt", "undefined", "unescape", "uneval"

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2009-2013 Kris Maglione <maglione.k@gmail.com> // Copyright (c) 2009-2014 Kris Maglione <maglione.k@gmail.com>
// //
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
@@ -240,16 +240,12 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
if (elem = doc.getElementById(String(elem))) { if (elem = doc.getElementById(String(elem))) {
// Urgh. Hack. // Urgh. Hack.
let namespaces; let namespaces;
if (attrs && !isXML(attrs)) if (attrs)
namespaces = iter([k.slice(6), DOM.fromJSON.namespaces[v] || v] namespaces = iter([k.slice(6), DOM.fromJSON.namespaces[v] || v]
for ([k, v] in Iterator(attrs)) for ([k, v] in Iterator(attrs))
if (/^xmlns(?:$|:)/.test(k))).toObject(); if (/^xmlns(?:$|:)/.test(k))).toObject();
let node; let node = DOM.fromJSON(xml, doc, obj.objects, namespaces);
if (isXML(xml))
node = DOM.fromXML(xml, doc, obj.objects);
else
node = DOM.fromJSON(xml, doc, obj.objects, namespaces);
if (!(node instanceof Ci.nsIDOMDocumentFragment)) if (!(node instanceof Ci.nsIDOMDocumentFragment))
savedElems.push(node); savedElems.push(node);
@@ -259,12 +255,6 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
fn(elem, node); fn(elem, node);
if (isXML(attrs))
// Evilness and such.
let (oldAttrs = attrs) {
attrs = (attr for each (attr in oldAttrs));
}
for (let attr in attrs || []) { for (let attr in attrs || []) {
let [ns, localName] = DOM.parseNamespace(attr); let [ns, localName] = DOM.parseNamespace(attr);
let name = attr; let name = attr;

View File

@@ -1246,7 +1246,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* *
* This is similar to Perl's extended regular expression format. * This is similar to Perl's extended regular expression format.
* *
* @param {string|XML} expr The expression to compile into a RegExp. * @param {string} expr The expression to compile into a RegExp.
* @param {string} flags Flags to apply to the new RegExp. * @param {string} flags Flags to apply to the new RegExp.
* @param {object} tokens The tokens to substitute. @optional * @param {object} tokens The tokens to substitute. @optional
* @returns {RegExp} A custom regexp object. * @returns {RegExp} A custom regexp object.