Skip to content

Commit 0283565

Browse files
authored
Make the two ways of event creation share a path
This introduces the "inner event creation steps" so we don't duplicate a bunch of logic. It also inlines timeStamp recommendations about clock resolution.
1 parent 06dae65 commit 0283565

File tree

1 file changed

+45
-39
lines changed

1 file changed

+45
-39
lines changed

dom.bs

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,6 @@ false.
708708
The <dfn attribute for=Event><code>timeStamp</code></dfn> attribute must return the value it was
709709
initialized to.
710710

711-
<p class=warning> User agents are strongly encouraged to set minimum resolution of the
712-
{{Event/timeStamp}} attribute to 5 microseconds following the existing <a>clock resolution</a>
713-
recommendation. [[!HR-TIME]]
714-
715711
<hr>
716712

717713
To <dfn export for=Event id=concept-event-initialize>initialize</dfn> an
@@ -809,20 +805,11 @@ interface, or of an interface that inherits from the {{Event}} interface, is inv
809805
must be run, given the arguments <var>type</var> and <var>eventInitDict</var>:
810806

811807
<ol>
812-
<li><p>Create a new object <var>event</var> using this interface.
813-
814-
<li><p>Set <var>event</var>'s <a>initialized flag</a>.
808+
<li><p>Let <var>event</var> be the result of running the <a>inner event creation steps</a> with
809+
this interface, null, now, and <var>eventInitDict</var>.
815810

816811
<li><p>Initialize <var>event</var>'s {{Event/type}} attribute to <var>type</var>.
817812

818-
<li><p>Initialize <var>event</var>'s {{Event/timeStamp}} attribute to a {{DOMHighResTimeStamp}}
819-
representing the high resolution time from the <a>time origin</a> to the occurrence of the call
820-
to the <var>event</var>'s <a>constructor</a>.
821-
822-
<li><p>For each <a>dictionary member</a> present in <var>eventInitDict</var>, find the attribute on
823-
<var>event</var> whose <a spec=webidl>identifier</a> matches the key of the
824-
<a>dictionary member</a> and then set the attribute to the value of that <a>dictionary member</a>.
825-
826813
<li><p>Return <var>event</var>.
827814
</ol>
828815

@@ -832,34 +819,24 @@ using <var>eventInterface</var>, which must be either {{Event}} or an interface
832819
it, and optionally given a <a>Realm</a> <var>realm</var>, run these steps:</p>
833820

834821
<ol>
835-
<li>
836-
<p>Create a new object <var>event</var> using <var>eventInterface</var>. If <var>realm</var>
837-
is given, use that Realm; otherwise, use the default behavior defined in Web IDL.
822+
<li><p>If <var>realm</var> is not given, then set it to null.
838823

839-
<p class="XXX">As of the time of this writing Web IDL does not yet define any default behavior;
840-
see <a href="https://github.com/heycam/webidl/issues/135">heycam/webidl#135</a>.
841-
842-
<li><p>Set <var>event</var>'s <a>initialized flag</a>.
843-
844-
<li><p>Let <var>defaultEventInitDict</var> be the result of
845-
<a lt="converted to an IDL value">converting</a> the JavaScript value undefined to the dictionary
846-
type accepted by <var>eventInterface</var>'s constructor. (This dictionary type will either be
847-
{{EventInit}} or a dictionary that inherits from it.)
824+
<li>
825+
<p>Let <var>dictionary</var> be the result of <a lt="converted to an IDL value">converting</a>
826+
the JavaScript value undefined to the dictionary type accepted by <var>eventInterface</var>'s
827+
constructor. (This dictionary type will either be {{EventInit}} or a dictionary that inherits from
828+
it.)
848829

849-
<li>For each <a>dictionary member</a> present in <var>defaultEventInitDict</var>, find the
850-
attribute on <var>event</var> whose <a spec=webidl>identifier</a> matches the key of the
851-
<a>dictionary member</a> and then set the attribute to the default value of that
852-
<a>dictionary member</a>.
830+
<p class="XXX">This does not work if members are required; see
831+
<a href="https://github.com/whatwg/dom/issues/600">whatwg/dom#600</a>.
853832

854-
<li><p>Set <var>event</var>'s {{Event/timeStamp}} attribute to a {{DOMHighResTimeStamp}}
855-
representing the high resolution time from the <a>time origin</a> to the occurrence that the
856-
event is signaling.
833+
<li>
834+
<p>Let <var>event</var> be the result of running the <a>inner event creation steps</a> with
835+
<var>eventInterface</var>, <var>realm</var>, the time of the occurrence that the event is
836+
signaling, and <var>dictionary</var>.
857837

858-
<p class=note>For example, in macOS the occurrence time for input actions are available via the
859-
timestamp property of corresponding <code>NSEvent</code> objects. So in this case, the
860-
{{Event/timeStamp}} value will be equivalent to the <code>NSEvent</code>'s timestamp offset by
861-
<a>time origin</a>, translated in milliseconds, and with its precision adjusted to meet the minimum
862-
<a>clock resolution</a>.
838+
<p class=example>In macOS the time of the occurrence for input actions are available via the
839+
<code>timestamp</code> property of <code>NSEvent</code> objects.
863840

864841
<li><p>Initialize <var>event</var>'s {{Event/isTrusted}} attribute to true.
865842

@@ -871,6 +848,35 @@ separately <a lt="create an event">create</a> and <a>dispatch</a> events, instea
871848
<a lt="fire an event">firing</a> them. It ensures the event's attributes are initialized to the
872849
correct defaults.</p>
873850

851+
<p>The <dfn noexport>inner event creation steps</dfn>, given an <var>interface</var>,
852+
<var>realm</var>, <var>time</var>, and <var>dictionary</var>, are as follows:</p>
853+
854+
<ol>
855+
<li>
856+
<p>Let <var>event</var> be the result of creating a new object using <var>eventInterface</var>. If
857+
<var>realm</var> is non-null, then use that Realm; otherwise, use the default behavior defined in
858+
Web IDL.
859+
860+
<p class="XXX">As of the time of this writing Web IDL does not yet define any default behavior;
861+
see <a href="https://github.com/heycam/webidl/issues/135">heycam/webidl#135</a>.
862+
863+
<li><p>Set <var>event</var>'s <a>initialized flag</a>.
864+
865+
<li>
866+
<p>Initialize <var>event</var>'s {{Event/timeStamp}} attribute to a {{DOMHighResTimeStamp}}
867+
representing the high resolution time from the <a>time origin</a> to <var>time</var>.
868+
869+
<p class=warning>User agents should set a minimum resolution of <var>event</var>'s
870+
{{Event/timeStamp}} attribute to 5 microseconds following the existing <a>clock resolution</a>
871+
recommendation. [[!HR-TIME]]
872+
873+
<li><p><a for=map>For each</a> <var>member</var><var>value</var> in <var>dictionary</var>, if
874+
<var>event</var> has an attribute whose <a spec=webidl>identifier</a> is <var>member</var>, then
875+
initialize that attribute to <var>value</var>.
876+
877+
<li><p>Return <var>event</var>.
878+
</ol>
879+
874880

875881
<h3 id=defining-event-interfaces>Defining event interfaces</h3>
876882

0 commit comments

Comments
 (0)