David Brittain wrote:
>
> In C++, it not a problem. Neither is it in Java where using the #pragma
> directive in IDL you can get the generated Java file to be placed in a
> package. However, in javascript in seems that there is a problem.
>
> In the scripting interface for our product we have the following sort of
> structure:
>
> interface IBrowser
> {
> INode getNode();
> }
>
> interface INode
> {
> function1();
> }
>
> interface IImage : INode
> {
> function2();
> }
>
> Now if the IBrowser interface returns an INode which actually is on an
> object that supports the IImage interface, then the only way to call
> function2() is by using QI to get the IImage interface.
>
> It's bad enough that we have to call QI (which we don't have to do
> under IE or NS4.x) but if we also have to use IID's in javascript (can
> you do this?)
No. Only named interfaces are allowed.
I am working on an extention to xpconnect that does what we call
'flattening'. The idea is that xpconnect will automatically
flatten the view of the interfaces of an object. So, JS code for
your example above would see an object containing all of the
methods of each of the interfaces on the object.
This will require the native object implementor to give us access
to a 'ClassObject' from which the set of interfaces can be
discovered by xpconnect in order to make use of the feature.
There are issues with potential shadowing of like-named methods
and a scheme for disambiguation. We need this all in order to
convert the DOM system away from its big bundle of generated C++
code and toward using xpconnect. I am working on this. It will
not be ready to deploy for some time.
John.
> then I think we're going to have a tough job getting our
> content guys to write any content that works on NS6.
>
> Is there any other way of doing this? One thing I looked at was using
> nsIXPCScriptable, am I right in thinking that this can be used to
> dynamically query an interface for the methods that it supports? This
> looked quite scary to use though!
I doubt you'd want to go there.
QI is not fun. But its not the end of the world either.
>
> Dave
>
> Pierre Phaneuf wrote:
>
> > David Brittain wrote:
> >
> >> var interface = plugin.QueryInterface(Components.interfaces.IPlugin);
> >>
> >> In this case how does javascript know which IPlugin to use, given that
> >> there may be a number of interfaces called IPlugin. As I understand it
> >> the namespace feature in XPCOM is not implemented, therefore is there
> >> not a problem with multiple vendors providing components which have the
> >> same interface names. Is there any way to get around this?
> >
> >
> > In C++, the parameter to QueryInterface is a UUID (universally unique
> > ID), and thus does not need a namespace.
> >
> > For JavaScript, this might be a bit "looser"...
> >