2

I noticed an occasional error logged on disabling the bootstrapped addon.

function shutdown:

function shutdown(data, reason) {

  forEachOpenWindow(unloadFromWindow);
  Services.wm.removeListener(WindowListener);
  Components.utils.unload('chrome://myaddon/content/main.jsm');
}

Sometimes, it came up with an error on disabling the addon:

NotFoundError: Node was not found main.jsm:112

Is it that the Components.utils.unload() is asynchronous?

1- Is that the case or is it due to some other issue?
2- If that is the case, how should it be dealt with?
3- Can the Components.utils.unload() be added to (processed in) the JSM that it is removing (removing itself)?
4- Any other suggestions?

Update:

Next test:
Disable -- no error
Enable/Disable -- 1 error (above)
Enable/Disable -- 2 error (above)
Enable/Disable -- 3 error (above)
Enable/Disable -- 4 error (above)
Enable/Disable -- 5 error (above)

Now that is strange ....

Update 2:
I found the problem.... typo/error in one of the listeners so it was NOT removed on shutdown() and with every subsequent enable/disable one more listeners was added...that was why the number of errors increased each time :)

erosman
  • 7,094
  • 7
  • 27
  • 46
  • While I can answer the question from your title, I cannot really comment on the sub-questions of why your code is broken: You simply did not provide enough code. Please update your question. – nmaier Jun 30 '14 at 08:13
  • I will explain it further. – erosman Jun 30 '14 at 09:17
  • Not enough. To debug actual code, actual code is needed. I also don't think the problem is with `Cu.unload`. – nmaier Jun 30 '14 at 09:56
  • Maybe ... I will look further into it but the (occasional) error goes away if `Components.utils.unload('chrome://myaddon/content/main.jsm');` is commented out. Also, since `console is undefined` the error is not with the code itself ;) – erosman Jun 30 '14 at 11:55
  • I wouldn't be so sure about that... – nmaier Jun 30 '14 at 12:01
  • @nmaier I updated my post (with strange findings). Is there a way that I can get you the code so you can see for yourself? – erosman Jun 30 '14 at 12:44
  • If your code does not fit into the question (after ripping out unnecessary parts), then at least quote the major areas and post the rest to github, bitbucket, pastebin or whatever. Also `console` isn't actually part of code modules (Didn't notice this before..). Makes me wonder where the `console` comes from?! Getting errors after the re-enabling the add-on point to the shutdown code not properly cleaning up or being broken in other subtle ways. – nmaier Jun 30 '14 at 12:53
  • @nmaier ...more code added .. I can upload the addon...but I have no private way of contacting you. – erosman Jun 30 '14 at 13:11
  • Well, SO is meant to profit everybody, so contacting me in private would defeat that. Either post the code somewhere public or I'll and everybody else will be unable to help you properly. – nmaier Jun 30 '14 at 14:39
  • 1
    @nmaier ... never mind... I found the problem...damn typo/error in one of the listeners so it was NOT removed on `shutdown()` and with every subsequent enable/disable one more listeners was added..that was why the number of errors increase each time :D – erosman Jun 30 '14 at 15:03

1 Answers1

2

Is Components.utils.unload asynchronous in Firefox bootstrapped extensions?

Cu.unload is not asynchronous. But also, it might not do what you expect.

It will just instruct the module loader to forget about it. Any references to the module instance from other code will still work, i.e. the module instance will be alive until all other references to it are gone and it can be garbage collected.

In that regard it can seem like unload is kinda asynchronous.

3- Can the Components.utils.unload() be added to (processed in) the JSM that it is removing (removing itself)?

Yes, the module can Cu.unload on itself. Code after Cu.unload will still work (see also the first part of my answer).

nmaier
  • 32,336
  • 5
  • 63
  • 78