This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 20299 - [Custom]: Extensions to the document interface are not valid WebIDL
Summary: [Custom]: Extensions to the document interface are not valid WebIDL
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
: 20242 (view as bug list)
Depends on:
Blocks: 17103
  Show dependency treegraph
 
Reported: 2012-12-08 02:01 UTC by Boris Zbarsky
Modified: 2012-12-11 19:31 UTC (History)
4 users (show)

See Also:


Attachments

Description Boris Zbarsky 2012-12-08 02:01:52 UTC
The spec draft says:

  partial interface Document { 
    Function register(DOMString name, optional Options options);
  } 
  dictionary Options { 
    object? prototype; 
    DocumentFragment? template; 
    LifecycleCallbacks? lifecycle; 
  }
  dictionary LifecycleCallbacks {
     void created(); 
  }

There are a bunch of issues here:

1) There need to be semicolons between the toplevel things.
2) Putting a generic name like "Options" in a flat namespace is a bit weird.  It
   needs a name that's less likely to be confusing to people and less likely to
   cause collisions.
3) "optional" is not valid on dictionary arguments.  They're always optional, so
   adding it gives you a parse error.
4) LifecycleCallbacks is presumably meant to be a callback interface, not a
   dictionary right?  But did you really want to use a callback interface here,
   not a callback function?
5) There seems to be some confusion in the prose that follows because it only
   talks about what to do if "prototype" is missing, say, not what to do if
   it's null.  Strictly speaking, the current spec says to throw if it's null,
   but then it makes no sense to declare it nullable in the dictionary.
6) Nothing says what should happen if "template" is missing.
7) Nothing says what should happen if "callbacks" are missing.

In any case, something like this might be more what you meant:

  callback ElementConstructor = Element();
  partial interface Document { 
    ElementConstructor register(DOMString name,
                                ElementRegistrationOptions options);
  };
  dictionary ElementRegistrationOptions { 
    object? prototype = null; 
    DocumentFragment? template = null; 
    LifecycleCallbacks? lifecycle = null; 
  };
  callback interface LifecycleCallbacks {
     void created(); 
  };

and then you don't have to worry about missing optional things, only null ones.
Comment 1 Boris Zbarsky 2012-12-10 04:16:33 UTC
> 3) "optional" is not valid on dictionary arguments.  They're always optional,
>     so adding it gives you a parse error.

Sorry, that part is a lie.  It's omitting the "optional" that's not OK.

The rest is still true, I believe.  ;)
Comment 2 Dimitri Glazkov 2012-12-10 21:42:27 UTC
(In reply to comment #0)

Thank you for looking this over!

> The spec draft says:
> 
>   partial interface Document { 
>     Function register(DOMString name, optional Options options);
>   } 
>   dictionary Options { 
>     object? prototype; 
>     DocumentFragment? template; 
>     LifecycleCallbacks? lifecycle; 
>   }
>   dictionary LifecycleCallbacks {
>      void created(); 
>   }
> 
> There are a bunch of issues here:
> 
> 1) There need to be semicolons between the toplevel things.

http://dvcs.w3.org/hg/webcomponents/rev/7a51557797a9

> 2) Putting a generic name like "Options" in a flat namespace is a bit weird.
> It
>    needs a name that's less likely to be confusing to people and less likely
> to
>    cause collisions.

http://dvcs.w3.org/hg/webcomponents/rev/80d7af3a9111

> 3) "optional" is not valid on dictionary arguments.  They're always
> optional, so
>    adding it gives you a parse error.

Good thing I saw your next comment :P

> 4) LifecycleCallbacks is presumably meant to be a callback interface, not a
>    dictionary right?  But did you really want to use a callback interface
> here,
>    not a callback function?

Oh yes! Callback interface is a better fit.

http://dvcs.w3.org/hg/webcomponents/rev/cb0d68b7de41

As for being the function -- there will be more callbacks in this dictionary:

https://www.w3.org/Bugs/Public/show_bug.cgi?id=18748
http://www.w3.org/TR/components-intro/#appendix-a-interfaces
(Note, this document is out of date, I haven't gotten to catching it up with the rest of the specifications yet).

> 5) There seems to be some confusion in the prose that follows because it only
>    talks about what to do if "prototype" is missing, say, not what to do if
>    it's null.  Strictly speaking, the current spec says to throw if it's
> null,
>    but then it makes no sense to declare it nullable in the dictionary.

http://dvcs.w3.org/hg/webcomponents/rev/3fa09764a196

> 6) Nothing says what should happen if "template" is missing.

http://dvcs.w3.org/hg/webcomponents/rev/6a0c8a13f13d

> 7) Nothing says what should happen if "callbacks" are missing.

With the null/missing treatment unified, the steps now make sense.
 
> In any case, something like this might be more what you meant:
> 
>   callback ElementConstructor = Element();
>   partial interface Document { 
>     ElementConstructor register(DOMString name,
>                                 ElementRegistrationOptions options);
>   };
>   dictionary ElementRegistrationOptions { 
>     object? prototype = null; 
>     DocumentFragment? template = null; 
>     LifecycleCallbacks? lifecycle = null; 
>   };
>   callback interface LifecycleCallbacks {
>      void created(); 
>   };
> 
> and then you don't have to worry about missing optional things, only null
> ones.

Did I get them all? :)

Not sure whether I should just use function ElementConstructor syntax yet. Sent mail to the list.
Comment 3 Dimitri Glazkov 2012-12-10 21:44:51 UTC
*** Bug 20242 has been marked as a duplicate of this bug. ***
Comment 4 Boris Zbarsky 2012-12-10 22:04:37 UTC
> Did I get them all? :)

Looks like it, yes.  I wouldn't worry too much about the exact type of ElementConstructor for the moment, while WebIDL gets sorted out around there.
Comment 5 Dimitri Glazkov 2012-12-10 22:17:26 UTC
(In reply to comment #4)
> > Did I get them all? :)
> 
> Looks like it, yes.  I wouldn't worry too much about the exact type of
> ElementConstructor for the moment, while WebIDL gets sorted out around there.

Cool! Filed bug 20329 so I don't forget.
Comment 6 William Chen 2012-12-11 19:09:01 UTC
The use of "prototype" as an identifier in the ElementRegistrationOptions dictionary is also invalid because it's a reserved identifier.

http://www.w3.org/TR/WebIDL/#idl-names
Comment 7 Boris Zbarsky 2012-12-11 19:14:04 UTC
That seems like a WebIDL bug to me, at first glance...
Comment 8 Dimitri Glazkov 2012-12-11 19:31:37 UTC
(In reply to comment #6)
> The use of "prototype" as an identifier in the ElementRegistrationOptions
> dictionary is also invalid because it's a reserved identifier.
> 
> http://www.w3.org/TR/WebIDL/#idl-names

Filed bug 20346 to track this.

First reaction same as Boris' --> unless the object is a Function, seems like .prototype should be allowed.