mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 00:17:57 +01:00
Work around some conceivable race conditions in one of my least favorite commits ever.
This commit is contained in:
@@ -255,16 +255,25 @@ var CommandWidgets = Class("CommandWidgets", {
|
|||||||
commandbar: Class.memoize(function () ({ group: "Cmd" })),
|
commandbar: Class.memoize(function () ({ group: "Cmd" })),
|
||||||
statusbar: Class.memoize(function () ({ group: "Status" })),
|
statusbar: Class.memoize(function () ({ group: "Status" })),
|
||||||
|
|
||||||
_whenReady: function _whenReady(name, id) {
|
_ready: function _ready(elem) {
|
||||||
|
return elem.contentDocument.documentURI === elem.getAttribute("src") &&
|
||||||
|
["viewable", "complete"].indexOf(elem.contentDocument.readyState) >= 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
_whenReady: function _whenReady(id) {
|
||||||
let elem = document.getElementById(id);
|
let elem = document.getElementById(id);
|
||||||
|
|
||||||
util.waitFor(function () elem.contentDocument.documentURI === elem.getAttribute("src") &&
|
util.waitFor(bind(this._ready, this, elem));
|
||||||
["viewable", "complete"].indexOf(elem.contentDocument.readyState) >= 0);
|
|
||||||
|
|
||||||
return elem;
|
return elem;
|
||||||
},
|
},
|
||||||
|
|
||||||
completionList: Class.memoize(function () this._whenReady("completionList", "dactyl-completions"), true),
|
completionList: Class.memoize(function () {
|
||||||
|
let elem = document.getElementById(elem);
|
||||||
|
while (!this._ready(elem))
|
||||||
|
yield 10;
|
||||||
|
yield elem;
|
||||||
|
}, true),
|
||||||
|
|
||||||
completionContainer: Class.memoize(function () this.completionList.parentNode),
|
completionContainer: Class.memoize(function () this.completionList.parentNode),
|
||||||
|
|
||||||
@@ -279,11 +288,14 @@ var CommandWidgets = Class("CommandWidgets", {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
multilineOutput: Class.memoize(function () {
|
multilineOutput: Class.memoize(function () {
|
||||||
let elem = this._whenReady("multilineOutput", "dactyl-multiline-output");
|
let elem = document.getElementById("dactyl-multiline-output");
|
||||||
|
while (!this._ready(elem))
|
||||||
|
yield 10;
|
||||||
|
|
||||||
elem.contentWindow.addEventListener("unload", function (event) { event.preventDefault(); }, true);
|
elem.contentWindow.addEventListener("unload", function (event) { event.preventDefault(); }, true);
|
||||||
elem.contentDocument.documentElement.id = "dactyl-multiline-output-top";
|
elem.contentDocument.documentElement.id = "dactyl-multiline-output-top";
|
||||||
elem.contentDocument.body.id = "dactyl-multiline-output-content";
|
elem.contentDocument.body.id = "dactyl-multiline-output-content";
|
||||||
return elem;
|
yield elem;
|
||||||
}, true),
|
}, true),
|
||||||
|
|
||||||
multilineInput: Class.memoize(function () document.getElementById("dactyl-multiline-input")),
|
multilineInput: Class.memoize(function () document.getElementById("dactyl-multiline-input")),
|
||||||
@@ -569,7 +581,7 @@ var CommandLine = Module("commandline", {
|
|||||||
get completionList() {
|
get completionList() {
|
||||||
let node = this.widgets.active.commandline;
|
let node = this.widgets.active.commandline;
|
||||||
if (!node.completionList) {
|
if (!node.completionList) {
|
||||||
let elem = this.widgets._whenReady("completionList", "dactyl-completions-" + node.id);
|
let elem = this.widgets._whenReady("dactyl-completions-" + node.id);
|
||||||
node.completionList = ItemList(elem.id);
|
node.completionList = ItemList(elem.id);
|
||||||
}
|
}
|
||||||
return node.completionList;
|
return node.completionList;
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ defineModule("base", {
|
|||||||
exports: [
|
exports: [
|
||||||
"ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "JSMLoader", "Object", "Runnable",
|
"ErrorBase", "Cc", "Ci", "Class", "Cr", "Cu", "Module", "JSMLoader", "Object", "Runnable",
|
||||||
"Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "XPCSafeJSObjectWrapper",
|
"Struct", "StructBase", "Timer", "UTF8", "XPCOM", "XPCOMUtils", "XPCSafeJSObjectWrapper",
|
||||||
"array", "call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
|
"array", "bind", "call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
|
||||||
"deprecated", "endModule", "forEach", "isArray", "isGenerator", "isinstance", "isObject",
|
"deprecated", "endModule", "forEach", "isArray", "isGenerator", "isinstance", "isObject",
|
||||||
"isString", "isSubclass", "iter", "iterAll", "keys", "memoize", "octal", "properties",
|
"isString", "isSubclass", "iter", "iterAll", "keys", "memoize", "octal", "properties",
|
||||||
"require", "set", "update", "values", "withCallerGlobal"
|
"require", "set", "update", "values", "withCallerGlobal"
|
||||||
@@ -580,6 +580,14 @@ function curry(fn, length, self, acc) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (curry.bind)
|
||||||
|
var bind = function bind(func) func.bind.apply(func, Array.slice(arguments, bind.length));
|
||||||
|
else
|
||||||
|
var bind = function bind(func, self) {
|
||||||
|
let args = Array.slice(arguments, bind.length);
|
||||||
|
return function bound() func.apply(self, args.concat(Array.slice(arguments)));
|
||||||
|
};
|
||||||
|
|
||||||
let sandbox = Cu.Sandbox(this);
|
let sandbox = Cu.Sandbox(this);
|
||||||
sandbox.__proto__ = this;
|
sandbox.__proto__ = this;
|
||||||
/**
|
/**
|
||||||
@@ -774,26 +782,37 @@ Class.memoize = function memoize(getter, wait)
|
|||||||
enumerable: true,
|
enumerable: true,
|
||||||
init: function (key) {
|
init: function (key) {
|
||||||
let done = false;
|
let done = false;
|
||||||
let prop = { configurable: true, enumerable: true, value: null, writable: true };
|
|
||||||
if (wait)
|
|
||||||
prop = {
|
|
||||||
configurable: true, enumerable: false,
|
|
||||||
get: function get() {
|
|
||||||
util.waitFor(function () done);
|
|
||||||
return this[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.get = function replace() {
|
if (wait)
|
||||||
let obj = this.instance || this;
|
this.get = function replace() {
|
||||||
Object.defineProperty(obj, key, prop);
|
let obj = this.instance || this;
|
||||||
try {
|
Object.defineProperty(obj, key, {
|
||||||
|
configurable: true, enumerable: false,
|
||||||
|
get: function get() {
|
||||||
|
util.waitFor(function () done);
|
||||||
|
return this[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
util.yieldable(function () {
|
||||||
|
let wait;
|
||||||
|
for (var res in getter.call(obj)) {
|
||||||
|
if (wait !== undefined)
|
||||||
|
yield wait;
|
||||||
|
wait = res;
|
||||||
|
}
|
||||||
|
Class.replaceProperty(obj, key, res);
|
||||||
|
done = true;
|
||||||
|
})();
|
||||||
|
|
||||||
|
return this[key];
|
||||||
|
};
|
||||||
|
else
|
||||||
|
this.get = function replace() {
|
||||||
|
let obj = this.instance || this;
|
||||||
|
Class.replaceProperty(obj, key, null);
|
||||||
return Class.replaceProperty(obj, key, getter.call(this, key));
|
return Class.replaceProperty(obj, key, getter.call(this, key));
|
||||||
}
|
};
|
||||||
finally {
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.set = function replace(val) Class.replaceProperty(this.instance || this, val);
|
this.set = function replace(val) Class.replaceProperty(this.instance || this, val);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,17 +56,18 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
get addonID() this.name + "@dactyl.googlecode.com",
|
get addonID() this.name + "@dactyl.googlecode.com",
|
||||||
addon: Class.memoize(function () {
|
addon: Class.memoize(function () {
|
||||||
let addon;
|
let addon;
|
||||||
util.waitFor(function () {
|
do {
|
||||||
addon = services.fuel.storage.get("dactyl.bootstrap", {}).addon;
|
addon = services.fuel.storage.get("dactyl.bootstrap", {}).addon;
|
||||||
if (addon && !addon.getResourceURI)
|
if (addon && !addon.getResourceURI) {
|
||||||
util.reportError(Error("Don't have add-on yet"));
|
util.reportError(Error("Don't have add-on yet"));
|
||||||
|
yield 10;
|
||||||
return !addon || addon.getResourceURI;
|
}
|
||||||
});
|
}
|
||||||
|
while (addon && !addon.getResourceURI);
|
||||||
|
|
||||||
if (!addon)
|
if (!addon)
|
||||||
addon = require("addons").AddonManager.getAddonByID(this.addonID);
|
addon = require("addons").AddonManager.getAddonByID(this.addonID);
|
||||||
return addon;
|
yield addon;
|
||||||
}, true),
|
}, true),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user