Skip to content

Commit

Permalink
Fix the owner document for all element constructors
Browse files Browse the repository at this point in the history
Fixes #1154, which originally covered only the undefined "document"
variable in the HTMLElement constructor, but expanded on further
investigation to reveal that the spec's current choice of node document
for Audio, Image, and Option was strange and not implemented in
browsers.

While there, cleans up all three of these named constructors to
correctly use "create an element," and to be in numbered algorithm form
instead of giant-prose-block form.
  • Loading branch information
domenic committed May 3, 2016
1 parent a021607 commit 16bbe08
Showing 1 changed file with 86 additions and 40 deletions.
126 changes: 86 additions & 40 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -3134,7 +3134,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
<li>The <dfn data-noexport="" data-x="concept-slot" data-x-href="https://dom.spec.whatwg.org/#concept-slot">slot</dfn> concept, and its <dfn data-noexport="" data-x="slot-name" data-x-href="https://dom.spec.whatwg.org/#slot-name">name</dfn> and <dfn data-noexport="" data-x-href="https://dom.spec.whatwg.org/#slot-assigned-nodes">assigned nodes</dfn></li>
<li>The <dfn data-noexport="" data-x="finding flattened slotables" data-x-href="https://dom.spec.whatwg.org/#find-flattened-slotables">find flattened slotables</dfn> algorithm</li>
<li>The <dfn data-noexport="" data-x-href="https://dom.spec.whatwg.org/#concept-node-pre-insert">pre-insert</dfn>, <dfn data-noexport="" data-x="concept-node-insert" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert">insert</dfn>, <dfn data-noexport="" data-x="concept-node-append" data-x-href="https://dom.spec.whatwg.org/#concept-node-append">append</dfn>, <dfn data-noexport="" data-x="concept-node-replace" data-x-href="https://dom.spec.whatwg.org/#concept-node-replace">replace</dfn>, <dfn data-noexport="" data-x="concept-node-remove" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove">remove</dfn>, and <dfn data-noexport="" data-x="concept-node-adopt" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt">adopt</dfn> algorithms for nodes</li>
<li>The <dfn data-noexport="" data-x="concept-element-attributes-change" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-change">change</dfn>, <dfn data-noexport="" data-x="concept-element-attributes-append" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-append">append</dfn>, <dfn data-noexport="" data-x="concept-element-attributes-remove" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-remove">remove</dfn>, and <dfn data-noexport="" data-x="concept-element-attributes-replace" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-replace">replace</dfn> algorithms for attributes</li>
<li>The <dfn data-noexport="" data-x="concept-element-attributes-change" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-change">change</dfn>, <dfn data-noexport="" data-x="concept-element-attributes-append" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-append">append</dfn>, <dfn data-noexport="" data-x="concept-element-attributes-remove" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-remove">remove</dfn>, <dfn data-noexport="" data-x="concept-element-attributes-replace" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-replace">replace</dfn>, and <dfn data-noexport="" data-x="concept-element-attributes-set-value" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-set-value">set value</dfn> algorithms for attributes</li>
<li>The <dfn data-noexport="" data-x="concept-node-insert-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert-ext">insertion steps</dfn>,
<dfn data-noexport="" data-x="concept-node-remove-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove-ext">removing steps</dfn>,
and <dfn data-noexport="" data-x="concept-node-adopt-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt-ext">adopting steps</dfn> hooks</li>
Expand Down Expand Up @@ -9570,8 +9570,7 @@ interface <dfn>HTMLUnknownElement</dfn> : <span>HTMLElement</span> { };</pre>
<div w-nodev>

<ol>
<li><p>Let <var>realm</var> be the result of <span>GetFunctionRealm</span>(the currently
executing <code>HTMLElement</code> function).</p></li>
<li><p>Let <var>realm</var> be the <span>current Realm Record</span>.</p></li>

<li><p>Let <var>registry</var> be <var>realm</var>'s <span data-x="concept-realm-global">global
object</span>'s <code>CustomElementsRegistry</code> object.</p></li>
Expand All @@ -9589,9 +9588,13 @@ interface <dfn>HTMLUnknownElement</dfn> : <span>HTMLElement</span> { };</pre>
empty, then:</p>

<ol>
<li><p>Let <var>localName</var> be the <var>definition</var>'s <span
<li><p>Let <var>localName</var> be <var>definition</var>'s <span
data-x="concept-custom-element-definition-local-name">local name</span>.</p></li>

<li><p>Let <var>document</var> be <var>realm</var>'s <span data-x="concept-realm-global">global
object</span>'s <span data-x="concept-document-window">newest <code>Document</code>
object</span>.</p></li>

