Closed
Bug 642987
Opened 14 years ago
Closed 12 years ago
PyXPCOM should allow callabales to be used as [function] interfaces
Categories
(Other Applications Graveyard :: PyXPCOM, defect)
Other Applications Graveyard
PyXPCOM
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: mark.yen, Assigned: mark.yen)
Details
Attachments
(1 file)
|
5.46 KB,
patch
|
Details | Diff | Splinter Review |
See attached patch. Interfaces marked as [function] (such as nsIDOMEventListener) can be implemented in JavaScript as functions; this patch does the equivalent for Python.
Not quite sure the patch is good enough as-is, particularly since I have yet to figure out how unit testing works in this area of code.
Attachment #520309 -
Flags: review?
| Assignee | ||
Updated•14 years ago
|
Attachment #520309 -
Flags: review? → review?(toddw)
Comment 1•14 years ago
|
||
Any ideas for a test case on this? As I'm still not sure how callables are meant to be used.
| Assignee | ||
Comment 2•14 years ago
|
||
called = False
def observe(subject, topic, data):
called = True
sip = components.classes["@mozilla.org/supports-interface-pointer;1"]\
.createInstance(components.interfaces\
.nsISupportsInterfacePointer)
sip.data = observe
sip.data.QueryInterface(components.interferfaces.nsIObserver)\
.observe(None, "topic", None)
assert(called)
Basically, it makes it possible to pass in Python functions in places where things like nsIObserver (and other XPCOM interfaces marked as [function]) are expected. (In this case, of course, actually hooking it up to nsIObserverService or something would be the typical use case)
Comment 3•13 years ago
|
||
This needs a isfunction check - because I could also have a class that implements __call__, then if I was using a class instance in this case it would trigger the __call__ method, instead of the class instance method.
| Assignee | ||
Comment 4•12 years ago
|
||
Comment on attachment 520309 [details] [diff] [review]
support [function]
Hrm. This got checked in in https://hg.mozilla.org/pyxpcom/rev/f4a3b01293f5 for some reason. Poked around more, fixed up in https://hg.mozilla.org/pyxpcom/rev/67a18ad95aab in cases where we have:
class Foo(object):
_com_interfaces_ = [components.interfaces.nsIObserver]
def observe(self, s, t, d):
print("observe")
def __call__(self, *args):
print "should not call me")
sip.data = Foo()
sip.data.QueryInterface(components.interfaces.nsIObserver).observe(None, "", "")
(It would previously prefer __call__ when *calling* things that are not getters/setters; it now only uses it if the named method doesn't exist.)
Attachment #520309 -
Flags: review?(toddw)
| Assignee | ||
Updated•12 years ago
|
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Updated•7 years ago
|
Product: Other Applications → Other Applications Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•