1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 23:57:59 +01:00

Fix some more CPG breakage.

This commit is contained in:
Kris Maglione
2012-12-16 21:09:41 -08:00
parent 2f0af0a3f1
commit 3e1911476b
12 changed files with 94 additions and 45 deletions

View File

@@ -1007,7 +1007,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
// Try to find a matching file.
let file = io.File(url);
if (file.exists() && file.isReadable())
return services.io.newFileURI(file).spec;
return file.URI.spec;
}
catch (e) {}
}

View File

@@ -638,6 +638,7 @@ var Buffer = Module("Buffer", {
| persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
let window = this.topWindow;
file = File(file);
if (!file.exists())
file.create(Ci.nsIFile.NORMAL_FILE_TYPE, octal(666));
@@ -649,7 +650,7 @@ var Buffer = Module("Buffer", {
persist.progressListener = update(Object.create(downloadListener), {
onStateChange: util.wrapCallback(function onStateChange(progress, request, flags, status) {
if (callback && (flags & Ci.nsIWebProgressListener.STATE_STOP) && status == 0)
util.trapErrors(callback, self, uri, file, progress, request, flags, status);
util.trapErrors(callback, self, uri, file.file, progress, request, flags, status);
return onStateChange.superapply(this, arguments);
})
@@ -657,7 +658,7 @@ var Buffer = Module("Buffer", {
else
persist.progressListener = downloadListener;
persist.saveURI(uri, null, null, null, null, file);
persist.saveURI(uri, null, null, null, null, file.path);
},
/**

View File

@@ -79,7 +79,7 @@ var Cache = Module("Cache", XPCOM(Ci.nsIRequestObserver), {
if (!this._cacheReader && this.cacheFile.exists()
&& !this.inQueue)
try {
this._cacheReader = services.ZipReader(this.cacheFile);
this._cacheReader = services.ZipReader(this.cacheFile.file);
}
catch (e if e.result == Cr.NS_ERROR_FILE_CORRUPTED) {
util.reportError(e);
@@ -99,14 +99,14 @@ var Cache = Module("Cache", XPCOM(Ci.nsIRequestObserver), {
if (!this.cacheFile.exists())
mode |= File.MODE_CREATE;
cache._cacheWriter = services.ZipWriter(this.cacheFile, mode);
cache._cacheWriter = services.ZipWriter(this.cacheFile.file, mode);
}
catch (e if e.result == Cr.NS_ERROR_FILE_CORRUPTED) {
util.reportError(e);
this.cacheFile.remove(false);
mode |= File.MODE_CREATE;
cache._cacheWriter = services.ZipWriter(this.cacheFile, mode);
cache._cacheWriter = services.ZipWriter(this.cacheFile.file, mode);
}
return this._cacheWriter;
},
@@ -159,7 +159,7 @@ var Cache = Module("Cache", XPCOM(Ci.nsIRequestObserver), {
},
flushJAR: function flushJAR(file) {
services.observer.notifyObservers(file, "flush-cache-entry", "");
services.observer.notifyObservers(File(file).file, "flush-cache-entry", "");
},
flushStartup: function flushStartup() {

View File

@@ -260,7 +260,7 @@ var ConfigBase = Class("ConfigBase", {
}
}
function processJar(file) {
let jar = services.ZipReader(file);
let jar = services.ZipReader(file.file);
if (jar)
try {
if (jar.hasEntry("chrome.manifest"))

View File

@@ -377,7 +377,7 @@ var Contexts = Module("contexts", {
return {
__proto__: frame,
filename: this.context.file[0] == "[" ? this.context.file
: services.io.newFileURI(File(this.context.file)).spec,
: File(this.context.file).URI.spec,
lineNumber: this.context.line
};
return frame;

View File

@@ -1562,7 +1562,7 @@ var DOM = Class("DOM", {
function tag(args, namespaces) {
let _namespaces = namespaces;
if (isinstance(args, ["String", "Number", _]))
if (isinstance(args, ["String", "Number", "Boolean", _]))
return doc.createTextNode(args);
if (isXML(args))
return DOM.fromXML(args, doc, nodes);

View File

@@ -105,7 +105,7 @@ var Download = Class("Download", {
function action() {
try {
if (this.MIMEInfo && this.MIMEInfo.preferredAction == this.MIMEInfo.useHelperApp)
this.MIMEInfo.launchWithFile(file);
this.MIMEInfo.launchWithFile(file.file);
else
file.launch();
}

View File

@@ -298,7 +298,7 @@ var Help = Module("Help", {
var addURIEntry = function addURIEntry(file, uri) addDataEntry(file, util.httpGet(uri).responseText);
}
else {
var zip = services.ZipWriter(FILE, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
var zip = services.ZipWriter(FILE.file, File.MODE_CREATE | File.MODE_WRONLY | File.MODE_TRUNCATE);
addURIEntry = function addURIEntry(file, uri)
zip.addEntryChannel(PATH + file, TIME, 9,

View File

@@ -361,7 +361,7 @@ var IO = Module("io", {
file = util.getFile(file);
if (file && file.exists() && file.isFile() && file.isReadable()) {
// let jar = services.zipReader.getZip(file); Crashes.
let jar = services.ZipReader(file);
let jar = services.ZipReader(file.file);
try {
let filter = RegExp("^" + util.regexp.escape(decodeURI(path))
+ "[^/]*/?$");
@@ -444,7 +444,7 @@ var IO = Module("io", {
return -1;
}
let process = services.Process(file);
let process = services.Process(file.file);
process.run(false, args.map(String), args.length);
try {
if (callable(blocking))
@@ -668,9 +668,7 @@ var IO = Module("io", {
// require bang if any of the paths exist
for (let [type, item] in iter(rtItems)) {
let file = io.File(rtDir);
file.append(type);
file.append(config.name + ".vim");
let file = io.File(rtDir).child(type, config.name + ".vim");
dactyl.assert(!file.exists() || args.bang, _("io.exists", file.path.quote()));
item.file = file;
}

View File

@@ -113,7 +113,7 @@ var Services = Module("Services", {
},
reinit: function () {},
_create: function (name, args) {
_create: function _create(name, args) {
try {
var service = this.services[name];
@@ -130,7 +130,10 @@ var Services = Module("Services", {
}
return res;
}
catch (e if service.quiet !== false) {
catch (e) {
if (service.quiet === false)
throw e.stack ? e : Error(e);
if (typeof util !== "undefined")
util.reportError(e);
else
@@ -149,7 +152,7 @@ var Services = Module("Services", {
* @param {string} meth The name of the function used to instantiate
* the service.
*/
add: function (name, class_, ifaces, meth) {
add: function add(name, class_, ifaces, meth) {
const self = this;
this.services[name] = { method: meth, class: class_, interfaces: Array.concat(ifaces || []) };
if (name in this && ifaces && !this.__lookupGetter__(name) && !(this[name] instanceof Ci.nsISupports))
@@ -167,14 +170,14 @@ var Services = Module("Services", {
* @param {string} init Name of a property or method used to initialize the
* class.
*/
addClass: function (name, class_, ifaces, init, quiet) {
addClass: function addClass(name, class_, ifaces, init, quiet) {
const self = this;
this.services[name] = { class: class_, interfaces: Array.concat(ifaces || []), method: "createInstance", init: init, quiet: quiet };
if (init)
memoize(this.services[name], "callable",
function () callable(XPCOMShim(this.interfaces)[this.init]));
this[name] = function () self._create(name, arguments);
this[name] = function Create() self._create(name, arguments);
update.apply(null, [this[name]].concat([Ci[i] for each (i in Array.concat(ifaces))]));
return this[name];
},
@@ -198,7 +201,7 @@ var Services = Module("Services", {
*
* @param {string} name The service's cache key.
*/
has: function (name) Set.has(this.services, name) && this.services[name].class in Cc &&
has: function has(name) Set.has(this.services, name) && this.services[name].class in Cc &&
this.services[name].interfaces.every(function (iface) iface in Ci)
});

View File

@@ -179,7 +179,7 @@ var ObjectStore = Class("ObjectStore", StoreBase, {
var Storage = Module("Storage", {
alwaysReload: {},
init: function () {
init: function init() {
this.cleanup();
let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
@@ -341,7 +341,7 @@ var File = Class("File", {
if (path instanceof Ci.nsIFileURL)
path = path.file;
if (path instanceof Ci.nsIFile)
if (path instanceof Ci.nsIFile || path instanceof File)
file = path.clone();
else if (/file:\/\//.test(path))
file = services["file:"].getFileFromURLSpec(path);
@@ -359,11 +359,8 @@ var File = Class("File", {
return File.DoesNotExist(path, e);
}
}
this.file = file;
let self = XPCSafeJSObjectWrapper(file.QueryInterface(Ci.nsILocalFile));
self.__proto__ = this;
return self;
this.file = file.QueryInterface(Ci.nsILocalFile);
return this;
},
charset: Class.Memoize(function () File.defaultEncoding),
@@ -372,7 +369,8 @@ var File = Class("File", {
* @property {nsIFileURL} Returns the nsIFileURL object for this file.
*/
URI: Class.Memoize(function () {
let uri = services.io.newFileURI(this).QueryInterface(Ci.nsIFileURL);
let uri = services.io.newFileURI(this.file)
.QueryInterface(Ci.nsIFileURL);
uri.QueryInterface(Ci.nsIMutable).mutable = false;
return uri;
}),
@@ -380,7 +378,7 @@ var File = Class("File", {
/**
* Iterates over the objects in this directory.
*/
iterDirectory: function () {
iterDirectory: function iterDirectory() {
if (!this.exists())
throw Error(_("io.noSuchFile"));
if (!this.isDirectory())
@@ -392,17 +390,18 @@ var File = Class("File", {
/**
* Returns a new file for the given child of this directory entry.
*/
child: function (name) {
child: function child() {
let f = this.constructor(this);
for each (let elem in name.split(File.pathSplit))
f.append(elem);
for (let [, name] in Iterator(arguments))
for each (let elem in name.split(File.pathSplit))
f.append(elem);
return f;
},
/**
* Returns an iterator for all lines in a file.
*/
get lines() File.readLines(services.FileInStream(this, -1, 0, 0),
get lines() File.readLines(services.FileInStream(this.file, -1, 0, 0),
this.charset),
/**
@@ -413,8 +412,8 @@ var File = Class("File", {
* @default #charset
* @returns {string}
*/
read: function (encoding) {
let ifstream = services.FileInStream(this, -1, 0, 0);
read: function read(encoding) {
let ifstream = services.FileInStream(this.file, -1, 0, 0);
return File.readStream(ifstream, encoding || this.charset);
},
@@ -426,7 +425,7 @@ var File = Class("File", {
* entries.
* @returns {[nsIFile]}
*/
readDirectory: function (sort) {
readDirectory: function readDirectory(sort) {
if (!this.isDirectory())
throw Error(_("io.eNotDir"));
@@ -441,7 +440,7 @@ var File = Class("File", {
*
* @returns {nsIFileURL}
*/
toURI: function toURI() services.io.newFileURI(this),
toURI: function toURI() services.io.newFileURI(this.file),
/**
* Writes the string *buf* to this file.
@@ -467,7 +466,7 @@ var File = Class("File", {
* @param {string} encoding The encoding to used to write the file.
* @default #charset
*/
write: function (buf, mode, perms, encoding) {
write: function write(buf, mode, perms, encoding) {
function getStream(defaultChar) {
return services.ConvOutStream(ofstream, encoding, 0, defaultChar);
}
@@ -487,7 +486,7 @@ var File = Class("File", {
if (!this.exists()) // OCREAT won't create the directory
this.create(this.NORMAL_FILE_TYPE, perms);
let ofstream = services.FileOutStream(this, mode, perms, 0);
let ofstream = services.FileOutStream(this.file, mode, perms, 0);
try {
var ocstream = getStream(0);
ocstream.writeString(buf);
@@ -506,7 +505,34 @@ var File = Class("File", {
ofstream.close();
}
return true;
}
},
// Wrapped native methods:
copyTo: function copyTo(dir, name)
this.file.copyTo(this.constructor(dir).file,
name),
copyToFollowingLinks: function copyToFollowingLinks(dir, name)
this.file.copyToFollowingLinks(this.constructor(dir).file,
name),
moveTo: function moveTo(dir, name)
this.file.moveTo(this.constructor(dir).file,
name),
equals: function equals(file)
this.file.equals(this.constructor(file).file),
contains: function contains(dir, recur)
this.file.contains(this.constructor(dir).file,
recur),
getRelativeDescriptor: function getRelativeDescriptor(file)
this.file.getRelativeDescriptor(this.constructor(file).file),
setRelativeDescriptor: function setRelativeDescriptor(file, path)
this.file.setRelativeDescriptor(this.constructor(file).file,
path)
}, {
/**
* @property {number} Open for reading only.
@@ -697,6 +723,28 @@ var File = Class("File", {
replacePathSep: function (path) path.replace("/", File.PATH_SEP, "g")
});
let (file = services.directory.get("ProfD", Ci.nsIFile)) {
Object.keys(file).forEach(function (prop) {
if (!(prop in File.prototype)) {
let isFunction;
try {
isFunction = callable(file[prop])
}
catch (e) {}
if (isFunction)
File.prototype[prop] = util.wrapCallback(function wrapper() this.file[prop].apply(this.file, arguments));
else
Object.defineProperty(File.prototype, prop, {
configurable: true,
get: function wrap_get() this.file[prop],
set: function wrap_set(val) { this.file[prop] = val; }
});
}
});
file = null;
}
endModule();
// catch(e){ dump(e + "\n" + (e.stack || Error().stack)); Components.utils.reportError(e) }

View File

@@ -827,7 +827,6 @@ var tests = {
time: {
error: ["", ":some-nonexistent-command"/*, "some_nonexistent_reference"*/], // FIXME
singleOutput: [":js null", "null"]
},
get tlistkeys() this.listcommands,
tmap: {},
@@ -903,7 +902,7 @@ var tests = {
error: ["foo"],
multiOutput: [
["", function (msg) {
var res = /(\w+dactyl) (\S+) \(([\^)]+)\) running on:\nMozilla/;
var res = /(\w+dactyl) (\S+) \(([\^)]+)\) running on:\nMozilla/.exec(msg);
return res && res[2] != "null" && res[3] != "null";
}]
]