1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-22 11:05:52 +01:00

Add array indexing to macro-string processing. Checkin Minefield crash workaround that was supposed to have been checked in yesterday.

This commit is contained in:
Kris Maglione
2011-05-27 19:48:30 -04:00
parent 98671742c3
commit 8459d93e0b
4 changed files with 39 additions and 14 deletions

View File

@@ -77,6 +77,13 @@
the form of <tt>&lt;e-<a>name</a>></tt>, its value is never shown but may be the form of <tt>&lt;e-<a>name</a>></tt>, its value is never shown but may be
used to test whether the given parameter is empty. used to test whether the given parameter is empty.
</p> </p>
<p>
Array elements, such as in the the <tt>&lt;args></tt> parameter
of <ex>:command</ex> macros, may be accessed by appending
<tt>[<a>n</a>]</tt>, where <a>n</a> is the one-based array
index, to the macro name. The first argument of a command is
therefore accessed with <tt>&lt;args[1]&lt;</tt>.
</p>
<p> <p>
Any substring enclosed by <em><tt>&lt;{</tt></em> and <em><tt>}></tt></em> Any substring enclosed by <em><tt>&lt;{</tt></em> and <em><tt>}></tt></em>
is automatically elided if any of the contained macros aren't currently is automatically elided if any of the contained macros aren't currently

View File

@@ -716,18 +716,28 @@ function Class() {
if (callable(args[0])) if (callable(args[0]))
superclass = args.shift(); superclass = args.shift();
var Constructor = eval(String.replace(<![CDATA[ if (loaded.util && util.haveGecko("6.0a1")) // Bug 657418.
(function constructor(PARAMS) { var Constructor = function Constructor() {
var self = Object.create(Constructor.prototype, { var self = Object.create(Constructor.prototype, {
constructor: { value: Constructor }, constructor: { value: Constructor },
}); });
self.instance = self; self.instance = self;
var res = self.init.apply(self, arguments); var res = self.init.apply(self, arguments);
return res !== undefined ? res : self; return res !== undefined ? res : self;
})]]>, };
"constructor", (name || superclass.className).replace(/\W/g, "_")) else
.replace("PARAMS", /^function .*?\((.*?)\)/.exec(args[0] && args[0].init || Class.prototype.init)[1] var Constructor = eval(String.replace(<![CDATA[
.replace(/\b(self|res|Constructor)\b/g, "$1_"))); (function constructor(PARAMS) {
var self = Object.create(Constructor.prototype, {
constructor: { value: Constructor },
});
self.instance = self;
var res = self.init.apply(self, arguments);
return res !== undefined ? res : self;
})]]>,
"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_")));
Constructor.className = name || superclass.className || superclass.name; Constructor.className = name || superclass.className || superclass.name;

View File

@@ -356,14 +356,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
([^]*?) // 1 ([^]*?) // 1
(?: (?:
(<\{) | // 2 (<\{) | // 2
(< ((?:[a-z]-)?[a-z-]+?) >) | // 3 4 (< ((?:[a-z]-)?[a-z-]+?) (?:\[([0-9]+)\])? >) | // 3 4 5
(\}>) // 5 (\}>) // 6
) )
]]>, "gixy"); ]]>, "gixy");
macro = String(macro); macro = String(macro);
let end = 0; let end = 0;
for (let match in re.iterate(macro)) { for (let match in re.iterate(macro)) {
let [, prefix, open, full, macro, close] = match; let [, prefix, open, full, macro, idx, close] = match;
end += match[0].length; end += match[0].length;
if (prefix) if (prefix)
@@ -390,9 +390,17 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
if (set.has(defaults, name)) if (set.has(defaults, name))
stack.top.elements.push(quote(defaults[name])); stack.top.elements.push(quote(defaults[name]));
else { else {
stack.top.elements.push(update( if (idx) {
function (obj) obj[name] != null ? quote(obj[name]) : set.has(obj, name) ? "" : unknown(full), idx = Number(idx) - 1;
{ test: function (obj) obj[name] != null && obj[name] !== false && (!flags.e || obj[name] != "") })); stack.top.elements.push(update(
function (obj) obj[name] != null && idx in obj[name] ? quote(obj[name][idx]) : set.has(obj, name) ? "" : unknown(full),
{ test: function (obj) obj[name] != null && idx in obj[name] && obj[name][idx] !== false && (!flags.e || obj[name][idx] != "") }));
}
else {
stack.top.elements.push(update(
function (obj) obj[name] != null ? quote(obj[name]) : set.has(obj, name) ? "" : unknown(full),
{ test: function (obj) obj[name] != null && obj[name] !== false && (!flags.e || obj[name] != "") }));
}
for (let elem in array.iterValues(stack)) for (let elem in array.iterValues(stack))
elem.seen[name] = true; elem.seen[name] = true;
@@ -1252,7 +1260,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
delete desc.writable; delete desc.writable;
desc.get = function get() value; desc.get = function get() value;
desc.set = function set(val) { desc.set = function set(val) {
if (String(val).indexOf(sentinel) < 0) if (!callable(val) || Function.prototype.toString(val).indexOf(sentinel) < 0)
Class.replaceProperty(this, k, val); Class.replaceProperty(this, k, val);
else { else {
let package_ = util.newURI(util.fixURI(Components.stack.caller.filename)).host; let package_ = util.newURI(util.fixURI(Components.stack.caller.filename)).host;

View File

@@ -32,7 +32,7 @@
<Description <Description
em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}" em:id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
em:minVersion="3.6" em:minVersion="3.6"
em:maxVersion="6.*"/> em:maxVersion="7.*"/>
</em:targetApplication> </em:targetApplication>
</Description> </Description>
</RDF> </RDF>