forked from bard/mozrepl
/
CommandLine.js
88 lines (66 loc) · 2.4 KB
/
CommandLine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const CATEGORY = 'c-mozrepl';
const CONTRACT_ID = '@mozilla.org/commandlinehandler/general-startup;1?type=repl';
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const CLASS_ID = Components.ID('{f62cbe68-ee70-4264-8586-66df185244f5}');
const Handler = {
QueryInterface: function(iid) {
if(iid.equals(Ci.nsICommandLineHandler) ||
iid.equals(Ci.nsIFactory) ||
iid.equals(Ci.nsISupports))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
handle: function(cmdLine) {
var uri;
try {
uri = cmdLine.handleFlagWithParam('repl', false);
} catch (e) {
}
if(uri || cmdLine.handleFlag('repl', false))
Cc['@hyperstruct.net/mozlab/mozrepl;1']
.getService(Ci.nsIMozRepl)
.start(4242);
},
helpInfo: '-repl Start REPL.\n',
createInstance: function(outer, iid) {
if(outer != null)
throw Cr.NS_ERROR_NO_AGGREGATION;
return this.QueryInterface(iid);
},
lockFactory: function(lock) {
/* no-op */
}
};
const Module = {
QueryInterface: function(iid) {
if(iid.equals(Ci.nsIModule) ||
iid.equals(Ci.nsISupports))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
getClassObject: function(compMgr, cid, iid) {
if(cid.equals(CLASS_ID))
return Handler.QueryInterface(iid);
throw Cr.NS_ERROR_NOT_REGISTERED;
},
registerSelf: function(compMgr, fileSpec, location, type) {
compMgr.QueryInterface(Ci.nsIComponentRegistrar);
compMgr.registerFactoryLocation(CLASS_ID, 'Handler', CONTRACT_ID, fileSpec, location, type);
var catMan = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
catMan.addCategoryEntry('command-line-handler', CATEGORY, CONTRACT_ID, true, true);
},
unregisterSelf: function mod_unreg(compMgr, location, type) {
compMgr.QueryInterface(Ci.nsIComponentRegistrar);
compMgr.unregisterFactoryLocation(CLASS_ID, location);
var catMan = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
catMan.deleteCategoryEntry('command-line-handler', CATEGORY);
},
canUnload: function (compMgr) {
return true;
}
};
function NSGetModule(comMgr, fileSpec) {
return Module;
}