Skip to content
Permalink
Browse files

Fix the owner document for all element constructors

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; also gives the HTMLElement constructor
its own <dfn> and inline some of its steps.
  • Loading branch information...
domenic committed May 2, 2016
1 parent a714902 commit c9d898386d7b79cf1c7e104b5768e393c924078f
Showing with 95 additions and 56 deletions.
  1. +95 −56 source
151 source
@@ -3022,7 +3022,6 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
<li>The <dfn data-noexport="" data-x="js-FunctionCreate" data-x-href="https://tc39.github.io/ecma262/#sec-functioncreate">FunctionCreate</dfn> abstract operation</li>
<li>The <dfn data-noexport="" data-x="js-Get" data-x-href="https://tc39.github.io/ecma262/#sec-get-o-p">Get</dfn> abstract operation</li>
<li>The <dfn data-noexport="" data-x="js-GetActiveScriptOrModule" data-x-href="https://tc39.github.io/ecma262/#sec-getactivescriptormodule">GetActiveScriptOrModule</dfn> abstract operation</li>
<li>The <dfn data-noexport="" data-x-href="https://tc39.github.io/ecma262/#sec-getfunctionrealm">GetFunctionRealm</dfn> abstract operation</li>
<li>The <dfn data-noexport="" data-x-href="https://tc39.github.io/ecma262/#sec-hasownproperty">HasOwnProperty</dfn> abstract operation</li>
<li>The <dfn data-noexport="" data-x="js-HostEnsureCanCompileStrings" data-x-href="https://tc39.github.io/ecma262/#sec-hostensurecancompilestrings">HostEnsureCanCompileStrings</dfn> abstract operation</li>
<li>The <dfn data-noexport="" data-x="js-HostPromiseRejectionTracker" data-x-href="https://tc39.github.io/ecma262/#sec-host-promise-rejection-tracker">HostPromiseRejectionTracker</dfn> abstract operation</li>
@@ -3134,7 +3133,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>
@@ -9533,7 +9532,7 @@ partial /*sealed*/ interface <dfn>Document</dfn> {
w-nodev>and which must be used by elements that have no additional requirements,</span> is
the <code>HTMLElement</code> interface.</p>

<pre class="idl">[Constructor]
<pre class="idl">[<span data-x="dom-HTMLElement">Constructor</span>]
interface <dfn>HTMLElement</dfn> : <span>Element</span> {
// metadata attributes
[<span>CEReactions</span>] attribute DOMString <span data-x="dom-title">title</span>;
@@ -9564,17 +9563,18 @@ interface <dfn>HTMLUnknownElement</dfn> : <span>HTMLElement</span> { };</pre>

<p>The <code>HTMLElement</code> interface holds methods and attributes related to a number of
disparate features, and the members of this interface are therefore described in various different
sections of this specification. <span w-nodev>Its constructor, when invoked, must perform the
following steps:</span></p>
sections of this specification.</p>

<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>
<p>An <dfn><code data-x="dom-HTMLElement">HTMLElement()</code></dfn> constructor is provided. It
cannot be invoked directly, but instead works when invoked via a <code data-x="">super()</code>
call inside a <span>custom element constructor</span>. When invoked, the constructor must perform
the following steps:</p>

<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>
<ol>
<li><p>Let <var>registry</var> be the <span>current global object</span>'s
<code>CustomElementsRegistry</code> object.</p></li>

<li><p>Let <var>definition</var> be the entry in <var>registry</var> with <span
data-x="concept-custom-element-definition-constructor">constructor</span> equal to NewTarget. If
@@ -9589,12 +9589,11 @@ 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
data-x="concept-custom-element-definition-local-name">local name</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>
to <var>definition</var>'s <span data-x="concept-custom-element-definition-local-name">local
name</span>, and <span>node document</span> set to the <span>current global object</span>'s
<span data-x="concept-document-window"><code>Document</code> object</span>.</p></li>

<li><p>Perform <var>element</var>.[[SetPrototypeOf]](<var>prototype</var>). Rethrow any
exceptions.</p></li>
@@ -9636,10 +9635,6 @@ interface <dfn>HTMLUnknownElement</dfn> : <span>HTMLElement</span> { };</pre>
</li>
</ol>

<p class="note">The <code>HTMLElement</code> constructor cannot be invoked directly. It only works
when used via a <code data-x="">super()</code> call inside a <span>custom element
constructor</span>.</p>

<hr>

<p>The <span>element interface</span> for an element with name <var>name</var> in the
@@ -26235,14 +26230,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, then <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-->
@@ -29682,17 +29690,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>

@@ -50047,18 +50067,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-->
@@ -67292,8 +67330,9 @@ console.log(plasticButton2.getAttribute("is")); // will output "plastic-button"<
<dt>A <dfn data-x="concept-custom-element-definition-construction-stack">construction
stack</dfn></dt>
<dd>A list, initially empty, that is manipulated by the <span>upgrade an element</span> algorithm
and the <code>HTMLElement</code> constructor. Each entry in the list will be either an element or
an <dfn data-x="concept-already-constructed-marker"><i>already constructed</i> marker</dfn>.</dd>
and the <span data-x="dom-HTMLElement"><code>HTMLElement</code> constructor</span>. Each entry in
the list will be either an element or an <dfn
data-x="concept-already-constructed-marker"><i>already constructed</i> marker</dfn>.</dd>
</dl>

<p>To <dfn data-export="">look up a custom element definition</dfn>, given a <var>document</var>,
@@ -67623,8 +67662,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>,
@@ -87761,7 +87800,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
@@ -103481,8 +103520,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

0 comments on commit c9d8983

Please sign in to comment.
You can’t perform that action at this time.