Closed Bug 1153603 Opened 5 years ago Closed 5 years ago

Wrong type of event when using createEvent + initEvent ("end" -> "endType")

Categories

(Core :: DOM: Events, defect)

37 Branch
x86
macOS
defect
Not set

Tracking

()

RESOLVED FIXED
mozilla40
Tracking Status
firefox40 --- fixed

People

(Reporter: ibnrubaxa, Assigned: smaug)

References

(Blocks 1 open bug)

Details

(Keywords: testcase)

Attachments

(2 files, 2 obsolete files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36

Steps to reproduce:

var event = document.createEvent('Event');
event.initEvent('end', true, true);

Example: http://jsbin.com/mivodadeko/2/edit?js,output


Actual results:

even.type === 'endType'; // Bug!


Expected results:

even.type === 'end';
Component: Untriaged → DOM: Events
Keywords: testcase
Product: Firefox → Core
oh, bizarre bug.

(new Event("end")).type 
in browser console is enough to show the issue.
Status: UNCONFIRMED → NEW
Ever confirmed: true
zoom, begin and repeat have similar issues.


thinking how to fix this... the issue is that we map the same internal event type to two
different dom event types.
For the SMIL events, beginEvent/endEvent/repeatEvent are the actual event types (unfortunately) but their event handler attributes are onbegin/onend/onrepeat.  So e.initEvent("end") should not be anything related to beginEvent.  Similarly for e.initEvent("zoom").

Would it work to skip the insertion of the entry for "begin", etc. into sStringEventTable in nsContentUtils::InitializeEventTable (maybe by adding a flag to the EventNameType field that we can check)?  Then a string lookup of "begin" would not find anything, but an atom lookup of nsGkAtoms::onbegin would find the entry.

I'd have to check that all uses of GetEventId are really only caring about event handler attributes, and GetEventClassID/GetEventIdAndAtom are really only caring about event types.
Flags: needinfo?(bugs)
(The cleanest solution would be to have separate fields for the event handler attribute name and the event type, but that's probably a waste of memory just to handle these few SVG events correctly.)
Assignee: nobody → bugs
Flags: needinfo?(bugs)
This is an issue with the SpeechSynthesisUtterance end event as well:
https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html#dfn-utteranceonend

I would like to create proper event ids, and add the events to the name mapping, but that is not possible since the SMIL end event already has an entry.
Attached patch v1 (obsolete) — Splinter Review
Attachment #8599499 - Flags: review?(cam)
Blocks: 1159878
Comment on attachment 8599499 [details] [diff] [review]
v1

Review of attachment 8599499 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/base/nsContentUtils.cpp
@@ +644,5 @@
> +static bool
> +ShouldAddEventToStringEventTable(const EventNameMapping& aMapping)
> +{
> +  switch(aMapping.mId) {
> +#define ID_TO_EVENT(name_, _id, _type, _struct) \

Either all trailing or all leading underscores.
Attachment #8599499 - Flags: review?(cam) → review+
silly copy-pasting from inconsistent code.
Attached patch consistent _ usage (obsolete) — Splinter Review
Attached patch for check inSplinter Review
Keywords: checkin-needed
Attachment #8599499 - Attachment is obsolete: true
Attachment #8599837 - Attachment is obsolete: true
Flags: in-testsuite+
https://hg.mozilla.org/mozilla-central/rev/4d5f30e402da
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla40
You need to log in before you can comment on or make changes to this bug.