views:

218

answers:

1

I am beta testing an application that includes a Firefox extension as one component. It was originally deployed when FF3.5.5 was the latest version, and survived 3.5.6 and 3.5.7. However on FF3.6 I'm getting the following in my error console:

Warning: reference to undefined property Components.interfaces.nsIProcess2
Source file: chrome://overthewall/content/otwhelper.js
Line: 55

Error: Component returned failure code: 0x80570018 (NS_ERROR_XPC_BAD_IID) 
         [nsIJSCID.createInstance]
Source file: chrome://overthewall/content/otwhelper.js
Line: 55

The function throwing the error is:

48 function otwRunHelper(cmd, aCallback) {
49  var file =
50      Components.classes["@mozilla.org/file/local;1"].
51      createInstance(Components.interfaces.nsILocalFile);
52  file.initWithPath(otwRegInstallDir+'otwhelper.exe');
53
54  otwProcess = Components.classes["@mozilla.org/process/util;1"]
55                  .createInstance(Components.interfaces.nsIProcess2);
56
57  otwProcess.init(file);
58  var params = new Array();
59  params = cmd.split(' ');
60  
61  otwNextCallback = aCallback;
62  otwObserver = new otwHelperProcess();
63  otwProcess.runAsync(params, params.length, otwObserver, false);
64 }

As you can see, all this function does is run an external EXE helper file (located by a registry key) with some command line parameters and sets up an Observer to asynchronously wait for a response and process the Exit code.

The offending line implies that Components.interfaces.nsIProcess2 is no longer defined in FF3.6. Where did it go? I can't find anything in the Mozilla documentation indicating that it has been changed in the latest release.

+3  A: 

The method on nsIProcess2 was moved to nsIProcess. For your code to work in both versions, change this line:

otwProcess = Components.classes["@mozilla.org/process/util;1"]
                .createInstance(Components.interfaces.nsIProcess2);

to this:

otwProcess = Components.classes["@mozilla.org/process/util;1"]
                .createInstance(Components.interfaces.nsIProcess2 || Components.interfaces.nsIProcess);

You will still get the warning, but the error will go away, and your code will work just fine in both versions. You could also store the interface iid in a variable and use the variable:

let iid = ("nsIProcess2" in Components.interfaces) ?
  Components.interfaces.nsIProcess2 :
  Components.interfaces.nsIProcess;
otwProcess = Components.classes["@mozilla.org/process/util;1"]
                .createInstance(iid);
sdwilsh
Fantastic. Thanks!!! I missed the one liner in the Mozilla docs pointing this out.
rwired
To be fair, you didn't miss it. I just told the guy who made the change to update the docs yesterday because of your question. :)
sdwilsh