mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-28 04:52:28 +01:00
Fix some CPOW issues. Everything is still terrible, though.
This commit is contained in:
@@ -275,6 +275,8 @@ literal.locations = literal_.locations;
|
||||
function apply(obj, meth, args) {
|
||||
// The function's own apply method breaks in strange ways
|
||||
// when using CPOWs.
|
||||
if (callable(meth))
|
||||
return Function.apply.call(meth, obj, args);
|
||||
return Function.apply.call(obj[meth], obj, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ lazyRequire("promises", ["CancelablePromise", "Promise", "promises"]);
|
||||
lazyRequire("sanitizer", ["sanitizer"]);
|
||||
lazyRequire("storage", ["File", "storage"]);
|
||||
lazyRequire("template", ["template"]);
|
||||
|
||||
let global = this;
|
||||
/**
|
||||
* A class to manage the primary web content buffer. The name comes
|
||||
* from Vim's term, 'buffer', which signifies instances of open
|
||||
@@ -30,14 +30,17 @@ lazyRequire("template", ["template"]);
|
||||
*/
|
||||
var Buffer = Module("Buffer", {
|
||||
Local: function Local(dactyl, modules, window) {
|
||||
let gBrowser = window.gBrowser;
|
||||
return {
|
||||
get win() { return window.content; }
|
||||
get browser() { return gBrowser.mCurrentBrowser; },
|
||||
};
|
||||
},
|
||||
|
||||
init: function init(win) {
|
||||
init: function init(win, browser) {
|
||||
if (win)
|
||||
this.win = win;
|
||||
if (browser)
|
||||
this.browser = browser;
|
||||
},
|
||||
|
||||
get addPageInfoSection() { return Buffer.bound.addPageInfoSection; },
|
||||
@@ -66,7 +69,9 @@ var Buffer = Module("Buffer", {
|
||||
/**
|
||||
* The load context of the window bound to this buffer.
|
||||
*/
|
||||
get loadContext() { return sanitizer.getContext(this.win); },
|
||||
get loadContext() {
|
||||
return sanitizer.getContext(this.win, this.topWindow);
|
||||
},
|
||||
|
||||
/**
|
||||
* Content preference methods.
|
||||
@@ -243,24 +248,62 @@ var Buffer = Module("Buffer", {
|
||||
},
|
||||
set lastInputField(value) { this.localStore.lastInputField = util.weakReference(value); },
|
||||
|
||||
get win() {
|
||||
if (this.browser)
|
||||
return this.browser.contentWindow;
|
||||
return this._win;
|
||||
},
|
||||
|
||||
set win(value) {
|
||||
this._win = value;
|
||||
},
|
||||
|
||||
/**
|
||||
* @property {nsIURI} The current top-level document.
|
||||
*/
|
||||
get doc() { return this.win.document; },
|
||||
get doc() {
|
||||
if (this.browser)
|
||||
return this.browser.contentDocument;
|
||||
return this.win.document;
|
||||
},
|
||||
|
||||
get docShell() { return util.docShell(this.win); },
|
||||
get docShell() {
|
||||
let docShell;
|
||||
if (this.browser)
|
||||
docShell = this.browser.docShell;
|
||||
|
||||
if (!docShell && this.win && this.win.QueryInterface)
|
||||
docShell = util.docShell(this.win);
|
||||
|
||||
return docShell;
|
||||
},
|
||||
|
||||
get webNav() {
|
||||
if (this.browser)
|
||||
return this.browser.webNavigation;
|
||||
|
||||
return this.docShell.QueryInterface(Ci.nsIWebNavigation);
|
||||
},
|
||||
|
||||
get modules() { return this.topWindow.dactyl.modules; },
|
||||
set modules(val) {},
|
||||
|
||||
topWindow: Class.Memoize(function () {
|
||||
if (this.browser)
|
||||
return this.browser.ownerDocument.defaultView;
|
||||
|
||||
return util.topWindow(this.win);
|
||||
}),
|
||||
|
||||
/**
|
||||
* @property {nsIURI} The current top-level document's URI.
|
||||
*/
|
||||
get uri() { return util.newURI(this.win.location.href); },
|
||||
get uri() {
|
||||
if (this.browser)
|
||||
return this.browser.currentURI.clone();
|
||||
|
||||
return util.newURI(this.win.location.href);
|
||||
},
|
||||
|
||||
/**
|
||||
* @property {nsIURI} The current top-level document's URI, sans
|
||||
@@ -278,16 +321,20 @@ var Buffer = Module("Buffer", {
|
||||
* fragment identifier.
|
||||
*/
|
||||
get documentURI() {
|
||||
return this.doc.documentURIObject ||
|
||||
util.newURI(this.doc.documentURI);
|
||||
if (this.browser)
|
||||
return this.browser.documentURI.clone();
|
||||
|
||||
return this.uri.cloneIgnoringRef();
|
||||
},
|
||||
|
||||
/**
|
||||
* @property {string} The current top-level document's URL.
|
||||
*/
|
||||
get URL() {
|
||||
return update(new String(this.win.location.href),
|
||||
util.newURI(this.win.location.href));
|
||||
let uri = this.browser ? this.browser.currentURI
|
||||
: util.newURI(this.win.location.href);
|
||||
|
||||
return update(new String(uri.spec), uri);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -296,6 +343,9 @@ var Buffer = Module("Buffer", {
|
||||
get pageHeight() { return this.win.innerHeight; },
|
||||
|
||||
get contentViewer() {
|
||||
if (!this.win || Cu.isCrossProcessWrapper(this.win) || !this.docShell)
|
||||
return null; // e10s
|
||||
|
||||
return this.docShell.contentViewer
|
||||
.QueryInterface(Ci.nsIMarkupDocumentViewer ||
|
||||
Ci.nsIContentViewer);
|
||||
@@ -307,6 +357,9 @@ var Buffer = Module("Buffer", {
|
||||
*/
|
||||
get zoomLevel() {
|
||||
let v = this.contentViewer;
|
||||
if (v == null)
|
||||
return this.ZoomManager.zoom * 100;
|
||||
|
||||
return v[v.textZoom == 1 ? "fullZoom" : "textZoom"] * 100;
|
||||
},
|
||||
set zoomLevel(value) { this.setZoom(value, this.fullZoom); },
|
||||
@@ -323,7 +376,12 @@ var Buffer = Module("Buffer", {
|
||||
/**
|
||||
* @property {string} The current document's title.
|
||||
*/
|
||||
get title() { return this.doc.title; },
|
||||
get title() {
|
||||
if (this.browser)
|
||||
return this.browser.contentTitle;
|
||||
|
||||
return this.doc.title;
|
||||
},
|
||||
|
||||
/**
|
||||
* @property {number} The buffer's horizontal scroll percentile.
|
||||
@@ -370,11 +428,21 @@ var Buffer = Module("Buffer", {
|
||||
* @property {Window} Returns the currently focused frame.
|
||||
*/
|
||||
get focusedFrame() {
|
||||
try {
|
||||
if (Cu.isCrossProcessWrapper(this.win))
|
||||
return this.win;
|
||||
} catch (e) {
|
||||
util.dump("WTF: " + e);
|
||||
util.dump(this.win, this.browser);
|
||||
return this.win;
|
||||
}
|
||||
|
||||
let frame = this.localStore.focusedFrame;
|
||||
return frame && frame.get() || this.win;
|
||||
},
|
||||
set focusedFrame(frame) {
|
||||
this.localStore.focusedFrame = util.weakReference(frame);
|
||||
if (!Cu.isCrossProcessWrapper(this.win))
|
||||
this.localStore.focusedFrame = util.weakReference(frame);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -2652,10 +2720,18 @@ var Buffer = Module("Buffer", {
|
||||
"boolean", false,
|
||||
{
|
||||
setter: function (value) {
|
||||
return buffer.contentViewer.authorStyleDisabled = value;
|
||||
let { contentViewer } = buffer;
|
||||
|
||||
if (contentViewer)
|
||||
return contentViewer.authorStyleDisabled = value;
|
||||
return false;
|
||||
},
|
||||
getter: function () {
|
||||
return buffer.contentViewer.authorStyleDisabled;
|
||||
let { contentViewer } = buffer;
|
||||
|
||||
if (contentViewer)
|
||||
return contentViewer.authorStyleDisabled;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ var Cache = Module("Cache", XPCOM(Ci.nsIRequestObserver), {
|
||||
},
|
||||
|
||||
parse: function parse(str) {
|
||||
if ('{['.contains(str[0]))
|
||||
if ('{['.includes(str[0]))
|
||||
return JSON.parse(str);
|
||||
return str;
|
||||
},
|
||||
|
||||
@@ -620,7 +620,7 @@ var CompletionContext = Class("CompletionContext", {
|
||||
var substrings = [text];
|
||||
}
|
||||
else {
|
||||
var compare = function compare(text, s) { return text.contains(s); };
|
||||
var compare = function compare(text, s) { return text.includes(s); };
|
||||
var substrings = [];
|
||||
let start = 0;
|
||||
let idx;
|
||||
@@ -1169,7 +1169,7 @@ var Completion = Module("completion", {
|
||||
if (context.ignoreCase) {
|
||||
compare = util.compareIgnoreCase;
|
||||
contains = function contains_(a, b) {
|
||||
return a && a.toLowerCase().contains(b.toLowerCase());
|
||||
return a && a.toLowerCase().includes(b.toLowerCase());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -409,7 +409,9 @@ var Contexts = Module("contexts", {
|
||||
return frame;
|
||||
},
|
||||
|
||||
groups: Class.Memoize(function () { return this.matchingGroups(); }),
|
||||
groups: Class.Memoize(function () {
|
||||
return this.matchingGroups();
|
||||
}),
|
||||
|
||||
allGroups: Class.Memoize(function () {
|
||||
return Object.create(this.groupsProto, {
|
||||
|
||||
@@ -954,12 +954,18 @@ var DOM = Class("DOM", {
|
||||
try {
|
||||
if (elem instanceof Ci.nsIDOMDocument)
|
||||
elem = elem.defaultView;
|
||||
if (elem instanceof Ci.nsIDOMElement)
|
||||
services.focus.setFocus(elem, flags);
|
||||
else if (elem instanceof Ci.nsIDOMWindow) {
|
||||
services.focus.focusedWindow = elem;
|
||||
if (services.focus.focusedWindow != elem)
|
||||
services.focus.clearFocus(elem);
|
||||
|
||||
if (Cu.isCrossProcessWrapper(elem)) {
|
||||
elem.focus();
|
||||
}
|
||||
else {
|
||||
if (elem instanceof Ci.nsIDOMElement)
|
||||
services.focus.setFocus(elem, flags);
|
||||
else if (elem instanceof Ci.nsIDOMWindow) {
|
||||
services.focus.focusedWindow = elem;
|
||||
if (services.focus.focusedWindow != elem)
|
||||
services.focus.clearFocus(elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
@@ -299,7 +299,7 @@ var DownloadList = Class("DownloadList",
|
||||
addDownload: function addDownload(download) {
|
||||
if (!this.downloads.has(download)) {
|
||||
download = Download(download, this);
|
||||
if (this.filter && !download.displayName.contains(this.filter))
|
||||
if (this.filter && !download.displayName.includes(this.filter))
|
||||
return;
|
||||
|
||||
this.downloads.set(download.download, download);
|
||||
|
||||
@@ -117,7 +117,7 @@ var Help = Module("Help", {
|
||||
| ^ (?P<space> \s*)
|
||||
(?P<char> [-•*+]) \ //
|
||||
(?P<content> .*\n
|
||||
(?: ${"\\2"} // This is incorrectly interpreted as an octal literal otherwise}\ \ .*\n | \s*\n)* )
|
||||
(?: ${"\\2" /* This is incorrectly interpreted as an octal literal otherwise */}\ \ .*\n | \s*\n)* )
|
||||
|
||||
| (?P<par>
|
||||
(?: ^ [^\S\n]*
|
||||
|
||||
@@ -97,9 +97,12 @@ var Modules = function Modules(window) {
|
||||
if (normal)
|
||||
return create(proto);
|
||||
|
||||
let sandbox = Components.utils.Sandbox(window, { sandboxPrototype: proto || modules,
|
||||
sandboxName: name || ("Dactyl Sandbox " + ++_id),
|
||||
wantXrays: true });
|
||||
let sandbox = Components.utils.Sandbox(Cu.getObjectPrincipal(global),
|
||||
{ sandboxPrototype: proto || modules,
|
||||
sandboxName: name || ("Dactyl Sandbox " + ++_id),
|
||||
addonId: config.addon.id,
|
||||
wantXrays: true,
|
||||
metadata: { addonID: config.addon.id } });
|
||||
|
||||
// Hack:
|
||||
// sandbox.Object = jsmodules.Object;
|
||||
|
||||
@@ -425,7 +425,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
|
||||
delete desc.writable;
|
||||
desc.get = function get() { return value; }
|
||||
desc.set = function set(val) {
|
||||
if (!callable(val) || !Function.prototype.toString(val).contains(sentinel))
|
||||
if (!callable(val) || !Function.prototype.toString(val).includes(sentinel))
|
||||
Class.replaceProperty(this, k, val);
|
||||
else {
|
||||
let package_ = util.newURI(Components.stack.caller.filename).host;
|
||||
|
||||
@@ -411,7 +411,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
function* prefs() {
|
||||
for (let pref of prefArray) {
|
||||
let userValue = services.pref.prefHasUserValue(pref);
|
||||
if (onlyNonDefault && !userValue || !pref.contains(filter))
|
||||
if (onlyNonDefault && !userValue || !pref.includes(filter))
|
||||
continue;
|
||||
|
||||
let value = this.get(pref);
|
||||
|
||||
@@ -329,10 +329,13 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
||||
* @param {Window|Document|Node} thing The thing for which to return
|
||||
* a load context.
|
||||
*/
|
||||
getContext: function getContext(thing) {
|
||||
getContext: function getContext(thing, global = null) {
|
||||
if (!Ci.nsILoadContext)
|
||||
return null;
|
||||
|
||||
if (Cu.isCrossProcessWrapper(thing) && global)
|
||||
thing = global;
|
||||
|
||||
if (thing instanceof Ci.nsIDOMNode && thing.ownerDocument)
|
||||
thing = thing.ownerDocument;
|
||||
if (thing instanceof Ci.nsIDOMDocument)
|
||||
@@ -634,7 +637,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
||||
completion: function initCompletion(dactyl, modules, window) {
|
||||
modules.completion.visibleHosts = function completeHosts(context) {
|
||||
let res = util.visibleHosts(window.content);
|
||||
if (context.filter && !res.some(host => host.contains(context.filter)))
|
||||
if (context.filter && !res.some(host => host.includes(context.filter)))
|
||||
res.push(context.filter);
|
||||
|
||||
context.title = ["Domain"];
|
||||
|
||||
@@ -225,7 +225,7 @@ var Hive = Class("Hive", {
|
||||
name = null;
|
||||
}
|
||||
|
||||
if (filter && filter.contains(","))
|
||||
if (filter && filter.includes(","))
|
||||
return filter.split(",").reduce(
|
||||
(n, f) => n + this.removeSheet(name, f, index), 0);
|
||||
|
||||
|
||||
@@ -562,7 +562,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
rec([]);
|
||||
return res;
|
||||
}
|
||||
catch (e if e.message && e.message.contains("res is undefined")) {
|
||||
catch (e if e.message && e.message.includes("res is undefined")) {
|
||||
// prefs.safeSet() would be reset on :rehash
|
||||
prefs.set("javascript.options.methodjit.chrome", false);
|
||||
util.dactyl.warn(_(UTF8("error.damnYouJägermonkey")));
|
||||
@@ -591,7 +591,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
*/
|
||||
dequote: function dequote(pattern, chars) {
|
||||
return pattern.replace(/\\(.)/,
|
||||
(m0, m1) => chars.contains(m1) ? m1 : m0);
|
||||
(m0, m1) => chars.includes(m1) ? m1 : m0);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1485,6 +1485,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
this.dump(util.stackLines(error.stack).join("\n"));
|
||||
}
|
||||
catch (e) { dump(e + "\n"); }
|
||||
dump("Stack: " + Error().stack + "\n");
|
||||
}
|
||||
|
||||
// ctypes.open("libc.so.6").declare("kill", ctypes.default_abi, ctypes.void_t, ctypes.int, ctypes.int)(
|
||||
@@ -1727,11 +1728,12 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
* @returns {Window} The top-level parent window.
|
||||
*/
|
||||
topWindow: function topWindow(win) {
|
||||
return win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem
|
||||
.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow);
|
||||
let docShell = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDocShell);
|
||||
let { rootTreeItem } = docShell;
|
||||
if (rootTreeItem)
|
||||
return rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1742,9 +1744,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
*/
|
||||
trapErrors: function trapErrors(func, self, ...args) {
|
||||
try {
|
||||
if (!callable(func))
|
||||
func = self[func];
|
||||
return func.apply(self || this, args);
|
||||
return apply(self || this, func, args);
|
||||
}
|
||||
catch (e) {
|
||||
this.reportError(e);
|
||||
|
||||
Reference in New Issue
Block a user