RFE: IDLified generic callback function type




17 years ago
17 years ago


(Reporter: akkzilla, Assigned: dougt)



Firefox Tracking Flags

(Not tracked)




17 years ago
I shouldn't have to define a whole new type each time I write a class that needs
a callback function.  But there seems to be no such generic type.  There's
nsIObserver, but it returns strings; functions or pointers would be cleaner for
most applications.  Cc'ing some folks who were involved in the IRC discussion.

Comment 1

17 years ago
It would be *really* sweet if you could just pass in a JavaScript or Python 
function and XPConnect/PyXPCOM would Do The Right Thing.

Comment 2

17 years ago
I like objects. Callback functions are *so* '70s.

How do you call a generic callback function from C++? What are the parameters?

XPConnect has support for [function] interfaces. See 

You can create [function] interfaces, but you need to specify specific call 
signatures. What is generic about that.

Comment 3

17 years ago
> It would be *really* sweet if you could just pass in a JavaScript or Python 
> function and XPConnect/PyXPCOM would Do The Right Thing.

XPConnect *does* do the right thing. In JS functions are objects. They can have 
functions attached to them (now or later - by the time call time rolls around). 
If the caller assert that foo implements an interface then xpconnect believes 
the caller.

BTW, I think it would really suck if people started writing and using a bunch of 
[function] interfaces.

Comment 4

17 years ago
why?  I missing the point.  what jband said.  Use interfaces if you want to do
something like this.
Last Resolved: 17 years ago
Resolution: --- → WONTFIX

Comment 5

17 years ago
The point was not to have to define a new type for each new class that ever
needs to do asynchronous notification.  It bloats our source tree and our app to
define all these classes that are only used once, rather than having a generic
class which is general purpose and might be reusable.  I just got this silly
idea that reuse of classes, and bloat reduction, were good ideas.  Sorry.

Comment 6

17 years ago
akkana: Show us the patch. What is the magical callback signature that can be
reused so widely?

Comment 7

17 years ago
Maybe an object which has a function which takes an nsresult and a generic
nsISupports?  Something like this:

interface nsINotification : nsISupports
  void notify(nsISupports object, nsresult status);

We probably already have such an object, buried somewhere -- I just didn't know
where to look, and when I asked on IRC I got several responses agreeing that it
would be useful and encouraging me to file an RFE, so I did.

Turns out I no longer need this myself at the moment -- the class I was working
on got folded into another set of APIs at the request of the module owners.  And
maybe it's too late for this because everybody's already written a bazillion
different callback object classes and wouldn't think to look for the generic
one. That would be a documentation issue more than anything.
You need to log in before you can comment on or make changes to this bug.