<?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>20487</bug_id>
          
          <creation_ts>2012-12-22 00:01:03 +0000</creation_ts>
          <short_desc>[Custom]: Creation of custom elements via createElement is underdefined</short_desc>
          <delta_ts>2013-02-08 23:46:16 +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>FIXED</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>20684</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Boris Zbarsky">bzbarsky</reporter>
          <assigned_to name="Dimitri Glazkov">dglazkov</assigned_to>
          <cc>annevk</cc>
    
    <cc>bugs</cc>
    
    <cc>mrbkap</cc>
    
    <cc>wchen</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>80514</commentid>
    <comment_count>0</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-22 00:01:03 +0000</bug_when>
    <thetext>Consider this script:


  var proto = { myProp: 1 };
  proto.__proto__ = HTMLElement.prototype;
  var fun = document.register(&quot;x-foo&quot;, { prototype: obj });
  
  var elem1 = document.createElement(&quot;x-foo&quot;);
  var elem2 = document.createElement(&quot;X-FOO&quot;);
  var elem3 = document.createElementNS(null, &quot;x-foo&quot;);
  var elem4 = document.createElementNS(null, &quot;X-FOO&quot;);
  var elem5 = document.createElementNS(&quot;http://www.w3.org/1999/xhtml&quot;, &quot;x-foo&quot;);
  var elem6 = document.createElementNS(&quot;http://www.w3.org/1999/xhtml&quot;, &quot;X-FOO&quot;);

as far as I can tell, the specification does not define which of those elements, if any, have &quot;proto&quot; as their proto, nor whether it depends on whether &quot;document&quot; is an HTML document or an XML/XHTML document.

This is not a hypothetical problem: we just had two implementors who were trying to guess what the spec might maybe mean here write two different incompatible implementations.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80537</commentid>
    <comment_count>1</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2012-12-22 14:33:09 +0000</bug_when>
    <thetext>did you mean 
var fun = document.register(&quot;x-foo&quot;, { prototype: proto });
not
var fun = document.register(&quot;x-foo&quot;, { prototype: obj });
?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>80541</commentid>
    <comment_count>2</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2012-12-22 23:09:12 +0000</bug_when>
    <thetext>Yes, I did.  Sorry, renamed the protoobj partway through the comment, and didn&apos;t catch all the uses....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81975</commentid>
    <comment_count>3</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-01-22 22:15:52 +0000</bug_when>
    <thetext>createElement is here: https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#monkeypatch-create-element</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81977</commentid>
    <comment_count>4</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-01-22 22:20:08 +0000</bug_when>
    <thetext>You need to patch createElementNS too.

And presumably have a namespace check, somewhere?  Or should registering &quot;x-foo&quot; affect both html:x-foo and svg:x-foo?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81978</commentid>
    <comment_count>5</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-01-22 22:32:41 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; You need to patch createElementNS too.
&gt; 
&gt; And presumably have a namespace check, somewhere?  Or should registering
&gt; &quot;x-foo&quot; affect both html:x-foo and svg:x-foo?

Yup, working on it. 

I am thinking something along the lines of: you can&apos;t create custom elements out of it unless your namespace and qualifiedName are asking for HTML namespace. I need to read up on whether this still lets us create SVGElement-derived custom elements. I think it does.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81979</commentid>
    <comment_count>6</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-01-22 22:49:37 +0000</bug_when>
    <thetext>&gt; I think it does.

No, I don&apos;t think it would.

Furthermore the current text does not allow that sort of thing anyway, since it requires that prototypes &quot;inherit from HTMLElement.prototype&quot;, whatever that means.  It sure sounds like deriving things from SVG elements is excluded, though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81981</commentid>
    <comment_count>7</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-01-22 23:35:37 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; &gt; I think it does.
&gt; 
&gt; No, I don&apos;t think it would.

You&apos;re right.

&gt; 
&gt; Furthermore the current text does not allow that sort of thing anyway, since
&gt; it requires that prototypes &quot;inherit from HTMLElement.prototype&quot;, whatever
&gt; that means.  It sure sounds like deriving things from SVG elements is
&gt; excluded, though.

Aside from incorrect wording, I am wondering if I should ignore SVG elements, at least for now.

Ian pointed out that ideally, it should be possible to create custom SVG elements as well, but there&apos;s a lot of complexity that starts creeping here once I open that pandora&apos;s box.

I have no intention to ever introduce namespaces here, so it should be possible to add SVG support later: the custom element namespace would be resolved based on inherited interface.

WDYT?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82109</commentid>
    <comment_count>8</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-01-24 20:38:28 +0000</bug_when>
    <thetext>That might be doable somehow by basically special-casing particular namespaces _somewhere_ in the spec, yes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82246</commentid>
    <comment_count>9</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-01-28 23:22:24 +0000</bug_when>
    <thetext>I think I finally got it. https://dvcs.w3.org/hg/webcomponents/rev/1b0e39e2d815 and https://dvcs.w3.org/hg/webcomponents/rev/d46c3b299481.

Boris, can you pls take a look?

https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#monkeypatch-create-element

Anne, I liked the wording that you&apos;ve added, but I still needed to replace the steps in my monkeypatch, because I have to:

a) define how interface is determined -- I wonder if this could be a different monkeypatch in HTML?
b) run instantiation/finalization steps before I return out of createElement/NS.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82263</commentid>
    <comment_count>10</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-01-29 06:14:53 +0000</bug_when>
    <thetext>&gt; When a custom element is instantiated with the createElement method,