<li><p>Let <var>element</var> be a new element that implements the <code>HTMLElement</code>
interface, with no attributes, namespace set to the <span>HTML namespace</span>, local name set
to <var>localName</var>, and <span>node document</span> set to <var>document</var>.</p></li>
Expand Down Expand Up @@ -26235,14 +26238,27 @@ interface <dfn>HTMLImageElement</dfn> : <span>HTMLElement</span> {
<p>A constructor is provided for creating <code>HTMLImageElement</code> objects (in addition to
the factory methods from DOM such as <code
data-x="dom-Document-createElement">createElement()</code>): <dfn
data-x="dom-image"><code>Image(<var>width</var>, <var>height</var>)</code></dfn>.
When invoked as a constructor, this must return a new <code>HTMLImageElement</code> object (a new
<code>img</code> element). If the <var>width</var> argument is present, the new object's
<code data-x="attr-dim-width">width</code> content attribute must be set to <var>width</var>. If the <var>height</var> argument is also present, the new object's
<code data-x="attr-dim-height">height</code> content attribute must be set to <var>height</var>.
The element's <span>node document</span> must be the <span>active document</span> of the
<span>browsing context</span> of the <code>Window</code> object on which the interface object of
the invoked constructor is found.</p>
data-x="dom-image"><code>Image(<var>width</var>, <var>height</var>)</code></dfn>. When invoked,
the constructor must perform the following steps:</p>

<ol>
<li><p>Let <var>document</var> be the <span>current global object</span>'s <span
data-x="concept-document-window"><code>Document</code> object</span>.</p></li>

<li><p>Let <var>img</var> be the result of <span data-x="create an element">creating an
element</span> given <var>document</var>, <code>img</code>, and the <span>HTML
namespace</span>.</p></li>

<li><p>If <var>width</var> is given, then <span data-x="concept-element-attributes-set-value">set
an attribute value</span> for <var>img</var> using "<code data-x="attr-dim-width">width</code>"
and <var>width</var>.</p></li>

<li><p>If <var>height</var> is given, <span data-x="concept-element-attributes-set-value">set an
attribute value</span> for <var>img</var> using "<code data-x="attr-dim-height">height</code>"
and <var>height</var>.</p></li>

<li><p>Return <var>img</var>.</p></li>
</ol>

</div>
<!--TOPIC:HTML-->
Expand Down Expand Up @@ -29677,17 +29693,29 @@ interface <dfn>HTMLAudioElement</dfn> : <span>HTMLMediaElement</span> {};</pre>
<p>A constructor is provided for creating <code>HTMLAudioElement</code> objects (in addition to
the factory methods from DOM such as <code
data-x="dom-Document-createElement">createElement()</code>):
<dfn><code data-x="dom-Audio">Audio(<var>src</var>)</code></dfn>. When invoked as a
constructor, it must return a new <code>HTMLAudioElement</code> object (a new <code>audio</code>
element). The element must be created with its <code data-x="attr-media-preload">preload</code>
attribute set to the literal value "<code data-x="attr-media-preload-auto">auto</code>". If the
<var>src</var> argument is present, the object created must be created with its <code
data-x="attr-media-src">src</code> content attribute set to the provided value (this will <a
href="#concept-media-load-algorithm-at-creation">cause the user agent to invoke</a> the object's
<span data-x="concept-media-load-algorithm">resource selection algorithm</span> before returning).
The element's <span>node document</span> must be the <span>active document</span> of the <span>browsing
context</span> of the <code>Window</code> object on which the interface object of the invoked
constructor is found.</p>
<dfn><code data-x="dom-Audio">Audio(<var>src</var>)</code></dfn>. When invoked,
the constructor must perform the following steps:</p>

<ol>
<li><p>Let <var>document</var> be the <span>current global object</span>'s <span
data-x="concept-document-window"><code>Document</code> object</span>.</p></li>

<li><p>Let <var>audio</var> be the result of <span data-x="create an element">creating an
element</span> given <var>document</var>, <code>audio</code>, and the <span>HTML
namespace</span>.</p></li>

<li><p><span data-x="concept-element-attributes-set-value">Set an attribute value</span> for
<var>audio</var> using "<code data-x="attr-media-preload">preload</code>" and "<code
data-x="attr-media-preload-auto">auto</code>".</p></li>

<li><p>If <var>src</var> is given, then <span data-x="concept-element-attributes-set-value">set
an attribute value</span> for <var>audio</var> using "<code data-x="attr-media-src">src</code>"
and <var>src</var>. (This will <a href="#concept-media-load-algorithm-at-creation">cause the user
agent to invoke</a> the object's <span data-x="concept-media-load-algorithm">resource selection
algorithm</span> before returning.)</p></li>

<li><p>Return <var>audio</var>.</p></li>
</ol>

</div>

Expand Down Expand Up @@ -50042,18 +50070,36 @@ interface <dfn>HTMLOptionElement</dfn> : <span>HTMLElement</span> {
<p>A constructor is provided for creating <code>HTMLOptionElement</code> objects (in addition to
the factory methods from DOM such as <code
data-x="dom-Document-createElement">createElement()</code>):
<dfn><code data-x="dom-option">Option(<var>text</var>, <var>value</var>, <var>defaultSelected</var>, <var>selected</var>)</code></dfn>. When invoked as a
constructor, it must return a new <code>HTMLOptionElement</code> object (a new <code>option</code>
element). If the first argument is not the empty string, the new object must have as its only
child a <code>Text</code> node whose data is the value of that argument. Otherwise, it must have
no children. If the <var>value</var> argument is present, the new object must have a
<code data-x="attr-option-value">value</code> attribute set with the value of the argument as its
value. If the <var>defaultSelected</var> argument is true, the new object must have a
<code data-x="attr-option-selected">selected</code> attribute set with no value. If the <var>selected</var> argument is true, the new object must have its <span
data-x="concept-option-selectedness">selectedness</span> set to true; otherwise the <span
data-x="concept-option-selectedness">selectedness</span> must be set to false, even if the <var>defaultSelected</var> argument is true. The element's <span>node document</span> must be the <span>active
document</span> of the <span>browsing context</span> of the <code>Window</code> object on which
the interface object of the invoked constructor is found.</p>
<dfn><code data-x="dom-option">Option(<var>text</var>, <var>value</var>,
<var>defaultSelected</var>, <var>selected</var>)</code></dfn>. When invoked, the constructor must
perform the following steps:</p>

<ol>
<li><p>Let <var>document</var> be the <span>current global object</span>'s <span
data-x="concept-document-window"><code>Document</code> object</span>.</p></li>

<li><p>Let <var>option</var> be the result of <span data-x="create an element">creating an
element</span> given <var>document</var>, <code>option</code>, and the <span>HTML
namespace</span>.</p></li>

<li><p>If <var>text</var> is not the empty string, then append to <var>option</var> a new
<code>Text</code> node whose data is <var>text</var>.</p></li>

<li><p>If <var>value</var> is given, then <span data-x="concept-element-attributes-set-value">set
an attribute value</span> for <var>option</var> using "<code
data-x="attr-option-value">value</code>" and <var>value</var>.</p></li>

<li><p>If <var>defaultSelected</var> is true, then <span
data-x="concept-element-attributes-set-value">set an attribute value</span> for <var>option</var>
using "<code data-x="attr-option-selected">selected</code>" and the empty string.</p></li>

<li><p>If <var>selected</var> is true, then set <var>option</var>'s <span
data-x="concept-option-selectedness">selectedness</span> to true; otherwise set its <span
data-x="concept-option-selectedness">selectedness</span> to false (even if
<var>defaultSelected</var> is true).</p></li>

<li><p>Return <var>option</var>.</p></li>
</ol>

</div>
<!--TOPIC:HTML-->
Expand Down Expand Up @@ -67618,8 +67664,8 @@ fetch(articleURL)
<li><p>Let <var>document</var> be <var>element</var>'s <span>node document</span>.</p></li>

<li><p>Let <var>is</var> be the value of the attribute in <var>element</var>'s <span>attribute
list</span> whose qualified name is "<code data-x="">is</code>", if any such attribute exists,
or null otherwise.</p></li>
list</span> whose qualified name is "<code data-x="attr-is">is</code>", if any such attribute
exists, or null otherwise.</p></li>

<li><p>Let <var>definition</var> be the result of <span data-x="look up a custom element
definition">looking up a custom element definition</span> given <var>document</var>,
Expand Down Expand Up @@ -87756,7 +87802,7 @@ interface <dfn>NavigatorOnLine</dfn> {
<h6>Current</h6>

<p>The JavaScript specification defines the <span>current Realm Record</span>, sometimes
abbreviated to "the current Realm". <ref spec=JAVASCRIPT></p>
abbreviated to the "current Realm". <ref spec=JAVASCRIPT></p>

<p>Then, the <dfn>current settings object</dfn> is the <span
data-x="concept-realm-settings-object">environment settings object</span> of the <span>current
Expand Down Expand Up @@ -103476,8 +103522,8 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {

<li><p>Let <var>local name</var> be the tag name of the token.</p></li>

<li><p>Let <var>is</var> be the value of the "<code data-x="">is</code>" attribute in the given
token, if such an attribute exists, or null otherwise.</p></li>
<li><p>Let <var>is</var> be the value of the "<code data-x="attr-is">is</code>" attribute in the
given token, if such an attribute exists, or null otherwise.</p></li>

<li><p>Let <var>definition</var> be the result of <span data-x="look up a custom element
definition">looking up a custom element definition</span> given <var>document</var>, <var>given
Expand Down

0 comments on commit 16bbe08

Please sign in to comment.