1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-28 18:42:28 +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
* 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) {
if (!this.command)

View File

@@ -216,22 +216,11 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
applyTriggerObserver: function triggerObserver(type, args) {
if (type in this._observers)
this._observers[type] = this._observers[type].filter(function (callback) {
if (callback.get()) {
try {
try {
callback.get().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;
}
this._observers[type] = this._observers[type]
.filter(callback => {
callback = callback.get();
if (callback)
util.trapErrors(() => callback.apply(null, args));
});
},
@@ -1922,7 +1911,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
// dactyl.hideGUI();
if (dactyl.userEval("typeof document", null, "test.js") === "undefined")
jsmodules.__proto__ = XPCSafeJSObjectWrapper(window);
jsmodules.__proto__ = window;
if (dactyl.commandLineOptions.preCommands)
dactyl.commandLineOptions.preCommands.forEach(function (cmd) {

View File

@@ -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-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
// 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);
propertyIsEnumerable = Function.call.bind(propertyIsEnumerable);
if (typeof XPCSafeJSObjectWrapper === "undefined")
this.XPCSafeJSObjectWrapper = XPCNativeWrapper;
let getGlobalForObject = Cu.getGlobalForObject || (obj => obj.__parent__);
function require(module_, target) {
if (/^[A-Za-z0-9]+:/.test(module_))
return module(module_);
@@ -149,16 +144,55 @@ function require_(obj, name, from, targetName) {
defineModule("base", {
// sed -n 's/^(const|var|function) ([a-zA-Z0-9_]+).*/ "\2",/p' base.jsm | sort | fmt
exports: [
"ErrorBase", "Cc", "Ci", "Class", "Cr", "Cs", "Cu", "Finished",
"Module", "JSMLoader", "RealSet", "Set", "Struct", "StructBase",
"Timer", "UTF8", "XPCOM", "XPCOMShim", "XPCOMUtils",
"XPCSafeJSObjectWrapper", "array", "bind", "call", "callable",
"ctypes", "curry", "debuggerProperties", "defineModule",
"deprecated", "endModule", "forEach", "hasOwnProperty",
"isArray", "isGenerator", "isinstance", "isObject", "isString",
"isSubclass", "isXML", "iter", "iterAll", "iterOwnProperties",
"keys", "literal", "memoize", "modujle", "octal", "properties",
"require", "set", "update", "values", "update_"
"Cc",
"Ci",
"Class",
"Cr",
"Cs",
"Cu",
"ErrorBase",
"Finished",
"JSMLoader",
"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
* 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 {boolean} properties Whether to inspect the prototype chain
@@ -230,7 +249,7 @@ function prototype(obj)
XPCNativeWrapper.unwrap(obj).__proto__ ||
Object.getPrototypeOf(XPCNativeWrapper.unwrap(obj));
function properties(obj, prototypes, debugger_) {
function properties(obj, prototypes) {
let orig = obj;
let seen = RealSet(["dactylPropertyNames"]);
@@ -277,13 +296,7 @@ function properties(obj, prototypes, debugger_) {
}
for (; obj; obj = prototypes && prototype(obj)) {
try {
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))));
var iter = (v for each (v in props(obj)));
for (let key in iter)
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;
/**
* 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
* instance of the builtin Array type. The array may come from
* any window, frame, namespace, or execution context, which
* is not the case when using (obj instanceof Array).
*/
var isArray =
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]";
var { isArray } = Array;
/**
* Returns true if and only if its sole argument is an
@@ -740,33 +743,6 @@ function update(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
@@ -812,8 +788,10 @@ function Class(...args) {
return res !== undefined ? res : self; \n\
})',
"constructor", (name || superclass.className).replace(/\W/g, "_"))
.replace("PARAMS", /^function .*?\((.*?)\)/.exec(args[0] && args[0].init || Class.prototype.init)[1]
.replace(/\b(self|res|Constructor)\b/g, "$1_")));
.replace("PARAMS",
/^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;
@@ -842,21 +820,14 @@ function Class(...args) {
return Constructor;
}
if (Cu.getGlobalForObject)
Class.objectGlobal = function (object) {
try {
return Cu.getGlobalForObject(object);
}
catch (e) {
return null;
}
};
else
Class.objectGlobal = function (object) {
while (object.__parent__)
object = object.__parent__;
return object;
};
Class.objectGlobal = function (object) {
try {
return Cu.getGlobalForObject(object);
}
catch (e) {
return null;
}
};
/**
* @class Class.Property
@@ -1089,7 +1060,6 @@ Class.makeClosure = function makeClosure() {
return _closure;
}
let x = /commandline/i.test(this);
iter(properties(this), properties(this, true)).forEach(function (k) {
if (!__lookupGetter__.call(this, k) && callable(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
// given in the LICENSE.txt file included with this file.
@@ -6,8 +6,8 @@
var EXPORTED_SYMBOLS = ["require"];
// Deal with cross-compartment XML passing issues.
function create(proto) Object.create(proto);
this["import"] = function import_(obj) {
let res = {};
for each (let key in Object.getOwnPropertyNames(obj))

View File

@@ -480,14 +480,8 @@ var Contexts = Module("contexts", {
getDocs: function getDocs(context) {
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))
return context.INFO;
if (typeof context.INFO == "xml" && config.haveGecko(null, "14.*"))
return context.INFO;
}
catch (e) {}
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)
;
else if (typeof val == "xml" && context instanceof Ci.nsIDOMDocument)
this[length++] = DOM.fromXML(val, context, this.nodes);
else if (DOM.isJSONXML(val)) {
if (context instanceof Ci.nsIDOMDocument)
this[length++] = DOM.fromJSON(val, context, this.nodes);
@@ -1510,21 +1508,6 @@ var DOM = Class("DOM", {
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) {
if (!doc)
doc = document;
@@ -1540,8 +1523,6 @@ var DOM = Class("DOM", {
if (isinstance(args, ["String", "Number", "Boolean", _]))
return doc.createTextNode(args);
if (isXML(args))
return DOM.fromXML(args, doc, nodes);
if (isObject(args) && "toDOM" in args)
return args.toDOM(doc, namespaces, nodes);
if (args instanceof Ci.nsIDOMNode)
@@ -1666,11 +1647,6 @@ var DOM = Class("DOM", {
return indent +
DOM.escapeHTML(String(args), true);
if (isXML(args))
return indent +
args.toXMLString()
.replace(/^/m, indent);
if (isObject(args) && "toDOM" in args)
return indent +
services.XMLSerializer()

View File

@@ -81,7 +81,7 @@ var JavaScript = Module("javascript", {
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)) {
seen.add(key);
yield key;
@@ -89,7 +89,8 @@ var JavaScript = Module("javascript", {
// Properties aren't visible in an XPCNativeWrapper until
// 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 {
if (key in obj && !seen.has(key)) {
seen.add(key);
@@ -638,7 +639,7 @@ var JavaScript = Module("javascript", {
"ROCSSPrimitiveValue", "RangeError", "ReferenceError", "RegExp",
"StopIteration", "String", "SyntaxError", "TypeError", "URIError",
"Uint16Array", "Uint32Array", "Uint8Array", "XML", "XMLHttpProgressEvent",
"XMLList", "XMLSerializer", "XPCNativeWrapper", "XPCSafeJSWrapper",
"XMLList", "XMLSerializer", "XPCNativeWrapper",
"XULControllers", "constructor", "decodeURI", "decodeURIComponent",
"encodeURI", "encodeURIComponent", "escape", "eval", "isFinite", "isNaN",
"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
// 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))) {
// Urgh. Hack.
let namespaces;
if (attrs && !isXML(attrs))
if (attrs)
namespaces = iter([k.slice(6), DOM.fromJSON.namespaces[v] || v]
for ([k, v] in Iterator(attrs))
if (/^xmlns(?:$|:)/.test(k))).toObject();
let node;
if (isXML(xml))
node = DOM.fromXML(xml, doc, obj.objects);
else
node = DOM.fromJSON(xml, doc, obj.objects, namespaces);
let node = DOM.fromJSON(xml, doc, obj.objects, namespaces);
if (!(node instanceof Ci.nsIDOMDocumentFragment))
savedElems.push(node);
@@ -259,12 +255,6 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
fn(elem, node);
if (isXML(attrs))
// Evilness and such.
let (oldAttrs = attrs) {
attrs = (attr for each (attr in oldAttrs));
}
for (let attr in attrs || []) {
let [ns, localName] = DOM.parseNamespace(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.
*
* @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 {object} tokens The tokens to substitute. @optional
* @returns {RegExp} A custom regexp object.