<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>24020</bug_id>
          
          <creation_ts>2013-12-06 15:58:32 +0000</creation_ts>
          <short_desc>[Custom]: A tag name should be associated with the constructor and not the prototype</short_desc>
          <delta_ts>2015-07-06 08:16:49 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>HISTORICAL - Component Model</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>25669</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Erik Arvidsson">erik.arvidsson</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>dominicc</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>97248</commentid>
    <comment_count>0</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2013-12-06 15:58:32 +0000</bug_when>
    <thetext>Given how WebIdl works with interfaces that are realized as ES constructor functions with a prototype we should associate the tag name with a function and not the prototype.

class MyElement extends HTMLElement {}
associate(&apos;my-element, MyElement)

When an element is created for &apos;my-element&apos; we find the registered Function and call its @@create. Here is how HTMLElement @@create is implemented.

var constructorToNameMap = new WeakMap();

function associate(name, constr) {
  constructorToNameMap.set(constr, name);
}

HTMLElement[Symbol.create] = function() {
  var name = constructorToNameMap.get(this);
  if (!name)
    throw new TypeError(&apos;Illegal constructor&apos;);

  // $Internal_createElementWithName(name);
  return document.createElement(name);    
};

The common case is that people do not override @@create so we do not need to run any user code to create an instance. When the user does a `new MyElement` we do run the constructor, just like for all other js constructors.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>97287</commentid>
    <comment_count>1</comment_count>
    <who name="Dominic Cooney">dominicc</who>
    <bug_when>2013-12-08 00:32:29 +0000</bug_when>
    <thetext>I think this should be addressed in Level 2 of the Custom Elements spec, or in a related spec. Chrome is not in a position to implement this now.

The current implementation in Chrome associates the registered element name with the generated constructor. This is effectively the same data as the constructorToNameMap. So I think Chrome would have no problem implementing requirements based on your proposal.

I do not think the specification needs to be as literal as the JavaScript you have provided here, but it is a good informative sketch.

I think that the requirement that registering a Custom Element with a prototype that is an interface prototype object should be relaxed to allow multiple element names to share a prototype as is the case with built-in elements like HTMLHeadingElement, etc. Perhaps misuse of a built-in interface prototype object should be disallowed, however Chrome would not have a problem with a completely laissez-faire approach.

Relaxing the interface prototype object restriction would be a forward-compatible change because it makes errors into non-errors.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105770</commentid>
    <comment_count>2</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2014-05-12 22:08:11 +0000</bug_when>
    <thetext>I am trying to work out what is the significance of storing constructor, rather than prototype in custom element definition. Can you help me understand that?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105850</commentid>
    <comment_count>3</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2014-05-13 13:56:04 +0000</bug_when>
    <thetext>I think this is mostly conceptual since we are locking down the prototype and constructor properties so we can go back and forth as needed.

However, ES/WebIDL works with Functions and ES6 has meta operations for creating new objects from a constructor, not from its prototype (since the prototype does not have any relevance to how the instance is created).

http://people.mozilla.org/~jorendorff/es6-draft.html#sec-createfromconstructor</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105854</commentid>
    <comment_count>4</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2014-05-13 14:22:28 +0000</bug_when>
    <thetext>(In reply to Erik Arvidsson from comment #3)
&gt; I think this is mostly conceptual since we are locking down the prototype
&gt; and constructor properties so we can go back and forth as needed.
&gt; 
&gt; However, ES/WebIDL works with Functions and ES6 has meta operations for
&gt; creating new objects from a constructor, not from its prototype (since the
&gt; prototype does not have any relevance to how the instance is created).
&gt; 
&gt; http://people.mozilla.org/~jorendorff/es6-draft.html#sec-
&gt; createfromconstructor

Ah! That makes sense. I will leave the bug open and block it on bug 25669.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121748</commentid>
    <comment_count>5</comment_count>
    <who name="Hayato Ito">hayato</who>
    <bug_when>2015-07-06 08:16:49 +0000</bug_when>
    <thetext>Moved to https://github.com/w3c/webcomponents/issues/214</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>