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 21947 - [Custom]: Clarify registering HTMLElement.prototype as a prototype multiple times
Summary: [Custom]: Clarify registering HTMLElement.prototype as a prototype multiple t...
Status: RESOLVED INVALID
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 14968
  Show dependency treegraph
 
Reported: 2013-05-07 05:29 UTC by Dominic Cooney
Modified: 2013-05-07 05:48 UTC (History)
1 user (show)

See Also:


Attachments

Description Dominic Cooney 2013-05-07 05:29:42 UTC
If the author does this:

document.register('x-foo', {prototype: HTMLElement.prototype})

I think the current spec says implementations should throw a namespace error per step 5.4 (because HTMLElement does not inherit from HTMLElement.)

However that is really a coincidence; that step is designed to stop you extending elements outside the SVG and HTML namespaces.

I think defining multiple custom elements with the same prototype object should be an error (because the constructor property will be updated!) and extending HTMLElement.prototype directly sucks particularly because it is a widely shared object.

However if the decision is that a given prototype object can be used for multiple definitions, I think HTMLElement.prototype should be allowed to be (ab)used multiple times too.

Perhaps you could make document.register('x-foo', {prototype: HTMLElement.prototype}) to be sugar for Object.create(HTMLElement.prototype, {}) just like document.register('x-foo') is. The same could go for using any built-in interface prototype object directly like this.
Comment 1 Scott Miles 2013-05-07 05:41:06 UTC
I'm confused what you mean about overwriting the 'constructor' property. 

Normally, the constructor of a prototype is the thing that constructed the prototype, not any constructor it is attached to.

IOW,

  P = {};
  c = P.constructor;

  Foo = function() {};
  Foo.prototype = P;
  assert(P.constructor === c); // true

  Bar = function() {};
  Bar.prototype = P;
  assert(P.constructor === c); // true

Are these prototypes handled differently somehow?
Comment 2 Dominic Cooney 2013-05-07 05:48:50 UTC
Sorry, I misread the spec. The constructor generation algorithm says:

If PROTOTYPE is already an interface prototype object for any interface object or PROTOTYPE has a non-configurable property named constructor, throw a NotSupportedError and stop.

This is clear and obviates these issues. Sorry for the spam.