The concept of &quot;custom element&quot; is not defined in a way that I can tell, as a createElement implementor, whethere I&apos;m creating a &quot;custom element&quot;.

Perhaps this should simply say &quot;When an element is instantiated...&quot;?

The custom element instantiation algorithm might need to say something about what happens if the namespace is neither HTML nor SVG.  Or can that situation not arise?

I don&apos;t think anything defines how to tell whether a custom interface inherits from HTMLElement.  I certainly can&apos;t find anything that defines it.

The custom element instantiation algorithm creates HTML-namespaced elements even if we&apos;re extending SVG elements.  That seems ... odd.

&gt; Let CHAIN be ELEMENT&apos;s prototype chain, in reverse order (starting with at the
&gt; top of the prototype chain)

Is the &quot;top&quot; Object.prototype or the other end?  Better to say which end you&apos;re starting with (e.g. the prototype closest to the object or furthest away) instead of assuming your mental geometry matches other people&apos;s.

Apart from those, this is starting to look much better, yes.  I think at this point the createElement bits are fine and the remaining vagueness has been pushed to elsewhere.  ;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82317</commentid>
    <comment_count>11</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-01-30 00:04:25 +0000</bug_when>
    <thetext>(In reply to comment #10)
&gt; &gt; When a custom element is instantiated with the createElement method,
&gt; 
&gt; The concept of &quot;custom element&quot; is not defined in a way that I can tell, as
&gt; a createElement implementor, whethere I&apos;m creating a &quot;custom element&quot;.
&gt; 
&gt; Perhaps this should simply say &quot;When an element is instantiated...&quot;?

Sounds good: https://dvcs.w3.org/hg/webcomponents/rev/709e43cb4699

&gt; 
&gt; The custom element instantiation algorithm might need to say something about
&gt; what happens if the namespace is neither HTML nor SVG.  Or can that
&gt; situation not arise?

As spec&apos;d now, you can build a non-HTML/SVG Element and get away with instantiating it in any namespace. Which seems fine.

&gt; 
&gt; I don&apos;t think anything defines how to tell whether a custom interface
&gt; inherits from HTMLElement.  I certainly can&apos;t find anything that defines it.

This is true. I need to think about this. I think the solution is to just use the Web IDL&apos;s concept of inheritance (http://www.w3.org/TR/WebIDL/#dfn-inherit), but then specify how custom element&apos;s interface is defined.

&gt; 
&gt; The custom element instantiation algorithm creates HTML-namespaced elements
&gt; even if we&apos;re extending SVG elements.  That seems ... odd.

No, as spec&apos;d now, it will throw a NamespaceError. Which actually might be bad. For:

var s = document.createElement(&apos;svg&apos;)

WebKit simply creates an HTMLUnknownElement. Should I do that instead? It seems more error-prone.

&gt; 
&gt; &gt; Let CHAIN be ELEMENT&apos;s prototype chain, in reverse order (starting with at the
&gt; &gt; top of the prototype chain)
&gt; 
&gt; Is the &quot;top&quot; Object.prototype or the other end?  Better to say which end
&gt; you&apos;re starting with (e.g. the prototype closest to the object or furthest
&gt; away) instead of assuming your mental geometry matches other people&apos;s.

Will fix.

&gt; 
&gt; Apart from those, this is starting to look much better, yes.  I think at
&gt; this point the createElement bits are fine and the remaining vagueness has
&gt; been pushed to elsewhere.  ;)

Yay! Now to push it out all the way :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82319</commentid>
    <comment_count>12</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-01-30 06:52:32 +0000</bug_when>
    <thetext>&gt; As spec&apos;d now, you can build a non-HTML/SVG Element and get away with
&gt; instantiating it in any namespace. Which seems fine.

I think if you try to instantiate an element not in the HTML namespace which has HTMLElement.prototype on the proto chain we should consider making that not work.  Just my 2 cents.

&gt; No, as spec&apos;d now, it will throw a NamespaceError

Why?

&gt;var s = document.createElement(&apos;svg&apos;)
&gt;WebKit simply creates an HTMLUnknownElement. 

I think so does everyone else.  Certainly Gecko does (in an HTML document).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82376</commentid>
    <comment_count>13</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-01-30 23:46:55 +0000</bug_when>
    <thetext>(In reply to comment #12)
&gt; &gt; As spec&apos;d now, you can build a non-HTML/SVG Element and get away with
&gt; &gt; instantiating it in any namespace. Which seems fine.
&gt; 
&gt; I think if you try to instantiate an element not in the HTML namespace which
&gt; has HTMLElement.prototype on the proto chain we should consider making that
&gt; not work.  Just my 2 cents.

Good point.

&gt; 
&gt; &gt; No, as spec&apos;d now, it will throw a NamespaceError
&gt; 
&gt; Why?

Because of this line:

&quot;If INTERFACE inherits from SVGElement and NAMESPACE is not SVG namespace, throw a NamespaceError and stop.&quot;

I am not sure if that&apos;s the right behavior, though.

&gt; 
&gt; &gt;var s = document.createElement(&apos;svg&apos;)
&gt; &gt;WebKit simply creates an HTMLUnknownElement. 
&gt; 
&gt; I think so does everyone else.  Certainly Gecko does (in an HTML document).

WDYT, should we keep the same lackadaisical behavior for custom elements? For example, for a custom element &quot;super-svg&quot;, that extends SVGSVGElement:

var superSvg1 = document.createElement(&apos;super-svg&apos;);

Should it:

a) throw NamespaceError
b) returns HTMLUnknownElement
c) returns the instance of &quot;super-svg&quot; custom element?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82389</commentid>
    <comment_count>14</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-01-31 02:35:31 +0000</bug_when>
    <thetext>&gt; &quot;If INTERFACE inherits from SVGElement and NAMESPACE is not SVG namespace,
