Making WrapNative less needed?

31 views
Skip to first unread message

Doug Turner

unread,
Jun 5, 2012, 11:56:22 AM6/5/12
to bzba...@mozilla.com, bho...@mozilla.com, pet...@mozilla.com
Recently, I needed to change an IDL that was exposed to the web. It was using a fixed type nsIFoo. The spec changed and I needed to be able to return one of two different types: nsIFoo or nsIBar depending on how the API was used. So, I changed the interface parameter to an jsval. And now, I have to do alot of extra work which is unfortunate.

* I need to hold on to the window that was associated with the calls. In my case, we are jumping back and forth between threads (so that we can do IO or whatever). Since the DOM isn't thread safe, you need to do stupid comptr tricks using .swap(). You need to carefully ensure that every path leads to a release on the right thread.

* Another issue is that wrapping an object is an advanced and scary process. Questions like "is this window still okay to use?", "do I have the right context?", "Wtf is the difference between a js scope and a js context?".

Under the hood, when using a fixed type like nsIFoo we must be creating jsval's to pass into javascript. Is it possible to build some extra love in this code so that passing different types is easier and safer?

Doug

Ms2ger

unread,
Jun 5, 2012, 12:06:05 PM6/5/12
to
On 06/05/2012 05:56 PM, Doug Turner wrote:
> Recently, I needed to change an IDL that was exposed to the web. It
> was using a fixed type nsIFoo. The spec changed and I needed to be
> able to return one of two different types: nsIFoo or nsIBar depending
> on how the API was used. So, I changed the interface parameter to an
> jsval.

Let me stop you right here. Why not change it to nsISupports?

(Note that the new DOM bindings will support WebIDL unions, which are
exactly what you want here.)

Ms2ger

Kyle Huey

unread,
Jun 5, 2012, 12:17:27 PM6/5/12
to Ms2ger, dev-pl...@lists.mozilla.org
On Jun 5, 2012 9:10 AM, "Ms2ger" <ms2...@gmail.com> wrote:
>
> On 06/05/2012 05:56 PM, Doug Turner wrote:
>>
>> Recently, I needed to change an IDL that was exposed to the web. It
>> was using a fixed type nsIFoo. The spec changed and I needed to be
>> able to return one of two different types: nsIFoo or nsIBar depending
>> on how the API was used. So, I changed the interface parameter to an
>> jsval.
>
>
> Let me stop you right here. Why not change it to nsISupports?

Yes. That is the correct way to do this today. XPConnect will handle the
wrapping for you.

- Kyle

> (Note that the new DOM bindings will support WebIDL unions, which are
exactly what you want here.)
>
> Ms2ger
>
> _______________________________________________
> dev-platform mailing list
> dev-pl...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform

Doug Turner

unread,
Jun 5, 2012, 12:45:48 PM6/5/12
to mozilla.de...@googlegroups.com, Ms2ger, dev-pl...@lists.mozilla.org

> Yes. That is the correct way to do this today. XPConnect will handle the
> wrapping for you.


Perfect.

Doug Turner

unread,
Jun 5, 2012, 12:45:48 PM6/5/12
to Ms2ger, dev-pl...@lists.mozilla.org

> Yes. That is the correct way to do this today. XPConnect will handle the
> wrapping for you.


Perfect.
Reply all
Reply to author
Forward
0 new messages