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 17146 - [Custom]: Constructor generation algorithm doesn’t create the right prototype chain
Summary: [Custom]: Constructor generation algorithm doesn’t create the right prototype...
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:
Depends on:
Blocks: 14968
  Show dependency treegraph
 
Reported: 2012-05-22 02:30 UTC by Dominic Cooney
Modified: 2012-06-04 06:54 UTC (History)
0 users

See Also:


Attachments

Description Dominic Cooney 2012-05-22 02:30:29 UTC
Specifically in this part:

"Create a new JavaScript object with BASE as prototype"

This is a ambiguous because BASE is described as "a DOM element which implements the HTMLElement interface." Is it an instance of a DOM element? Or the constructor like HTMLFooElement?

Anyway, the prototype of the new JavaScript object should be BASE.prototype, eg HTMLDivElement.prototype.

Probably more precise prose is required here because not all HTML elements have specific unique prototypes (eg INS, DEL both use HTMLModElement.)

Can I suggest replacing step 1 with language like:

Let BASEINTERFACE be the DOM Interface used by BASE.
Create a new JavaScript object with BASEINTERFACE.prototype as the prototype.
Comment 1 Dimitri Glazkov 2012-05-24 00:01:18 UTC
(In reply to comment #0)
> Specifically in this part:
> 
> "Create a new JavaScript object with BASE as prototype"
> 
> This is a ambiguous because BASE is described as "a DOM element which
> implements the HTMLElement interface." Is it an instance of a DOM element? Or
> the constructor like HTMLFooElement?
> 
> Anyway, the prototype of the new JavaScript object should be BASE.prototype, eg
> HTMLDivElement.prototype.
> 
> Probably more precise prose is required here because not all HTML elements have
> specific unique prototypes (eg INS, DEL both use HTMLModElement.)
> 
> Can I suggest replacing step 1 with language like:
> 
> Let BASEINTERFACE be the DOM Interface used by BASE.
> Create a new JavaScript object with BASEINTERFACE.prototype as the prototype.

This is tricky. We're trying to dance around the notion of DOM element prototypes without naming them directly. I feel like the BASEINTERFACE.prototype is a cop-out.

Could you not take var div = document.createElement('div') and treat it as a prototype for a custom DOM element. Why not?
Comment 2 Dominic Cooney 2012-05-29 01:31:25 UTC
(In reply to comment #1)
> This is tricky. We're trying to dance around the notion of DOM element
> prototypes without naming them directly. I feel like the
> BASEINTERFACE.prototype is a cop-out.

I think you need to embrace the fact that this interacts with JavaScript. The BASEINTERFACE.prototype is clumsy because it is pseudo-JavaScript syntax. Why not adopt language from the Web IDL spec for referring to the prototype?

> Could you not take var div = document.createElement('div') and treat it as a
> prototype for a custom DOM element. Why not?

You could, but it would be bad for these reasons:

- document.createElement could have been replaced by script, so you would need all this torturous language to refer to the real createElement that would be worse than just referring to the prototype that you mean.

- it ends up creating a superfluous div *instance* to sit on the prototype chain. Do you want to require implementations make the following madness work?

var c = /* create custom element */;
document.body.appendChild(c);
document.body.appendChild(Object.getPrototypeOf(c));
// look upon my document oh ye mighty and despair
Comment 3 Dimitri Glazkov 2012-05-30 20:25:34 UTC
http://dvcs.w3.org/hg/webcomponents/rev/cfed72372d62

WDYT? Please reopen if I still didn't get it :)
Comment 4 Dominic Cooney 2012-06-04 06:54:11 UTC
Looks good.

I am not confident this step is necessary:

Set the [[Construct]] internal method on CONSTRUCTOR

since presumably [[Construct]] is implicitly there by virtue of this being a function object.

If the spec has non-normative comments, it might be worth pointing out that the "prototype" property has certain properties specified in the Web IDL spec, just like the Web IDL spec points out itself for interface objects <http://www.w3.org/TR/WebIDL/#interface-object> ie the part that reads:

Since an interface object for a non-callback interface is a function object, it will have a “prototype” property with attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.