RE: [WebIDL] Would it make sense to add annotations for "creates a new object each time" and "always returns the same object"?

> From: Marcos Caceres [mailto:w3c@marcosc.com]
> 
> On Thursday, October 18, 2012 at 3:11 PM, Boris Zbarsky wrote:
> 
> > Consider a method declaration like so:
> >
> > MyInterface getFoo();
> >
> > It's impossible to tell from that IDL whether you get back the same
> > object every time or whether the same object is returned each time, or
> > whether it's sometimes the same and sometimes a new one. Generally you
> > have to rely on the prose to indicate that, and often the writers of the
> > prose forget to do so.
> >
> > In Gecko, we have found it useful to annotate methods and attributes
> > with this sort of information (we use [Creator] for methods that always
> > return a new object and we're about to add an annotation for attributes
> > that always return the same object, but we haven't decided on a name for
> > it yet).
> >
> > Would it make sense to add such annotations to WebIDL so that this sort
> > of thing doesn't have to be described in prose?
> >
> 
> I would be in favor of this. For example, the JS i18n API returns you a
> different object when you ask it for "resolved options". As an author, it
> would be nice to see at a glance that you get a distinct object. And as a
> tester, it could add some trivial automation to testing a method's
> behavior.

I naively assumed that all interface-typed objects returned the same instance 
when the calling params and API behavior finds a "same" object (e.g., getAttributeNode).

This distinction is already clear (at least to me) when using types such as T[] vs sequence<T> and
objects that are dictionary vs. interface. What are the exceptions to this rule?

Received on Thursday, 18 October 2012 15:37:51 UTC