xpcomcore-rubygem 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/xpcomcore-rubygem.gemspec +144 -2
- data/xpcomcore/LICENSE +21 -0
- data/xpcomcore/README +27 -0
- data/xpcomcore/Rakefile +83 -0
- data/xpcomcore/VERSION.yml +5 -0
- data/xpcomcore/bin/popen_helper.sh +47 -0
- data/xpcomcore/bootstrapper.js +32 -0
- data/xpcomcore/components/XPCOMCore.js +122 -0
- data/xpcomcore/doc/files.html +275 -0
- data/xpcomcore/doc/index.html +275 -0
- data/xpcomcore/doc/symbols/Error.html +264 -0
- data/xpcomcore/doc/symbols/File.NoSuchFileError.html +334 -0
- data/xpcomcore/doc/symbols/File.html +451 -0
- data/xpcomcore/doc/symbols/Kernel.html +1098 -0
- data/xpcomcore/doc/symbols/LoadError.html +334 -0
- data/xpcomcore/doc/symbols/SelfConceptError.html +334 -0
- data/xpcomcore/doc/symbols/Sys.html +394 -0
- data/xpcomcore/doc/symbols/XPCBuiltins.html +314 -0
- data/xpcomcore/doc/symbols/_global_.html +264 -0
- data/xpcomcore/doc/symbols/src/lib_file.js.html +82 -0
- data/xpcomcore/doc/symbols/src/lib_kernel.js.html +250 -0
- data/xpcomcore/doc/symbols/src/lib_sys.js.html +60 -0
- data/xpcomcore/doc/symbols/src/lib_xpc_builtins.js.html +20 -0
- data/xpcomcore/etc/jsdoc-toolkit/README.txt +186 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame.js +33 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/Chain.js +102 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/Dumper.js +144 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/Hash.js +84 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/Link.js +153 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/Namespace.js +10 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/Opt.js +134 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/Reflection.js +26 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/String.js +93 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/frame/Testrun.js +129 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/handlers/FOODOC.js +26 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/handlers/XMLDOC.js +26 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/handlers/XMLDOC/DomReader.js +159 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/handlers/XMLDOC/XMLDoc.js +16 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/handlers/XMLDOC/XMLParse.js +292 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC.js +104 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/DocComment.js +200 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/DocTag.js +294 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/JsDoc.js +126 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/JsPlate.js +109 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Lang.js +144 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Parser.js +145 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/PluginManager.js +33 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Symbol.js +645 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/SymbolSet.js +241 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/TextStream.js +41 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Token.js +18 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/TokenReader.js +332 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/TokenStream.js +133 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Util.js +32 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Walker.js +474 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/main.js +111 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/plugins/commentSrcJson.js +20 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/plugins/frameworkPrototype.js +16 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/plugins/functionCall.js +10 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/plugins/publishSrcHilite.js +62 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/plugins/symbolLink.js +10 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/plugins/tagParamConfig.js +31 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/plugins/tagSynonyms.js +43 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/run.js +348 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/t/TestDoc.js +144 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/t/runner.js +13 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test.js +325 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/addon.js +24 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/anon_inner.js +14 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/augments.js +31 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/augments2.js +26 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/borrows.js +46 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/borrows2.js +23 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/config.js +22 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/constructs.js +18 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/encoding.js +10 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/encoding_other.js +12 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/event.js +54 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/exports.js +14 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/functions_anon.js +39 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/functions_nested.js +33 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/global.js +13 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/globals.js +25 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/ignore.js +10 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/inner.js +16 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/jsdoc_test.js +477 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/lend.js +33 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/memberof.js +19 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/memberof_constructor.js +17 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/module.js +17 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/name.js +19 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/namespace_nested.js +23 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/nocode.js +13 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/oblit_anon.js +20 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/overview.js +20 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/param_inline.js +37 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/params_optional.js +8 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/prototype.js +17 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/prototype_nested.js +9 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/prototype_oblit.js +13 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/prototype_oblit_constructor.js +24 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/public.js +10 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/scripts/code.js +5 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/scripts/notcode.txt +5 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/shared.js +42 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/shared2.js +2 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/shortcuts.js +22 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/static_this.js +13 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/synonyms.js +31 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/tosource.js +23 -0
- data/xpcomcore/etc/jsdoc-toolkit/app/test/variable_redefine.js +14 -0
- data/xpcomcore/etc/jsdoc-toolkit/changes.txt +96 -0
- data/xpcomcore/etc/jsdoc-toolkit/conf/sample.conf +31 -0
- data/xpcomcore/etc/jsdoc-toolkit/java/build.xml +36 -0
- data/xpcomcore/etc/jsdoc-toolkit/java/build_1.4.xml +36 -0
- data/xpcomcore/etc/jsdoc-toolkit/java/classes/js.jar +0 -0
- data/xpcomcore/etc/jsdoc-toolkit/java/src/JsDebugRun.java +21 -0
- data/xpcomcore/etc/jsdoc-toolkit/java/src/JsRun.java +21 -0
- data/xpcomcore/etc/jsdoc-toolkit/jsdebug.jar +0 -0
- data/xpcomcore/etc/jsdoc-toolkit/jsrun.jar +0 -0
- data/xpcomcore/etc/jsdoc-toolkit/jsrun.sh +52 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/allclasses.tmpl +17 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/allfiles.tmpl +56 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/class.tmpl +646 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/index.tmpl +39 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/publish.js +200 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/static/default.css +162 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/static/header.html +2 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/static/index.html +19 -0
- data/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/symbol.tmpl +35 -0
- data/xpcomcore/lib/file.js +75 -0
- data/xpcomcore/lib/kernel.js +243 -0
- data/xpcomcore/lib/sys.js +52 -0
- data/xpcomcore/lib/xpc_builtins.js +13 -0
- data/xpcomcore/test/file_test.js +27 -0
- data/xpcomcore/test/fixtures/empty +0 -0
- data/xpcomcore/test/fixtures/love.js +1 -0
- data/xpcomcore/test/fixtures/mad_love.js +1 -0
- data/xpcomcore/test/fixtures/mad_world.js +1 -0
- data/xpcomcore/test/fixtures/syntax_error.js +1 -0
- data/xpcomcore/test/kernel_test.js +95 -0
- data/xpcomcore/test/sys_test.js +19 -0
- data/xpcomcore/test/xpc_builtins_test.js +8 -0
- metadata +143 -1
@@ -0,0 +1,75 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview This file defines the implementation of our File object.
|
3
|
+
*/
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @class File class used for things such as creating filesystem paths, reading files, etc.
|
7
|
+
*/
|
8
|
+
function File() {};
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @class Exception representing an error loading a file.
|
12
|
+
* @extends Error
|
13
|
+
* @constructor
|
14
|
+
* @param {String} message The error message to be given for this exception.
|
15
|
+
* @returns {Error}
|
16
|
+
*/
|
17
|
+
File.NoSuchFileError = function(message) {
|
18
|
+
var err = new Error(message);
|
19
|
+
err.name = "File.NoSuchFileError";
|
20
|
+
return err;
|
21
|
+
};
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Joins the given string arguments together using the operating system's native path
|
25
|
+
* separator.
|
26
|
+
* @param {String[]} components Set of strings to join together.
|
27
|
+
* @returns {String} The resulting path.
|
28
|
+
*/
|
29
|
+
File.join = function() {
|
30
|
+
var file = new XPCBuiltins.nsILocalFile(arguments[0]);
|
31
|
+
|
32
|
+
for(var i = 1; i < arguments.length; i++) {
|
33
|
+
file.append(arguments[i]);
|
34
|
+
}
|
35
|
+
|
36
|
+
return file.path;
|
37
|
+
};
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Reads the given number of bytes (or the entire contents if the argument is ommitted)
|
41
|
+
* from the specified file
|
42
|
+
* @param {String} filePath Path to a file.
|
43
|
+
* @param {int} [maxBytes] Number of bytes to read from the file. Defaults to entire file.
|
44
|
+
* @returns {String} The data read from the given file.
|
45
|
+
*/
|
46
|
+
File.read = function(filePath, maxBytes) {
|
47
|
+
var file = new XPCBuiltins.nsILocalFile(filePath);
|
48
|
+
|
49
|
+
if (!file.exists()) { throw(new File.NoSuchFileError("No such file or directory - " + filePath)); };
|
50
|
+
|
51
|
+
var fileInputStream = $Cc["@mozilla.org/network/file-input-stream;1"].createInstance($Ci.nsIFileInputStream);
|
52
|
+
fileInputStream.init(file, -1, -1, 0);
|
53
|
+
|
54
|
+
var binaryInputStream = $Cc["@mozilla.org/binaryinputstream;1"].createInstance($Ci.nsIBinaryInputStream);
|
55
|
+
binaryInputStream.setInputStream(fileInputStream);
|
56
|
+
|
57
|
+
try {
|
58
|
+
return binaryInputStream.readBytes((maxBytes == null) ? binaryInputStream.available() : maxBytes);
|
59
|
+
} catch (e if e.result == $Cr.NS_ERROR_FAILURE) {
|
60
|
+
// FIXME - hack
|
61
|
+
// If we hit this, we're probably trying to read from a special device like a pipe. Fall back to
|
62
|
+
// reading a byte at a time and returning when we likely hit EOF (as indicated by another exception)
|
63
|
+
var output = '';
|
64
|
+
while (true) {
|
65
|
+
try {
|
66
|
+
output = output + binaryInputStream.readBytes((maxBytes == null) ? 1 : maxBytes);
|
67
|
+
if (maxBytes != null) { return output; }
|
68
|
+
} catch (e if e.result == $Cr.NS_ERROR_FAILURE) {
|
69
|
+
return output;
|
70
|
+
}
|
71
|
+
};
|
72
|
+
} finally {
|
73
|
+
binaryInputStream.close();
|
74
|
+
}
|
75
|
+
};
|
@@ -0,0 +1,243 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview This file specifies a set of globally useful features/shortcuts
|
3
|
+
* and defines our "Kernel" object, which is the base for doing a lot of simple
|
4
|
+
* things with XPCOMCore such as loading in other files and printing to the
|
5
|
+
* console.
|
6
|
+
*/
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @class Exception representing an error loading a file.
|
10
|
+
* @extends Error
|
11
|
+
* @constructor
|
12
|
+
* @param {String} message The error message to be given for this exception.
|
13
|
+
* @returns {Error}
|
14
|
+
*/
|
15
|
+
function LoadError(message) {
|
16
|
+
var err = new Error(message);
|
17
|
+
err.name = arguments.callee.name;
|
18
|
+
return err;
|
19
|
+
};
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @class Exception representing an error determining what the path to the currently executing file is.
|
23
|
+
* @extends Error
|
24
|
+
* @constructor
|
25
|
+
* @param {String} message The error message to be given for this exception.
|
26
|
+
* @returns {Error}
|
27
|
+
*/
|
28
|
+
function SelfConceptError(message) {
|
29
|
+
var err = new Error(message);
|
30
|
+
err.name = arguments.callee.name;
|
31
|
+
return err;
|
32
|
+
};
|
33
|
+
|
34
|
+
/**
|
35
|
+
* A pseudo-constructor to make JSDoc happy and actually document things in {@link Kernel}.
|
36
|
+
* If this method is called with an argument, all properties from {@link Kernel} are taken
|
37
|
+
* and defined as the return value of getter methods set on the given object.
|
38
|
+
* @class Our central 'class' containing a lot of properties and methods we need to
|
39
|
+
* build the rest of XPCOMCore on top of.
|
40
|
+
* @param {Object} mixinScope Optional argument, any object to mix {@link Kernel}'s properties
|
41
|
+
* into.
|
42
|
+
* @return The prototype object of the Kernel function.
|
43
|
+
*/
|
44
|
+
function Kernel(mixinScope) {
|
45
|
+
var myPrototype = arguments.callee.prototype;
|
46
|
+
if (mixinScope) {
|
47
|
+
// FIXME - figure out a better way than this object jammed in here to special case our
|
48
|
+
// methods we really want to be calling getters when they're mixed in.
|
49
|
+
var callingGetters = {'$CURRENT_FILE': {defaultArgs: [2]}, '$CURRENT_DIRECTORY': {defaultArgs: [3] }};
|
50
|
+
var makeGetter = function(attr) { return function() { return myPrototype[attr]; } };
|
51
|
+
var makeCallingGetter = function(attr, argsArray) {
|
52
|
+
return function() {
|
53
|
+
return myPrototype[attr].apply(this, argsArray);
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
for (var p in myPrototype) {
|
58
|
+
if (callingGetters[p]) {
|
59
|
+
mixinScope.__defineGetter__(p, makeCallingGetter(p, callingGetters[p].defaultArgs || []));
|
60
|
+
} else {
|
61
|
+
mixinScope.__defineGetter__(p, makeGetter(p));
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
// Load up our standard library into the mixinScope.
|
66
|
+
var standardLibraries = ['file', 'sys', 'xpc_builtins'];
|
67
|
+
var standardLibraryLoader = function() {
|
68
|
+
standardLibraries.forEach(function(library) { require(library); }, this);
|
69
|
+
};
|
70
|
+
standardLibraryLoader.call(mixinScope);
|
71
|
+
};
|
72
|
+
return myPrototype;
|
73
|
+
};
|
74
|
+
|
75
|
+
Kernel.prototype = {
|
76
|
+
/**
|
77
|
+
* A shortcut constant to Components.classes.
|
78
|
+
*/
|
79
|
+
$Cc: Components.classes,
|
80
|
+
|
81
|
+
/**
|
82
|
+
* A shortcut constant to Components.interfaces.
|
83
|
+
*/
|
84
|
+
$Ci: Components.interfaces,
|
85
|
+
|
86
|
+
/**
|
87
|
+
* A shortcut constant to Components.results.
|
88
|
+
*/
|
89
|
+
$Cr: Components.results,
|
90
|
+
|
91
|
+
/**
|
92
|
+
* A shortcut constant to Components.utils.
|
93
|
+
*/
|
94
|
+
$Cu: Components.utils,
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Taking inspiration from Ruby, this defines the set of paths to check when
|
98
|
+
* trying to load a file via either {@link Kernel#load} or {@link Kernel#require}.
|
99
|
+
* @type Array
|
100
|
+
*/
|
101
|
+
$LOAD_PATH: [XPCOMCoreConfig.getProperty('libRoot')],
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Taking inspiration from Ruby, this defines the currently loaded files that
|
105
|
+
* have been loaded through {@link Kernel#require}.
|
106
|
+
* @type Array
|
107
|
+
*/
|
108
|
+
$LOADED_FEATURES: ["kernel.js"],
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Taking inspiration from Ruby, this method tries to determine the filesystem path to
|
112
|
+
* the caller code of this method.
|
113
|
+
* NOTE - when {@link Kernel} is mixed into an object, this function gets mixed in via
|
114
|
+
* a special case behaviour that makes it a getter that actually calls the function
|
115
|
+
* rather than returning the function object itself. This is to facilitate being able
|
116
|
+
* to call '$CURRENT_FILE' in your code rather than '$CURRENT_FILE()'. The stackTraversalDepth
|
117
|
+
* parameter is there for this reason, since we need to traverse the stack further than
|
118
|
+
* normal to find the calling scope than we normally would.
|
119
|
+
* @returns {String} The path to the current file
|
120
|
+
* @param {int} stackTraversalDepth Optional argument, how far to look up the stack to
|
121
|
+
* figure out who called us. The default is usually safe.
|
122
|
+
* @throws {SelfConceptError} Thrown when we can't figure out what the filesystem
|
123
|
+
* path to the current file is.
|
124
|
+
*/
|
125
|
+
$CURRENT_FILE: function(stackTraversalDepth) {
|
126
|
+
try {
|
127
|
+
var stackTraversalDepth = stackTraversalDepth || 1;
|
128
|
+
var ioService = $Cc["@mozilla.org/network/io-service;1"].getService($Ci.nsIIOService);
|
129
|
+
// FIXME - UGH. This is so seedy.
|
130
|
+
// Traverse up the stack as far as needed to get our caller's stack frame. Sometimes we need to
|
131
|
+
// traverse more than one level up, like when this function is actually called from a getter
|
132
|
+
// property that references it.
|
133
|
+
var callerStack = Components.stack;
|
134
|
+
for (var i = 0; i < stackTraversalDepth; i++) {
|
135
|
+
callerStack = callerStack.caller;
|
136
|
+
}
|
137
|
+
// Split based on the stupid fucking " -> " Gecko puts in the filename and get the last entry
|
138
|
+
var ostensiblyUs = callerStack.filename.split(" -> ").slice(-1);
|
139
|
+
var callerFileURI = ioService.newURI(ostensiblyUs, null, null);
|
140
|
+
// QI for an nsIFileURL which lets us get a handle on an actual file attribute and automagically does
|
141
|
+
// resource: URL resolution for us
|
142
|
+
callerFileURI.QueryInterface($Ci.nsIFileURL);
|
143
|
+
// And theoretically, we can now get a handle on an nsIFile and return the path of that.
|
144
|
+
return callerFileURI.file.path;
|
145
|
+
} catch(e) {
|
146
|
+
throw(new SelfConceptError("The filesystem location of the current file could not be determined. -- " + e));
|
147
|
+
}
|
148
|
+
},
|
149
|
+
|
150
|
+
/**
|
151
|
+
* This method tries to determine the filesystem path to parent directory of the caller
|
152
|
+
* code of this method NOTE - see the note on $CURRENT_FILE, as the same applies here.
|
153
|
+
* @returns {String} The path to the current directory
|
154
|
+
* @param {int} stackTraversalDepth Optional argument, how far to look up the stack to
|
155
|
+
* figure out who called us. The default is usually safe.
|
156
|
+
* @throws {SelfConceptError} Thrown when we can't figure out what the filesystem
|
157
|
+
* path to the parent directory of the current file is.
|
158
|
+
*/
|
159
|
+
$CURRENT_DIRECTORY: function(stackTraversalDepth) {
|
160
|
+
var stackTraversalDepth = stackTraversalDepth || 2;
|
161
|
+
var currentFilePath = Kernel.prototype.$CURRENT_FILE(stackTraversalDepth);
|
162
|
+
|
163
|
+
var file = new XPCBuiltins.nsILocalFile(currentFilePath);
|
164
|
+
return file.parent.path;
|
165
|
+
},
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Returns a reference to an object allowing for get()/set() on environment variables.
|
169
|
+
* @type nsIEnvironment
|
170
|
+
*/
|
171
|
+
|
172
|
+
$ENV: Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment),
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Prints a string to standard out, without a trailing newline.
|
176
|
+
* @param {String} str String to print to standard out.
|
177
|
+
*/
|
178
|
+
print: function(str) {
|
179
|
+
dump(str);
|
180
|
+
},
|
181
|
+
|
182
|
+
/**
|
183
|
+
* Prints a string to standard out, with a trailing newline.
|
184
|
+
* @param {String} str String to print to standard out.
|
185
|
+
*/
|
186
|
+
puts: function(str) {
|
187
|
+
print(str + "\n");
|
188
|
+
},
|
189
|
+
|
190
|
+
/**
|
191
|
+
* Searches {@link Kernel#$LOAD_PATH} for files to load into the current global scope.
|
192
|
+
* Files loaded via this method will not be added to {@link Kernel#$LOADED_FEATURES} and hence
|
193
|
+
* can be repeatedly loaded and executed.
|
194
|
+
* @param {String} featurePath Full or relative path including file extension to try and load.
|
195
|
+
* @returns {Boolean} True if the file was loaded succesfully
|
196
|
+
* @throws {LoadError} Thrown when we can't find the specified file in any directories specified
|
197
|
+
* in {@link Kernel#$LOAD_PATH}.
|
198
|
+
*/
|
199
|
+
load: function(featurePath) {
|
200
|
+
var loader = $Cc["@mozilla.org/moz/jssubscript-loader;1"].getService($Ci.mozIJSSubScriptLoader);
|
201
|
+
var foundFile = null;
|
202
|
+
// FIXME - so this is kinda shitty. We have an empty entry here so we default to just trying to load
|
203
|
+
// from an absolute path
|
204
|
+
var loadPath = $LOAD_PATH.concat([""]);
|
205
|
+
var loadPathLength = loadPath.length;
|
206
|
+
// FIXME - mozilla bug here. if i use foreach on array it ignores the granted security privileges
|
207
|
+
for (var i = 0; i < loadPathLength; i++) {
|
208
|
+
var potentialFile = $Cc["@mozilla.org/file/local;1"].createInstance($Ci.nsILocalFile);
|
209
|
+
potentialFile.initWithPath(loadPath[i] + "/" + featurePath);
|
210
|
+
if (potentialFile.exists()) {
|
211
|
+
foundFile = potentialFile;
|
212
|
+
break;
|
213
|
+
}
|
214
|
+
};
|
215
|
+
if (foundFile) {
|
216
|
+
foundFile.normalize();
|
217
|
+
loader.loadSubScript("file://" + encodeURI(foundFile.path));
|
218
|
+
return true;
|
219
|
+
} else {
|
220
|
+
throw(new LoadError("no such file to load -- " + featurePath));
|
221
|
+
}
|
222
|
+
},
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Searches {@link Kernel#$LOAD_PATH} for features to load into the current global scope.
|
226
|
+
* Files loaded via this method will be added to {@link Kernel#$LOADED_FEATURES} and hence two
|
227
|
+
* consecutive calls to this method will not load and execute the code twice.
|
228
|
+
* @returns {Boolean} True if successful, false if the specified feature has already been required.
|
229
|
+
* @param {String} featurePath Full or relative path without the file extension to try and require.
|
230
|
+
* @throws {LoadError} Thrown when we can't find the specified feature in any directories specified
|
231
|
+
* in {@link Kernel#$LOAD_PATH}.
|
232
|
+
*/
|
233
|
+
require: function(feature) {
|
234
|
+
var jsFeature = feature + ".js";
|
235
|
+
if ($LOADED_FEATURES.indexOf(jsFeature) == -1) {
|
236
|
+
load(jsFeature);
|
237
|
+
$LOADED_FEATURES.push(jsFeature);
|
238
|
+
return true;
|
239
|
+
} else {
|
240
|
+
return false;
|
241
|
+
}
|
242
|
+
}
|
243
|
+
};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview This file defines the implementation of our Sys namespace.
|
3
|
+
*/
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @namespace Sys namespace used for things such as executing external commands.
|
7
|
+
*/
|
8
|
+
|
9
|
+
var Sys = {
|
10
|
+
|
11
|
+
/**
|
12
|
+
* This getter returns the current temp directory as returned by the XPCOM directory service.
|
13
|
+
* @returns {String} The path to the temp directory
|
14
|
+
*/
|
15
|
+
get tempDir() {
|
16
|
+
return $Cc["@mozilla.org/file/directory_service;1"].getService($Ci.nsIProperties).get("TmpD", $Ci.nsIFile).path;
|
17
|
+
},
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Runs the command given as the first parameter with the arguments given as the remaining
|
21
|
+
* parameters and returns an object containing the exit status (as the exitStatus property)
|
22
|
+
* and command output (as the output property).
|
23
|
+
* @param {String[]} parameters First parameter is command name, rest are arguments to
|
24
|
+
* invoke the command with.
|
25
|
+
* @returns {Object} Object with 'exitStatus' and 'output' properties.
|
26
|
+
*/
|
27
|
+
run: function() {
|
28
|
+
var tempDir = Sys.tempDir;
|
29
|
+
var popenHelper = File.join(XPCOMCoreConfig.getProperty('binRoot'), "popen_helper.sh");
|
30
|
+
var file = new XPCBuiltins.nsILocalFile(popenHelper);
|
31
|
+
|
32
|
+
var process = $Cc["@mozilla.org/process/util;1"].createInstance($Ci.nsIProcess);
|
33
|
+
process.init(file);
|
34
|
+
|
35
|
+
var args = Array.prototype.slice.call(arguments);
|
36
|
+
var procArgs = [tempDir, "stdout"].concat(args);
|
37
|
+
|
38
|
+
process.run(false, procArgs, procArgs.length);
|
39
|
+
|
40
|
+
var outputPipe = File.join(tempDir, process.pid + ".stdout.pipe");
|
41
|
+
var outputPipeFile = new XPCBuiltins.nsILocalFile(outputPipe);
|
42
|
+
|
43
|
+
var output = null;
|
44
|
+
while (!outputPipeFile.exists()) {
|
45
|
+
null;
|
46
|
+
};
|
47
|
+
|
48
|
+
output = File.read(outputPipe);
|
49
|
+
|
50
|
+
return({exitStatus: process.exitValue, output: output});
|
51
|
+
}
|
52
|
+
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview This file defines the implementation of our XPCBuiltins namespace.
|
3
|
+
*/
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @namespace XPCBuiltins namespace used for holding constructors for standard XPCOM objects.
|
7
|
+
*/
|
8
|
+
|
9
|
+
var XPCBuiltins = {
|
10
|
+
|
11
|
+
nsILocalFile: Components.Constructor("@mozilla.org/file/local;1", $Ci.nsILocalFile, "initWithPath")
|
12
|
+
|
13
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
XULTestCase.create("File Test", function(setup, teardown, test) {
|
2
|
+
|
3
|
+
test("File.join should properly put together strings", function() {
|
4
|
+
this.assertEqual($CURRENT_FILE, File.join($CURRENT_DIRECTORY, "file_test.js"));
|
5
|
+
});
|
6
|
+
|
7
|
+
test("File.read without a maxBytes argument should read the entire contents of a file if it exists", function() {
|
8
|
+
this.assertEqual("var love = true;", File.read(File.join($CURRENT_DIRECTORY, "fixtures", "love.js")));
|
9
|
+
});
|
10
|
+
|
11
|
+
test("File.read with a maxBytes argument should read the given number of bytes from a file", function() {
|
12
|
+
this.assertEqual("var love", File.read(File.join($CURRENT_DIRECTORY, "fixtures", "love.js"), 8));
|
13
|
+
});
|
14
|
+
|
15
|
+
test("File.read with a maxBytes argument of 0 shouldn't throw an exception", function() {
|
16
|
+
this.assertEqual("", File.read(File.join($CURRENT_DIRECTORY, "fixtures", "love.js"), 0));
|
17
|
+
});
|
18
|
+
|
19
|
+
test("File.read with an empty file shouldn't throw an exception", function() {
|
20
|
+
this.assertEqual("", File.read(File.join($CURRENT_DIRECTORY, "fixtures", "empty")));
|
21
|
+
});
|
22
|
+
|
23
|
+
test("File.read with a non-existent file should throw an exception", function() {
|
24
|
+
this.assertRaise("File.NoSuchFileError", function(){ File.read("/tmp/ohmanihopethisfiledoesntexist"); });
|
25
|
+
});
|
26
|
+
|
27
|
+
});
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
var love = true;
|
@@ -0,0 +1 @@
|
|
1
|
+
var mad_love = true;
|
@@ -0,0 +1 @@
|
|
1
|
+
var mad_world = true;
|
@@ -0,0 +1 @@
|
|
1
|
+
var ;
|
@@ -0,0 +1,95 @@
|
|
1
|
+
XULTestCase.create("Kernel Test", function(setup, teardown, test) {
|
2
|
+
setup(function() {
|
3
|
+
$LOAD_PATH.push(File.join($CURRENT_DIRECTORY, "fixtures"));
|
4
|
+
});
|
5
|
+
|
6
|
+
test("Kernel() function should mix its properties into the passed in scope", function(){
|
7
|
+
var newScope = {};
|
8
|
+
this.assertNotEqual(0, Kernel.prototype.__count__);
|
9
|
+
this.assertEqual(0, newScope.__count__);
|
10
|
+
Kernel(newScope);
|
11
|
+
this.assertEqual(Kernel.prototype.__count__, newScope.__count__);
|
12
|
+
});
|
13
|
+
|
14
|
+
|
15
|
+
test("$CURRENT_FILE should be exposed as a getter that returns a value that is not a function", function(){
|
16
|
+
this.assertNotEqual("function", typeof($CURRENT_FILE));
|
17
|
+
});
|
18
|
+
|
19
|
+
test("$CURRENT_FILE should end in kernel_test.js", function(){
|
20
|
+
this.assertMatch(/kernel_test.js$/, $CURRENT_FILE);
|
21
|
+
});
|
22
|
+
|
23
|
+
|
24
|
+
test("$CURRENT_DIRECTORY should be exposed as a getter that returns a value that is not a function", function(){
|
25
|
+
this.assertNotEqual("function", typeof($CURRENT_DIRECTORY));
|
26
|
+
});
|
27
|
+
|
28
|
+
test("$CURRENT_DIRECTORY should end in test", function(){
|
29
|
+
this.assertMatch(/test$/, $CURRENT_DIRECTORY);
|
30
|
+
});
|
31
|
+
|
32
|
+
|
33
|
+
test("load should throw an exception when you give it a non-existent resource", function() {
|
34
|
+
this.assertRaise("LoadError", function() {
|
35
|
+
load("some-junk");
|
36
|
+
});
|
37
|
+
});
|
38
|
+
|
39
|
+
test("load should return true when it can load a file successfully", function() {
|
40
|
+
this.assertEqual(true, load("love.js"));
|
41
|
+
});
|
42
|
+
|
43
|
+
test("load should bubble up a syntax error if the loaded file is syntactically whack", function() {
|
44
|
+
this.assertRaise("SyntaxError", function() { load("syntax_error.js") });
|
45
|
+
});
|
46
|
+
|
47
|
+
test("load should allow loading a resource multiple times", function() {
|
48
|
+
load("love.js");
|
49
|
+
this.assertEqual(true, love);
|
50
|
+
|
51
|
+
love = false;
|
52
|
+
load("love.js");
|
53
|
+
this.assertEqual(true, love);
|
54
|
+
});
|
55
|
+
|
56
|
+
test("load works when using absolute paths", function() {
|
57
|
+
love = false;
|
58
|
+
|
59
|
+
var absolutePath = File.join($CURRENT_DIRECTORY, "fixtures", "love.js");
|
60
|
+
// FIXME: this is unix-only and janky:
|
61
|
+
this.assertMatch(/^\//, absolutePath);
|
62
|
+
|
63
|
+
load(absolutePath);
|
64
|
+
this.assertEqual(true, love);
|
65
|
+
});
|
66
|
+
|
67
|
+
|
68
|
+
test("require should load a file the first time (just like load)", function() {
|
69
|
+
this.assertEqual(true, require("love"));
|
70
|
+
});
|
71
|
+
|
72
|
+
test("require should return false if the resource has already been loaded", function() {
|
73
|
+
require("mad_love");
|
74
|
+
this.assertEqual(false, require("mad_love"));
|
75
|
+
});
|
76
|
+
|
77
|
+
test("require should not load a resource that's already been loaded", function() {
|
78
|
+
require("mad_world");
|
79
|
+
this.assertEqual(true, mad_world);
|
80
|
+
|
81
|
+
mad_world = false;
|
82
|
+
require("mad_world");
|
83
|
+
this.assertEqual(false, mad_world);
|
84
|
+
});
|
85
|
+
|
86
|
+
test("should expose a $ENV object that allows for getting environment variables", function() {
|
87
|
+
this.assert($ENV.get('HOME'));
|
88
|
+
});
|
89
|
+
|
90
|
+
test("should expose a $ENV object that allows for setting environment variables", function() {
|
91
|
+
$ENV.set('XPCOMCORETEST', "testing");
|
92
|
+
this.assertEqual($ENV.get('XPCOMCORETEST'), "testing");
|
93
|
+
});
|
94
|
+
|
95
|
+
});
|