On Thu, May 4, 2017 at 7:39 PM, Nathan Froyd <nfr...@mozilla.com> wrote:
> On Thu, May 4, 2017 at 12:32 PM, Henri Sivonen <hsivo...@hsivonen.fi> wrote:
>> On Thu, May 4, 2017 at 4:27 PM, Nathan Froyd <nfr...@mozilla.com> wrote:
>>> On Thu, May 4, 2017 at 3:08 AM, Henri Sivonen <hsivo...@hsivonen.fi> wrote:
>>>> Is it feasible (with reasonably low effort) to introduce a new XPIDL
>>>> type that is a pointer to a non-refcounted immutable static object in
>>>> C++ and still gets bridged to JS?
>>>
>>> You can certainly have static objects with what amount to dummy
>>> AddRef/Release methods passed through XPIDL (we do this in a couple of
>>> places throughout Gecko), but I don't think you can get away with
>>> having a non-refcounted object passed through XPIDL.
>>
>> Do the AddRef/Release need to be virtual?
>
> Yes.  (I'm not sure how XPConnect would discover the refcounting
> methods if they were non-virtual.)
>
> Please note that the static objects with dummy AddRef/Release methods
> also implement XPConnect interfaces, i.e. QueryInterface, nsresult
> virtual methods, etc.

OK. That doesn't fit my case. There's nothing virtual on either the
C++ or Rust side about mozilla::Encoding / encoding_rs::Encoding. All
the instances come from the Rust side and the interpretation of the
pointer just changes when crossing the FFI so that C++ thinks it's a
pointer to mozilla::Encoding. On the C++ side, the (all non-virtual)
methods take the "this" pointer and send it back to Rust as the first
argument to FFI.

> I think you could possibly make your things a WebIDL interface, which
> don't require refcounting, and magically make the WebIDL interfaces
> work with XPIDL, but I do not know the details there.

I'll keep that in mind. Thanks.

Another option is to have dual methods on objects that are accessed
from both C++ and JS: A non-scriptable method that takes const
mozilla::Encoding* and a scriptable method that takes something else:
either a string containing a name or some kind of manually-applied
XPCOM/XPIDL-ish wrapper for const mozilla::Encoding*. It just would be
nice for the wrapping part to be automagic in the binding.

-- 
Henri Sivonen
hsivo...@hsivonen.fi
https://hsivonen.fi/
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to