Skip to content
Browse files

added file handle wrapper to file module

  • Loading branch information...
1 parent 758d41c commit c81f6a5e316ce4713ff2e862caa799ec5dfc508c Kristoffer Walker committed Dec 15, 2009
Showing with 25 additions and 13 deletions.
  1. +19 −13 tree/packs/platform/file_1.js
  2. +6 −0 tree/packs/platform/testing/test_file.js
View
32 tree/packs/platform/file_1.js
@@ -27,6 +27,16 @@ sys: false
// We need to determine what platform we are on before
// defining these functions
+function constructFileHandle(nsIFile, aPath) {
+ var f;
+
+ function F() {}
+ F.prototype = nsIFile;
+ f = new F();
+ f.location = aPath;
+ return f;
+}
+
function openLocation(nsIFile, aLoc) {
var list, i;
@@ -44,8 +54,7 @@ function openLocation(nsIFile, aLoc) {
* @returns {object} A File object
*/
exports.open = function file_open(aLoc) {
- var loc,
- mozId = require("platform/firefox/utils_1").MOZID;
+ var mozId = require("platform/firefox/utils_1").MOZID;
if (typeof aLoc !== "string") {
throw new Error(
@@ -55,22 +64,19 @@ exports.open = function file_open(aLoc) {
switch(aLoc) {
case "Profile":
- loc = "ProfD";
- break;
-
+ return constructFileHandle(
+ Components.classes["@mozilla.org/file/directory_service;1"].
+ getService(Components.interfaces.nsIProperties).
+ get("ProfD", Components.interfaces.nsIFile), aLoc);
case "Kixx":
- return Components.classes["@mozilla.org/extensions/manager;1"].
+ return constructFileHandle(
+ Components.classes["@mozilla.org/extensions/manager;1"].
getService(Components.interfaces.nsIExtensionManager).
getInstallLocation(mozId).
- getItemLocation(mozId);
-
+ getItemLocation(mozId), aLoc);
default:
- return openLocation(file_open("Kixx"), aLoc);
+ return constructFileHandle(openLocation(file_open("Kixx"), aLoc), aLoc);
}
-
- return Components.classes["@mozilla.org/file/directory_service;1"].
- getService(Components.interfaces.nsIProperties).
- get(loc, Components.interfaces.nsIFile);
};
/**
View
6 tree/packs/platform/testing/test_file.js
@@ -35,6 +35,12 @@ var FT = (function () {
"packs/platform/panel should be a directory.");
assert(fu.open("packs/platform/panel/panel.html").isFile(),
"packs/platform/panel/panel.html should be a file.");
+
+ // test our own path property
+ assert(fu.open("packs/platform/panel/panel.html").location ===
+ "packs/platform/panel/panel.html",
+ "path property should be 'packs/platform/panel/panel.html'. ("+
+ fu.open("packs/platform/panel/panel.html").location +")");
};
return pub;

0 comments on commit c81f6a5

Please sign in to comment.
Something went wrong with that request. Please try again.