From 057600d780c8d87f9314051667b085c4f0c07618 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 17 Sep 2011 00:08:02 -0400 Subject: [PATCH] Fix :js context on Minefield. --- common/content/dactyl.js | 5 ++++- common/content/editor.js | 3 +++ common/content/events.js | 41 +++++++++++++++++++++++++---------- common/content/modes.js | 11 ++++++++++ common/modules/dom.jsm | 12 ++++++++-- common/modules/javascript.jsm | 2 +- common/modules/util.jsm | 12 ++++++---- 7 files changed, 66 insertions(+), 20 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 1cb3aa3f..26029ea8 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -475,7 +475,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { userEval: function (str, context, fileName, lineNumber) { let ctxt; - if (jsmodules.__proto__ != window) + if (jsmodules.__proto__ != window && jsmodules.__proto__ != XPCNativeWrapper(window) && + jsmodules.isPrototypeOf(context)) str = "with (window) { with (modules) { (this.eval || eval)(" + str.quote() + ") } }"; let info = contexts.context; @@ -1218,8 +1219,10 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { util.reportError(error); return; } + if (error.result == Cr.NS_BINDING_ABORTED) return; + if (echo) dactyl.echoerr(error, commandline.FORCE_SINGLELINE); else diff --git a/common/content/editor.js b/common/content/editor.js index 560bd9d6..1ae532bd 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -187,6 +187,9 @@ var Editor = Module("editor", { return; let textBox = config.isComposeWindow ? null : dactyl.focusedElement; + if (!DOM(textBox).isInput) + textBox = null; + let line, column; let keepFocus = modes.stack.some(function (m) isinstance(m.main, modes.COMMAND_LINE)); diff --git a/common/content/events.js b/common/content/events.js index bc04e386..31563e40 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -22,6 +22,18 @@ var EventHive = Class("EventHive", Contexts.Hive, { this.unlisten(null); }, + _events: function _events(event, callback) { + if (!isObject(event)) + var [self, events] = [null, array.toObject([[event, callback]])]; + else + [self, events] = [event, event[callback || "events"]]; + + if (Set.has(events, "input") && !Set.has(events, "dactyl-input")) + events["dactyl-input"] = events.input; + + return [self, events]; + }, + /** * Adds an event listener for this session and removes it on * dactyl shutdown. @@ -35,22 +47,17 @@ var EventHive = Class("EventHive", Contexts.Hive, { * untrusted events. */ listen: function (target, event, callback, capture, allowUntrusted) { - if (!isObject(event)) - var [self, events] = [null, array.toObject([[event, callback]])]; - else - [self, events] = [event, event[callback || "events"]]; - - if (Set.has(events, "input") && !Set.has(events, "dactyl-input")) - events["dactyl-input"] = events.input; + var [self, events] = this._events(event, callback); for (let [event, callback] in Iterator(events)) { let args = [Cu.getWeakReference(target), + self ? Cu.getWeakReference(self) : { get: function () null }, event, this.wrapListener(callback, self), capture, allowUntrusted]; - target.addEventListener.apply(target, args.slice(1)); + target.addEventListener.apply(target, args.slice(2)); this.sessionListeners.push(args); } }, @@ -65,12 +72,21 @@ var EventHive = Class("EventHive", Contexts.Hive, { * phase, otherwise during the bubbling phase. */ unlisten: function (target, event, callback, capture) { + if (target != null) + var [self, events] = this._events(event, callback); + this.sessionListeners = this.sessionListeners.filter(function (args) { - if (target == null || args[0].get() == target && args[1] == event && args[2].wrapped == callback && args[3] == capture) { - args[0].get().removeEventListener.apply(args[0].get(), args.slice(1)); + let elem = args[0].get(); + if (target == null || elem == target + && self == args[1].get() + && Set.has(events, args[2]) + && args[3].wrapped == events[args[2]] + && args[4] == capture) { + + elem.removeEventListener.apply(elem, args.slice(2)); return false; } - return !args[0].get(); + return elem; }); }, @@ -192,7 +208,8 @@ var Events = Module("events", { */ wrapListener: function wrapListener(method, self) { self = self || this; - method.wrapped = wrappedListener; + method.wrapper = wrappedListener; + wrappedListener.wrapped = method; function wrappedListener(event) { try { method.apply(self, arguments); diff --git a/common/content/modes.js b/common/content/modes.js index a29b36b1..d097f108 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -307,6 +307,17 @@ var Modes = Module("modes", { dactyl.triggerObserver("modes.add", mode); }, + removeMode: function removeMode(mode) { + if (this[mode.name] == mode) + delete this[mode.name]; + if (this._modeMap[mode.name] == mode) + delete this._modeMap[mode.name]; + if (this._modeMap[mode.mode] == mode) + delete this._modeMap[mode.mode]; + + this._mainModes = this._mainModes.filter(function (m) m != mode); + }, + dumpStack: function dumpStack() { util.dump("Mode stack:"); for (let [i, mode] in array.iterItems(this._modeStack)) diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index d90af730..e525a008 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -1399,18 +1399,26 @@ var DOM = Class("DOM", { * @param {Node} elem The context element. * @param {boolean} asIterator Whether to return the results as an * XPath iterator. + * @param {object} namespaces Additional namespaces to recognize. + * @optional * @returns {Object} Iterable result of the evaluation. */ XPath: update( - function XPath(expression, elem, asIterator) { + function XPath(expression, elem, asIterator, namespaces) { try { let doc = elem.ownerDocument || elem; if (isArray(expression)) expression = DOM.makeXPath(expression); + let resolver = XPath.resolver; + if (namespaces) { + namespaces = update({}, DOM.namespaces, namespaces); + resolver = function (prefix) namespaces[prefix] || null; + } + let result = doc.evaluate(expression, elem, - XPath.resolver, + resolver, asIterator ? Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE : Ci.nsIDOMXPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index d1e92337..412f2fe0 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -717,7 +717,7 @@ var JavaScript = Module("javascript", { try { var result = dactyl.userEval(js, this.context); - var xml = util.objectToString(result, true); + var xml = result === undefined ? "" : util.objectToString(result, true); } catch (e) { util.reportError(e); diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 07027705..711a8f97 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -823,11 +823,15 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @returns {nsIURI} */ newURI: function newURI(uri, charset, base) { - let idx = uri.lastIndexOf(" -> "); - if (~idx) - uri = uri.slice(idx + 4); + if (uri instanceof Ci.nsIURI) + var res = uri.clone(); + else { + let idx = uri.lastIndexOf(" -> "); + if (~idx) + uri = uri.slice(idx + 4); - let res = this.withProperErrors("newURI", services.io, uri, charset, base); + res = this.withProperErrors("newURI", services.io, uri, charset, base); + } res instanceof Ci.nsIURL; return res; },