B2G/gecko/browser/devtools/commandline/CmdCmd.jsm
/**
 * Load the commands from a single file
 * @param nsIFile aFile The file containing the commands that we should read
 * @param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which
 * we eval the script from the .mozcmd file. This should be a chrome window.
 */
Load the commands from a single file
@param nsIFile aFile The file containing the commands that we should read
@param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which
we eval the script from the .mozcmd file. This should be a chrome window.
Load the commands from a single file @param nsIFile aFile The file containing the commands that we should read @param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which we eval the script from the . mozcmd file . This should be a chrome window .
function loadCommandFile(aFile, aSandboxPrincipal) {
  NetUtil.asyncFetch(aFile, function refresh_fetch(aStream, aStatus) {
    if (!Components.isSuccessCode(aStatus)) {
      console.error("NetUtil.asyncFetch(" + aFile.path + ",..) failed. Status=" + aStatus);
      return;
    }
    let source = NetUtil.readInputStreamToString(aStream, aStream.available());
    aStream.close();
    let sandbox = new Cu.Sandbox(aSandboxPrincipal, {
      sandboxPrototype: aSandboxPrincipal,
      wantXrays: false,
      sandboxName: aFile.path
    });
    let data = Cu.evalInSandbox(source, sandbox, "1.8", aFile.leafName, 1);
    if (!Array.isArray(data)) {
      console.error("Command file '" + aFile.leafName + "' does not have top level array.");
      return;
    }
    data.forEach(function(commandSpec) {
      gcli.addCommand(commandSpec);
      commands.push(commandSpec.name);
    });
  }.bind(this));
}
function loadCommandFile ( aFile , aSandboxPrincipal ) { NetUtil . asyncFetch ( aFile , function refresh_fetch ( aStream , aStatus ) { if ( ! Components . isSuccessCode ( aStatus ) ) { console . error ( "NetUtil.asyncFetch(" + aFile . path + ",..) failed. Status=" + aStatus ) ; return ; } let source = NetUtil . readInputStreamToString ( aStream , aStream . available ( ) ) ; aStream . close ( ) ; let sandbox = new Cu . Sandbox ( aSandboxPrincipal , { sandboxPrototype : aSandboxPrincipal , wantXrays : false , sandboxName : aFile . path } ) ; let data = Cu . evalInSandbox ( source , sandbox , "1.8" , aFile . leafName , 1 ) ; if ( ! Array . isArray ( data ) ) { console . error ( "Command file '" + aFile . leafName + "' does not have top level array." ) ; return ; } data . forEach ( function ( commandSpec ) { gcli . addCommand ( commandSpec ) ; commands . push ( commandSpec . name ) ; } ) ; } . bind ( this ) ) ; }
Load the commands from a single file
 @param nsIFile aFile The file containing the commands that we should read
 @param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which
 we eval the script from the .mozcmd file.
Load the commands from a single file @param nsIFile aFile The file containing the commands that we should read @param nsIPrincipal aSandboxPrincipal Scope object for the Sandbox in which we eval the script from the . mozcmd file .