&gt; throw a NamespaceError and stop.&quot;

Oh, that part is just fine.  The problem is that in the very next step NAMESPACE is completely ignored and the element is created in the HTML namespace no matter what NAMESPACE was.  So if the incoming NAMESPACE is SVG and the interface inherits from SVGElement we&apos;ll get to step 5 and happily create ... an HTML element.

&gt; WDYT, should we keep the same lackadaisical behavior for custom elements?
&gt; For example, for a custom element &quot;super-svg&quot;, that extends SVGSVGElement:
&gt; 
&gt; var superSvg1 = document.createElement(&apos;super-svg&apos;);
&gt; 
&gt; Should it:
&gt; 
&gt; a) throw NamespaceError

I would probably be OK with this.

&gt; b) returns HTMLUnknownElement

I would be OK with this as long as the super-svg custom stuff is not applied to it...

&gt; c) returns the instance of &quot;super-svg&quot; custom element?

I would probably be OK with this one too.

Worth roping in Anne to see what his thoughts are on createElement here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82490</commentid>
    <comment_count>15</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-02-01 23:35:10 +0000</bug_when>
    <thetext>(In reply to comment #14)
&gt; &gt; &quot;If INTERFACE inherits from SVGElement and NAMESPACE is not SVG namespace,
&gt; &gt; throw a NamespaceError and stop.&quot;
&gt; 
&gt; Oh, that part is just fine.  The problem is that in the very next step
&gt; NAMESPACE is completely ignored and the element is created in the HTML
&gt; namespace no matter what NAMESPACE was.  So if the incoming NAMESPACE is SVG
&gt; and the interface inherits from SVGElement we&apos;ll get to step 5 and happily
&gt; create ... an HTML element.

I am terrible. Thank you for pointing this out.
https://dvcs.w3.org/hg/webcomponents/rev/c417c040987a

&gt; 
&gt; &gt; WDYT, should we keep the same lackadaisical behavior for custom elements?
&gt; &gt; For example, for a custom element &quot;super-svg&quot;, that extends SVGSVGElement:
&gt; &gt; 
&gt; &gt; var superSvg1 = document.createElement(&apos;super-svg&apos;);
&gt; &gt; 
&gt; &gt; Should it:
&gt; &gt; 
&gt; &gt; a) throw NamespaceError
&gt; 
&gt; I would probably be OK with this.

