On Aug 24, 8:35 pm, "Jake Donham" <[EMAIL PROTECTED]> wrote:
> Hi list,
>
> I am very confused about the role of QueryInterface when using XPCOM
> from Javascript. For instance, there are many nsI{Foo}Window
> interfaces, but I see extension code that uses methods from different
> interfaces without QIing among them. Is this behavior particular to
> windows or a general XPCOM/XPConnect thing? Does this have something
> to do with "aggregated" interfaces? What about "flattened" Javascript
> wrappers? (I came across these terms but could find no definition of
> them.)
>
> If I understand correctly, QueryInterface (and instanceof) can be used
> for their side-effect, which is to cache a "tear-off"--the underlying
> C++ object appropriately cast--of the interface so that future method
> calls against that interface succeed. What I can't figure out is what
> happens (or is supposed to happen) if you make a call against an
> interface for which no tear-off is cached--is one added automatically?
>
> Is there a page somewhere that lays this all out for the uninitiated
> (uninitialized?) among us? Many thanks,
>
> JakeJake, QueryInterface is only necessary when dealing with XPCOM / IDL objects in JS or C++ (you probably already knew that). Regular JS objects don't require QueryInterface. IDL is used to define interfaces. Interfaces can inherit from other interfaces (you probably already knew that too). Use QueryInterface to make JS (or probably XPConnect) aware of the interfaces supported by an object. Also note that QueryInterface works slightly different in JS than C++. In JS QueryInterface works _on_ the calling object, so you don't need to use a return value: var foo = bar.QueryInterface(nsIFoo); foo.fooMethod(); // or skip the return var bar.QueryInterface(nsiFoo) bar.fooMethod(); Interface "flattening" is a process where you can make an object that requires _no_ QueryInterfaces because XPConnect already knows about all the interfaces the object supports. This is done using nsIClassInfo see: http://www.mozilla.org/projects/xpcom/nsIClassInfo.html#Whats_interface_flattening Note: parts of my summary could be completely wrong :) _______________________________________________ dev-tech-xpcom mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-xpcom
