Closed Bug 305329 Opened 19 years ago Closed 19 years ago

Events create with createEvent can only be dispatched once

Categories

(Core :: DOM: Events, defect)

1.7 Branch
x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: kamiel, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6

It seems events created using createEvent can only be dispatched once. To
reissue the event it needs to be completly recreated using createEvent. Take a
look at this js code:

window.addEventListener('load',function(){
  testEvent = document.createEvent('Events')
  testEvent.initEvent('test',true,true);
  window.addEventListener('test',function(){alert('test event fired');},false);
  window.dispatchEvent(testEvent); // This gets handled OK
  window.dispatchEvent(testEvent); // This results in an error in FF 1.0.5 and above
},false);

The above code works in versions of firefox below 1.0.5. This has probably
something to do with fixes related to bug 289940. I find it strange I have to
recreate the event object every time I want it to be dispatched. Maybe I'm
overlooking something and this is for a good reason but both DOM spec and
Mozilla documention don't include anything about this.

For the time being I'm changing my code so that createEvent is called for every
custom event that is fired using dispatchEvent.

Reproducible: Always

Steps to Reproduce:
1. Put the JS snippet above in a XUL file
2. Load it
3. When the onload event is fired 2 javascript alerts should pop up.

Actual Results:  
One alert message is displayed and the following error message gets reported:

Error: [Exception... "Component returned failure code: 0x80070057
(NS_ERROR_ILLEGAL_VALUE) [nsIDOMEventTarget.dispatchEvent]"  nsresult:
"0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame ::
chrome://baremote/content/scripts/baremote.js :: baremote_pageload :: line 41" 
data: no]

Expected Results:  
It should have resulted in 2 javascript alerts being shown
See bug 194587 comment 8, this has been disabled for security reasons.
Assignee: nobody → events
Component: General → DOM: Events
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → 1.7 Branch
You need to call initEvent again before calling dispatchEvent a second time.  See bug 296704.
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.