<?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>25830</bug_id>
          
          <creation_ts>2014-05-20 15:54:42 +0000</creation_ts>
          <short_desc>[Custom]: What should be the name of the generated constructor returned by registerElement?</short_desc>
          <delta_ts>2015-07-06 08:04:39 +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>All</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>14968</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="johnjbarton">johnjbarton</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>dominicc</cc>
    
    <cc>erik.arvidsson</cc>
    
    <cc>mike</cc>
    
    <cc>public-webapps</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>106455</commentid>
    <comment_count>0</comment_count>
    <who name="johnjbarton">johnjbarton</who>
    <bug_when>2014-05-20 15:54:42 +0000</bug_when>
    <thetext>Two parts of the definition of Custom Elements conflict:

http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type
&quot;The custom element type identifies a custom element interface and is a sequence of characters that must match the NCName production, must contain a U+002D HYPHEN-MINUS character, and must not contain any uppercase ASCII letters.&quot;

http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-constructor
&quot;All custom elements must be constructable with a function object, called custom element constructor. &quot;

A name defined as containing a dash cannot be parsed as a function name in JavaScript. Consequently the two definitions above prevent mocking of Custom Elements in a way fully compatible with the standard.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106472</commentid>
    <comment_count>1</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2014-05-20 16:51:48 +0000</bug_when>
    <thetext>(In reply to johnjbarton from comment #0)
&gt; Two parts of the definition of Custom Elements conflict:
&gt; 
&gt; http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-type
&gt; &quot;The custom element type identifies a custom element interface and is a
&gt; sequence of characters that must match the NCName production, must contain a
&gt; U+002D HYPHEN-MINUS character, and must not contain any uppercase ASCII
&gt; letters.&quot;
&gt; 
&gt; http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-
&gt; constructor
&gt; &quot;All custom elements must be constructable with a function object, called
&gt; custom element constructor. &quot;
&gt; 
&gt; A name defined as containing a dash cannot be parsed as a function name in
&gt; JavaScript. Consequently the two definitions above prevent mocking of Custom
&gt; Elements in a way fully compatible with the standard.

&lt;_&lt; ... Is the problem with the meaning of the word &quot;identifies&quot;? Where is the custom element type parsed into a function name in the spec?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106484</commentid>
    <comment_count>2</comment_count>
    <who name="johnjbarton">johnjbarton</who>
    <bug_when>2014-05-20 17:00:14 +0000</bug_when>
    <thetext>This issue arose when mocking or faking Custom Elements. I needed to create a representation for the constructor function returned by document.registerElement(). It&apos;s not currently possible because registerElement() requires a function name identifier that is invalid in JavaScript.  That seems unfortunate given the focus on JavaScript for the API.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106488</commentid>
    <comment_count>3</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2014-05-20 17:03:11 +0000</bug_when>
    <thetext>(In reply to johnjbarton from comment #2)
&gt; This issue arose when mocking or faking Custom Elements. I needed to create
&gt; a representation for the constructor function returned by
&gt; document.registerElement(). It&apos;s not currently possible because
&gt; registerElement() requires a function name identifier that is invalid in
&gt; JavaScript.  That seems unfortunate given the focus on JavaScript for the
&gt; API.

Can you help me understand where in the spec the custom element type and function name are connected? They should be two separate concepts that are associated together in a definition via the process of registration.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106497</commentid>
    <comment_count>4</comment_count>
    <who name="johnjbarton">johnjbarton</who>
    <bug_when>2014-05-20 17:31:48 +0000</bug_when>
    <thetext>Yes, the type name is passed in to registerElement():
---
partial interface Document {
    Function registerElement(DOMString type, optional ElementRegistrationOptions options);
};
---
and a Function is returned. The &apos;name&apos; property of the returned function object will be a string matching &apos;type&apos;.


The section on es6 
http://w3c.github.io/webcomponents/spec/custom/#es6
has a different API and here it seems even more problematic:
---
The steps run when calling registerElement will change to:

Input
DOCUMENT, method&apos;s context object, a document
TYPE, the custom element type of the element being registered
FUNCTION, the custom element constructor, optional
---
The &apos;custom element constructor&apos; is 
http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-constructor
which says in part
---
Let CONSTRUCTOR be the interface object whose interface prototype object is PROTOTYPE and when called as a constructor, executes these steps:
Let ELEMENT be the context object
Let TYPE be the custom element type in DEFINITION
Let NAME be the local name in DEFINITION
---
I don&apos;t see how one can supply the constructor function required by this API through ordinary JS code.

To be sure I am not able to see exactly where the standard connects the &quot;local name&quot; with the TYPE. Experimentally you can see the connection in Chrome by typing into devtools console:

document.registerElement(&apos;x-foo&apos;)
gives
function x-foo() { [native code] }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106498</commentid>
    <comment_count>5</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2014-05-20 17:37:20 +0000</bug_when>
    <thetext>(In reply to johnjbarton from comment #4)
&gt; Yes, the type name is passed in to registerElement():
&gt; ---
&gt; partial interface Document {
&gt;     Function registerElement(DOMString type, optional
&gt; ElementRegistrationOptions options);
&gt; };
&gt; ---
&gt; and a Function is returned. The &apos;name&apos; property of the returned function
&gt; object will be a string matching &apos;type&apos;.

Well, no, that&apos;s not specified anywhere.

&gt; 
&gt; 
&gt; The section on es6 
&gt; http://w3c.github.io/webcomponents/spec/custom/#es6
&gt; has a different API and here it seems even more problematic:
&gt; ---
&gt; The steps run when calling registerElement will change to:
&gt; 
&gt; Input
&gt; DOCUMENT, method&apos;s context object, a document
&gt; TYPE, the custom element type of the element being registered
&gt; FUNCTION, the custom element constructor, optional
&gt; ---
&gt; The &apos;custom element constructor&apos; is 
&gt; http://w3c.github.io/webcomponents/spec/custom/#dfn-custom-element-
&gt; constructor
&gt; which says in part
&gt; ---
&gt; Let CONSTRUCTOR be the interface object whose interface prototype object is
&gt; PROTOTYPE and when called as a constructor, executes these steps:
&gt; Let ELEMENT be the context object
&gt; Let TYPE be the custom element type in DEFINITION
&gt; Let NAME be the local name in DEFINITION
&gt; ---
&gt; I don&apos;t see how one can supply the constructor function required by this API
&gt; through ordinary JS code.

No, you&apos;re just not reading the rest of the monkey-patching of the spec down below. The meaning of custom element constructor will change for ES6.

&gt; 
&gt; To be sure I am not able to see exactly where the standard connects the
&gt; &quot;local name&quot; with the TYPE. Experimentally you can see the connection in
&gt; Chrome by typing into devtools console:
&gt; 
&gt; document.registerElement(&apos;x-foo&apos;)
&gt; gives
&gt; function x-foo() { [native code] }

This just seems like a bug in Chrome. It&apos;s not anything that spec describes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106499</commentid>
    <comment_count>6</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2014-05-20 17:42:41 +0000</bug_when>
    <thetext>Filed https://code.google.com/p/chromium/issues/detail?id=375357</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106500</commentid>
    <comment_count>7</comment_count>
    <who name="johnjbarton">johnjbarton</who>
    <bug_when>2014-05-20 17:46:02 +0000</bug_when>
    <thetext>What value does the spec say the constructor function name should have?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106501</commentid>
    <comment_count>8</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2014-05-20 17:48:12 +0000</bug_when>
    <thetext>(In reply to johnjbarton from comment #7)
&gt; What value does the spec say the constructor function name should have?

Now, that&apos;s a good question. Can it be anonymous function?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106502</commentid>
    <comment_count>9</comment_count>
    <who name="johnjbarton">johnjbarton</who>
    <bug_when>2014-05-20 17:57:48 +0000</bug_when>
    <thetext>Yes seems like anonymous is fine:

&gt;function fakeRegisterElement() { return function() { console.log(&apos;born&apos;); } }
undefined
&gt;var xFoo = fakeRegisterElement()
undefined
&gt; new xFoo
born VM2040:2
Object {}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106503</commentid>
    <comment_count>10</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2014-05-20 17:59:35 +0000</bug_when>
    <thetext>Anonymous sounds reasonable to me. The name should be &quot;&quot;.

var f = function() {};
console.log(f.name); // &quot;&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>106623</commentid>
    <comment_count>11</comment_count>
    <who name="Dominic Cooney">dominicc</who>
    <bug_when>2014-05-22 02:04:24 +0000</bug_when>
    <thetext>Blink implementor feedback:

Blink names the function after the Custom Element name. My thinking was it is helpful for the developer to have a hint about what the function relates to when playing with it interactively. It is not a valid JavaScript identifier, although for that matter [native code] is not a valid function body; I&apos;m not sure what spec requires these names to be valid.

From this bug and feedback from our test suite submission authors apparently people expect the spec to have a requirement for this.

I think it will not be a problem for Blink to implement a different name.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121638</commentid>
    <comment_count>12</comment_count>
    <who name="Hayato Ito">hayato</who>
    <bug_when>2015-07-06 08:04:39 +0000</bug_when>
    <thetext>Moved to https://github.com/w3c/webcomponents/issues/211</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>