Skip to content

Commit cb7c16b

Browse files
zcorpanannevk
authored andcommitted
Make document.createEvent("touchevent") sometimes throw
Browsers typically disable touch events on non-touch devices, and there exists web content that detects this difference using document.createEvent(). Fixes #227.
1 parent 537e579 commit cb7c16b

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

dom.bs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4931,17 +4931,16 @@ method, when invoked, must run these steps:
49314931

49324932
<hr>
49334933

4934-
The <dfn method for=Document><code>createEvent(<var>interface</var>)</code></dfn> method, when
4934+
<p>The <dfn method for=Document><code>createEvent(<var>interface</var>)</code></dfn> method, when
49354935
invoked, must run these steps:
49364936

49374937
<ol>
4938-
<li>Let <var>constructor</var> be null.
4938+
<li><p>Let <var>constructor</var> be null.
49394939

49404940
<li>
4941-
If <var>interface</var> is an
4942-
<a>ASCII case-insensitive</a> match for any of the strings in the
4943-
first column in the following table, set <var>constructor</var> to the
4944-
interface in the second column on the same row as the matching string:
4941+
<p>If <var>interface</var> is an <a>ASCII case-insensitive</a> match for any of the strings in the
4942+
first column in the following table, then set <var>constructor</var> to the interface in the
4943+
second column on the same row as the matching string:
49454944

49464945
<table>
49474946
<thead>
@@ -4985,16 +4984,22 @@ invoked, must run these steps:
49854984
<tr><td>"<code>wheelevent</code>"<td>{{WheelEvent}}<td>[[!UIEVENTS]]
49864985
</table>
49874986

4988-
<li>If <var>constructor</var> is null, <a>throw</a> a
4989-
{{NotSupportedError}}.
4987+
<li><p>If <var>constructor</var> is null, then <a>throw</a> a {{NotSupportedError}}.
49904988

4991-
<li>Let <var>event</var> be the result of <a for=Event lt=constructor>invoking</a> the initial
4989+
<li>
4990+
<p>If the initial value of <var>constructor</var> is undefined, then <a>throw</a> a
4991+
{{NotSupportedError}}.
4992+
4993+
<p class=note>Typically user agents disable support for touch events in some configurations, in
4994+
which case the initial value of {{TouchEvent}} is undefined.
4995+
4996+
<li><p>Let <var>event</var> be the result of <a for=Event lt=constructor>invoking</a> the initial
49924997
value of <var>constructor</var> with the empty string as argument.
49934998
<!-- "initial value" as in before script could get to it -->
49944999

4995-
<li>Unset <var>event</var>'s <a>initialized flag</a>.
5000+
<li><p>Unset <var>event</var>'s <a>initialized flag</a>.
49965001

4997-
<li>Return <var>event</var>.
5002+
<li><p>Return <var>event</var>.
49985003
</ol>
49995004

50005005
<p class=note><a>Event</a> constructors ought to be used instead.