I sort of prefer this one, since it&apos;s very likely the user is unintentionally making a mistake by attempting to create a custom element in the wrong namespace.

&gt; 
&gt; &gt; b) returns HTMLUnknownElement
&gt; 
&gt; I would be OK with this as long as the super-svg custom stuff is not applied
&gt; to it...
&gt; 
&gt; &gt; c) returns the instance of &quot;super-svg&quot; custom element?
&gt; 
&gt; I would probably be OK with this one too.
&gt; 
&gt; Worth roping in Anne to see what his thoughts are on createElement here.

Anne, WDTY?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82693</commentid>
    <comment_count>16</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-02-07 12:49:52 +0000</bug_when>
    <thetext>I defined a hook recently to fix a similar bug for HTML (so it can say that for &quot;a&quot; and &quot;http://www.w3.org/1999/xhtml&quot; you use HTMLAnchorElement).

http://dom.spec.whatwg.org/#concept-element-interface

As far as I can tell you should be able to use that hook to define the appropriate interface.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82719</commentid>
    <comment_count>17</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-02-07 22:25:02 +0000</bug_when>
    <thetext>(In reply to comment #16)
&gt; I defined a hook recently to fix a similar bug for HTML (so it can say that
&gt; for &quot;a&quot; and &quot;http://www.w3.org/1999/xhtml&quot; you use HTMLAnchorElement).
&gt; 
&gt; http://dom.spec.whatwg.org/#concept-element-interface
&gt; 
&gt; As far as I can tell you should be able to use that hook to define the
&gt; appropriate interface.

Great, I really appreciate that.

Can I have your opinion on the question in https://www.w3.org/Bugs/Public/show_bug.cgi?id=20487#c13?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82747</commentid>
    <comment_count>18</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2013-02-08 10:57:01 +0000</bug_when>
    <thetext>Throwing seems fine to me. 

Ignoring it&apos;s declared as custom element because the namespace is wrong and just creating HTMLUnknownElement also seems fine to me.

It should do the same as what happens for createElementNS() I think with namespace being the HTML namespace.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82775</commentid>
    <comment_count>19</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-02-08 18:35:28 +0000</bug_when>
    <thetext>(In reply to comment #18)
&gt; Throwing seems fine to me. 
&gt; 
&gt; Ignoring it&apos;s declared as custom element because the namespace is wrong and
&gt; just creating HTMLUnknownElement also seems fine to me.

After some thinking, this seems like the most consistent behavior. Conceptually, the model of the element-interface-concept hook is a table:

(namespace, localName) -&gt; interface

if the namespace is wrong, then the result of this table lookup fails, and thus HTMLUnknownElement is returned.

If we add throwing, then we need to add more hooks, and that seems less consistent with how things work now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82798</commentid>
    <comment_count>20</comment_count>
    <who name="Dimitri Glazkov">dglazkov</who>
    <bug_when>2013-02-08 23:46:16 +0000</bug_when>
    <thetext>This is now done. Please let me know if I goofed up.

https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#monkeypatch-create-element

There&apos;s discussion that will probably trigger more changes in bug 20913.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>