1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-10 09:35:46 +01:00

Use rendered HTML for gF/:w !foo/:w >>foo until someone inevitably complains. Closes issue #44.

This commit is contained in:
Kris Maglione
2010-10-15 17:52:28 -04:00
parent 4bbfa212bc
commit b940a9db96
4 changed files with 71 additions and 96 deletions

View File

@@ -526,8 +526,8 @@ function call(fn) {
*/
function memoize(obj, key, getter) {
obj.__defineGetter__(key, function replace() (
Class.replaceProperty(this, key, null),
Class.replaceProperty(this, key, getter.call(this, key))));
Class.replaceProperty(this.instance || this, key, null),
Class.replaceProperty(this.instance || this, key, getter.call(this, key))));
}
/**
@@ -684,19 +684,8 @@ function Class() {
(function constructor() {
let self = Object.create(Constructor.prototype, {
constructor: { value: Constructor },
closure: {
configurable: true,
get: function () {
function closure(fn) function () fn.apply(self, arguments);
for (let k in iterAll(properties(this),
properties(this, true)))
if (!this.__lookupGetter__(k) && callable(this[k]))
closure[k] = closure(self[k]);
Object.defineProperty(this, "closure", { value: closure });
return closure;
}
}
});
self.instance = self;
var res = self.init.apply(self, arguments);
return res !== undefined ? res : self;
})]]>,
@@ -820,6 +809,14 @@ Class.prototype = {
return timer;
}
};
memoize(Class.prototype, "closure", function () {
const self = this;
function closure(fn) function () fn.apply(self, arguments);
for (let k in iterAll(properties(this), properties(this, true)))
if (!this.__lookupGetter__(k) && callable(this[k]))
closure[k] = closure(this[k]);
return closure;
});
/**
* A base class generator for classes which impliment XPCOM interfaces.

View File

@@ -56,8 +56,6 @@ const Services = Module("Services", {
this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher);
this.addClass("docshell", "@mozilla.org/docshell;1", [Ci.nsIBaseWindow, Ci.nsIWebNavigation,
Ci.nsIWebPageDescriptor, Ci.nsIWebProgress]);
this.addClass("file", "@mozilla.org/file/local;1", Ci.nsILocalFile);
this.addClass("file:", "@mozilla.org/network/protocol;1?name=file", Ci.nsIFileProtocolHandler);
this.addClass("find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);

View File

@@ -286,7 +286,7 @@ const File = Class("File", {
}
}
let self = XPCSafeJSObjectWrapper(file);
self.__proto__ = File.prototype;
self.__proto__ = this;
return self;
},
@@ -310,22 +310,32 @@ const File = Class("File", {
*/
read: function (encoding) {
let ifstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
let icstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
if (!encoding)
encoding = File.defaultEncoding;
ifstream.init(this, -1, 0, 0);
icstream.init(ifstream, encoding, 4096, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); // 4096 bytes buffering
let buffer = [];
let str = {};
while (icstream.readString(4096, str) != 0)
buffer.push(str.value);
icstream.close();
ifstream.close();
return buffer.join("");
try {
if (encoding instanceof Ci.nsIOutputStream) {
let l, len = 0;
while ((l = encoding.writeFrom(ifstream, 4096)) != 0)
len += l;
return len;
}
else {
var icstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
icstream.init(ifstream, encoding || File.defaultEncoding, 4096, // 4096 bytes buffering
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
let buffer = [];
let str = {};
while (icstream.readString(4096, str) != 0)
buffer.push(str.value);
return buffer.join("");
}
}
finally {
if (icstream)
icstream.close();
ifstream.close();
}
},
/**
@@ -376,6 +386,8 @@ const File = Class("File", {
stream.init(ofstream, encoding, 0, defaultChar);
return stream;
}
if (buf instanceof File)
buf = buf.read();
if (!encoding)
encoding = File.defaultEncoding;
@@ -391,18 +403,18 @@ const File = Class("File", {
this.create(this.NORMAL_FILE_TYPE, perms);
ofstream.init(this, mode, perms, 0);
let ocstream = getStream(0);
try {
ocstream.writeString(buf);
}
catch (e) {
if (e.result == Cr.NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) {
ocstream = getStream("?".charCodeAt(0));
if (callable(buf))
buf(ofstream.QueryInterface(Ci.nsIOutputStream));
else {
var ocstream = getStream(0);
ocstream.writeString(buf);
return false;
}
else
throw e;
}
catch (e if callable(buf) && e.result == Cr.NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) {
ocstream = getStream("?".charCodeAt(0));
ocstream.writeString(buf);
return false;
}
finally {
try {