Bug 706590 - API for implementing XPCOM interfaces #305
Conversation
} | ||
return headers; | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: defineLazyGetter is special, it is used to fetch and set an attribute lazily and only once:
https://developer.mozilla.org/en/JavaScript_code_modules/XPCOMUtils.jsm#defineLazyGetter%28%29
I'd imagine it has been used for performances reason. And it doesn't necessary worth its noise nor using mozilla-dark-feature use!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly it also assumes that this
represents a scope, which is valid now, but in of my loader prototypes it was not, so I'd prefer not to use it. If we need to be lazy just use a function that caches return value.
Conflicts: packages/addon-kit/lib/widget.js packages/api-utils/lib/observer-service.js packages/api-utils/lib/xpcom.js packages/api-utils/tests/test-xpcom.js
…nflicts with E4X.
…stance` to create new instances as suggested by @ochameau
throw e; | ||
else | ||
throw Cr.NS_ERROR_FAILURE; | ||
return this.component.QueryInterface(iid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my long comment first, #305 (comment)
but it seems broken, it looks like you are calling prototype method instead of instance one?
We would need something like:
if (this.singleton)
return this.singleton;
this.singleton = this.component.new();
return this.singleton.QueryInterface(iid);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what you suggested above was a better. I don't think of a service as of a static object, I think of it as a static object. If one needs singleton component it should be his responsibility to implement a factory with such a new
method that creates only one instance.
See my commens on #305 (comment) below:
I do agree, I'll change that
I guess it will make sense. It's just
Yeah I have been thinking back and forth on this & finally decided that it was more logical this way, since most of the XCOM components that require initialization implement
I see your point, but I would like to avoid introduction of yet another requirement, the whole API is no longer simple :( What about generation of those |
BTW thanks for the detailed comments, this really helps when fighting with XPCOM demons!! |
…inherits from `Unknown`.
@ochameau I consider this to be ready. Can you please take another look at it ? |
throw e; | ||
else | ||
throw Cr.NS_ERROR_FAILURE; | ||
return this.create().QueryInterface(iid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wrong identation on return this.create().QueryInterface(iid);
Tests are failing in test-request.js/test-weakmaps.js. There is a first issue here: |
@ochameau what are you testing against ? All tests pass on my machine both on nightly and stable FF. Are you sure you don't have any local changes or something ? |
I was testing on FF10, but I'm not able to reproduce anymore :/ You may want to fix In anycase, I r+ this patch again. On a side note, I went through Openwebapp source code, and I haven't seen any usecase of xpcom.js. Thanks again for this patch, I really like this module! |
If JSON.parse would have failed then it would be
I'll create a new bug for that.
I'll drop them a note about this ;) Thanks! |
fix bug 706590 - API for implementing XPCOM interfaces r=@ochameau
https://bugzilla.mozilla.org/show_bug.cgi?id=706590
This change modifies
xpcom
module in order to:Please note: This work branched out from #263 since it depends on those changes.