Closed Bug 1153603 Opened 5 years ago Closed 5 years ago

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


(Core :: DOM: Events, defect)

37 Branch
Not set



Tracking Status
firefox40 --- fixed


(Reporter: ibnrubaxa, Assigned: smaug)


(Blocks 1 open bug)


(Keywords: testcase)


(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);


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.
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:

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]

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+
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.