forked from bard/mozrepl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added command line handler for -repl switch.
darcs-hash:20070628003442-8cc29-298f36b0f15c257f4a9acd3b5db6466bd6cda7ea.gz
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
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; | ||
} | ||
|