Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Attribute getter naming in WebIDL bindings

27 views
Skip to first unread message

Boris Zbarsky

unread,
Aug 29, 2012, 4:20:15 PM8/29/12
to
Right now, attribute getters always get prefixed with "Get" in the
WebIDL bindings. So "readonly attribute long foo" becomes "int32_t
GetFoo()" in the C++.

Would it make sense to drop the Get in certain cases? In particular, in
cases in which:

1) The getter is infallible.
2) The return value is not returned via an outparam.
3) The return value is not an interface type or is not nullable.

So this IDL:

readonly attribute long foo;
readonly attribute Iface bar;
readonly attribute Iface? baz;

would become:

int32_t Foo();
already_AddRefed<Iface> Bar();
already_AddRefed<Iface> GetBaz();

(with Iface* instead in cases when the getter is not an addreffing getter).

Thoughts?

-Boris

Kyle Huey

unread,
Aug 29, 2012, 4:32:33 PM8/29/12
to Boris Zbarsky, dev-pl...@lists.mozilla.org
Sounds great!

- Kyle

Ehsan Akhgari

unread,
Aug 29, 2012, 7:27:33 PM8/29/12
to Kyle Huey, Boris Zbarsky, dev-pl...@lists.mozilla.org
On 12-08-29 4:32 PM, Kyle Huey wrote:
>> Thoughts?
>>
>
> Sounds great!

Sounds lovely!

Ehsan

Ms2ger

unread,
Aug 30, 2012, 4:16:31 AM8/30/12
to
It certainly looks nicer, but I'm not a big fan of complicating the
rules for assembling the C++ signature from the WebIDL. XPIDL's
consistency here, IMO, saves time when implementing an interface: you
can focus on the actual implementation, rather than the binding code.

HTH
Ms2ger

Jonas Sicking

unread,
Aug 30, 2012, 8:26:07 AM8/30/12
to Boris Zbarsky, dev-pl...@lists.mozilla.org
On Wed, Aug 29, 2012 at 5:20 PM, Boris Zbarsky <bzba...@mit.edu> wrote:
> Right now, attribute getters always get prefixed with "Get" in the WebIDL
> bindings. So "readonly attribute long foo" becomes "int32_t GetFoo()" in
> the C++.
>
> Would it make sense to drop the Get in certain cases? In particular, in
> cases in which:
>
> 1) The getter is infallible.
> 2) The return value is not returned via an outparam.
> 3) The return value is not an interface type or is not nullable.
>
> So this IDL:
>
> readonly attribute long foo;
> readonly attribute Iface bar;
> readonly attribute Iface? baz;

What would

readonly attribute long? bin;

compile into? If it compiles into something called GetBin then we'd
have a nice consistency that any getters for nullable types are named
GetX and any getters for non-nullable types are named X.

/ Jonas

Boris Zbarsky

unread,
Aug 30, 2012, 9:02:19 AM8/30/12
to
On 8/30/12 4:16 AM, Ms2ger wrote:
> It certainly looks nicer, but I'm not a big fan of complicating the
> rules for assembling the C++ signature from the WebIDL. XPIDL's
> consistency here, IMO, saves time when implementing an interface: you
> can focus on the actual implementation, rather than the binding code.

One of the goals, honestly, is to have the xpidl getters look exactly
like the C++ getters you'd have if you just wrote C++ getters (or for
that matter like the ones you probably already have).

That is, ideally WebIDL maps to the API you'd pick for your C++ class
for C++ consumers anyway.

-Boris

Boris Zbarsky

unread,
Aug 30, 2012, 9:06:50 AM8/30/12
to
On 8/30/12 8:26 AM, Jonas Sicking wrote:
> What would
>
> readonly attribute long? bin;
>
> compile into? If it compiles into something called GetBin then we'd
> have a nice consistency that any getters for nullable types are named
> GetX and any getters for non-nullable types are named X.

I was going to make it GetBin after thinking about it, yeah.

Specifically, it would be:

Nullable<int32_t> GetBin();

So my specific logic was going to be like so:

if (fallible || retval_nullable || retval_outparam) {
// prepend "Get"
}

-Boris

Jonas Sicking

unread,
Aug 30, 2012, 10:34:36 AM8/30/12
to Boris Zbarsky, dev-pl...@lists.mozilla.org
Sounds great!

/ Jonas
0 new messages