dom.html

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<p data-fill-with="logo"><a class="logo" href="https://whatwg.org/"> <img alt="WHATWG" height="100" src="https://resources.whatwg.org/logo-dom.svg"> </a> </p>
7272
<hgroup>
7373
<h1 class="p-name no-ref allcaps" id="title">DOM</h1>
74-
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated <time class="dt-updated" datetime="2016-04-18">18 April 2016</time></span></h2>
74+
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated <time class="dt-updated" datetime="2016-04-19">19 April 2016</time></span></h2>
7575
</hgroup>
7676
<div data-fill-with="spec-metadata">
7777
<dl>
@@ -2737,13 +2737,14 @@ <h3 class="heading settled" data-level="4.5" id="interface-document"><span class
27372737
</ol>
27382738
<hr>
27392739
<p>The <dfn class="idl-code" data-dfn-for="Document" data-dfn-type="method" data-export="" id="dom-document-createevent"><code>createEvent(<var>interface</var>)</code><a class="self-link" href="#dom-document-createevent"></a></dfn> method, when
2740-
invoked, must run these steps:</p>
2740+
invoked, must run these steps: </p>
27412741
<ol>
2742-
<li>Let <var>constructor</var> be null.
27432742
<li>
2744-
If <var>interface</var> is an <a data-link-type="dfn" href="#ascii-case-insensitive">ASCII case-insensitive</a> match for any of the strings in the
2745-
first column in the following table, set <var>constructor</var> to the
2746-
interface in the second column on the same row as the matching string:
2743+
<p>Let <var>constructor</var> be null. </p>
2744+
<li>
2745+
<p>If <var>interface</var> is an <a data-link-type="dfn" href="#ascii-case-insensitive">ASCII case-insensitive</a> match for any of the strings in the
2746+
first column in the following table, then set <var>constructor</var> to the interface in the
2747+
second column on the same row as the matching string: </p>
27472748
<table>
27482749
<thead>
27492750
<tr>
@@ -2876,11 +2877,19 @@ <h3 class="heading settled" data-level="4.5" id="interface-document"><span class
28762877
<td><code class="idl"><a data-link-type="idl">WheelEvent</a></code>
28772878
<td><a data-link-type="biblio" href="#biblio-uievents">[UIEVENTS]</a>
28782879
</table>
2879-
<li>If <var>constructor</var> is null, <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#notsupportederror">NotSupportedError</a></code>.
2880-
<li>Let <var>event</var> be the result of <a data-link-type="dfn" href="#concept-event-constructor">invoking</a> the initial
2881-
value of <var>constructor</var> with the empty string as argument.
2882-
<li>Unset <var>event</var>’s <a data-link-type="dfn" href="#initialized-flag">initialized flag</a>.
2883-
<li>Return <var>event</var>.
2880+
<li>
2881+
<p>If <var>constructor</var> is null, then <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#notsupportederror">NotSupportedError</a></code>. </p>
2882+
<li>
2883+
<p>If the initial value of <var>constructor</var> is undefined, then <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#notsupportederror">NotSupportedError</a></code>. </p>
2884+
<p class="note" role="note">Typically user agents disable support for touch events in some configurations, in
2885+
which case the initial value of <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/touch-events/#touchevent-interface">TouchEvent</a></code> is undefined. </p>
2886+
<li>
2887+
<p>Let <var>event</var> be the result of <a data-link-type="dfn" href="#concept-event-constructor">invoking</a> the initial
2888+
value of <var>constructor</var> with the empty string as argument. </p>
2889+
<li>
2890+
<p>Unset <var>event</var>’s <a data-link-type="dfn" href="#initialized-flag">initialized flag</a>. </p>
2891+
<li>
2892+
<p>Return <var>event</var>. </p>
28842893
</ol>
28852894
<p class="note" role="note"><a data-link-type="dfn" href="#concept-event">Event</a> constructors ought to be used instead. </p>
28862895
<hr>
@@ -3183,7 +3192,7 @@ <h3 class="heading settled" data-level="4.9" id="interface-element"><span class=
31833192
<p>Set <var>result</var> to <a data-link-type="abstract-op" href="https://tc39.github.io/ecma262/#sec-construct">Construct</a>(<var>C</var>). Rethrow any
31843193
exceptions. </p>
31853194
<li>
3186-
<p>If <var>result</var> does not implement the <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/dom.html#htmlelement">HTMLElement</a></code> interface, <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code class="idl"><a data-link-type="idl" href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror">TypeError</a></code> exception. </p>
3195+
<p>If <var>result</var> does not implement the <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/dom.html#htmlelement">HTMLElement</a></code> interface, <a data-link-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <code class="idl"><a data-link-type="idl">TypeError</a></code> exception. </p>
31873196
<p class="note" role="note">This is meant to be a brand check to ensure that the object was allocated by the <code class="idl"><a data-link-type="idl" href="https://html.spec.whatwg.org/multipage/dom.html#htmlelement">HTMLElement</a></code> constructor. See <a href="https://github.com/heycam/webidl/issues/97">webidl #97</a> about making this more
31883197
precise. </p>
31893198
<li>
@@ -4929,7 +4938,7 @@ <h3 class="heading settled" data-level="8.1" id="dom-events-changes"><span class
49294938
</ul>
49304939
<h3 class="heading settled" data-level="8.2" id="dom-core-changes"><span class="secno">8.2. </span><span class="content">DOM Core</span><a class="self-link" href="#dom-core-changes"></a></h3>
49314940
<p>These are the changes made to the features described in <cite>DOM Level 3 Core</cite>.</p>
4932-
<p><code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a></code>, <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#dfn-domexception">DOMException</a></code>, and <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#common-domtimestamp">DOMTimeStamp</a></code> are now defined in Web IDL.</p>
4941+
<p><code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a></code>, <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#dfn-DOMException">DOMException</a></code>, and <code class="idl"><a data-link-type="idl" href="https://heycam.github.io/webidl/#common-domtimestamp">DOMTimeStamp</a></code> are now defined in Web IDL.</p>
49334942
<p><code class="idl"><a data-link-type="idl" href="#node">Node</a></code> now inherits from <code class="idl"><a data-link-type="idl" href="#eventtarget">EventTarget</a></code>.</p>
49344943
<p><a data-link-type="dfn" href="#concept-node">Nodes</a> are implicitly <a data-link-type="dfn" href="#concept-node-adopt">adopted</a> across <a data-link-type="dfn" href="#concept-document">document</a> boundaries.</p>
49354944
<p><a data-link-type="dfn" href="#concept-doctype">Doctypes</a> now always have a <a data-link-type="dfn" href="#concept-node-document">node document</a> and can be moved
@@ -6020,7 +6029,6 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
60206029
<a data-link-type="biblio">[ECMASCRIPT]</a> defines the following terms:
60216030
<ul>
60226031
<li><a href="https://tc39.github.io/ecma262/#sec-construct">Construct</a>
6023-
<li><a href="https://tc39.github.io/ecma262/#sec-native-error-types-used-in-this-standard-typeerror">TypeError</a>
60246032
</ul>
60256033
<li>
60266034
<a data-link-type="biblio">[css-animations-1]</a> defines the following terms:
@@ -6090,7 +6098,19 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
60906098
<li>
60916099
<a data-link-type="biblio">[WEBIDL]</a> defines the following terms:
60926100
<ul>
6101+
<li><a href="https://heycam.github.io/webidl/#dfn-DOMException">DOMException</a>
60936102
<li><a href="https://heycam.github.io/webidl/#idl-DOMString">DOMString</a>
6103+
<li><a href="https://heycam.github.io/webidl/#hierarchyrequesterror">HierarchyRequestError</a>
6104+
<li><a href="https://heycam.github.io/webidl/#inuseattributeerror">InUseAttributeError</a>
6105+
<li><a href="https://heycam.github.io/webidl/#indexsizeerror">IndexSizeError</a>
6106+
<li><a href="https://heycam.github.io/webidl/#invalidcharactererror">InvalidCharacterError</a>
6107+
<li><a href="https://heycam.github.io/webidl/#invalidnodetypeerror">InvalidNodeTypeError</a>
6108+
<li><a href="https://heycam.github.io/webidl/#invalidstateerror">InvalidStateError</a>
6109+
<li><a href="https://heycam.github.io/webidl/#namespaceerror">NamespaceError</a>
6110+
<li><a href="https://heycam.github.io/webidl/#notfounderror">NotFoundError</a>
6111+
<li><a href="https://heycam.github.io/webidl/#notsupportederror">NotSupportedError</a>
6112+
<li><a href="https://heycam.github.io/webidl/#syntaxerror">SyntaxError</a>
6113+
<li><a href="https://heycam.github.io/webidl/#wrongdocumenterror">WrongDocumentError</a>
60946114
</ul>
60956115
</ul>
60966116
<h2 class="no-num no-ref heading settled" id="references"><span class="content">References</span><a class="self-link" href="#references"></a></h2>

0 commit comments

Comments
 (0)