Closed Bug 194587 Opened 21 years ago Closed 19 years ago

Synthetic (Trigger) Event via dispatchEvent() method generates exception

Categories

(Documentation Graveyard :: Web Developer, defect)

defect
Not set
major

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: leonard, Assigned: doronr)

References

()

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3b) Gecko/20030221
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3b) Gecko/20030221

I took some code directly adapted from the Gecko DOM Reference
(http://www.mozilla.org/docs/dom/domref/dom_el_ref36.html) but when trying to
implement it, I get the following exception generated:

Error: uncaught exception: [Exception... "Could not convert JavaScript argument
arg 0 [nsIDOMEventTarget.dispatchEvent]"  nsresult: "0x80570009
(NS_ERROR_XPC_BAD_CONVERT_JS)"  location: "JS frame ::
http://randomfoo.net/sandbox/mozilla/dispatchEvent/ref.html :: <TOP_LEVEL> ::
line 6"  data: no]

As a secondary issue, there does not seem to be any documentation for the names
of the Event Interface types that Gecko uses.  Is this available anywhere (and
if it's just in the source, mind giving a pointer to where I might want to start
looking?)

Reproducible: Always

Steps to Reproduce:
This documentation is totally wrong.  

1) The boolean return value has nothing to do with whether the event is successful
2) dispatchEvent takes an event object, not a string.

I suggest looking at
http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html# for
something like correct documentation.
Assignee: saari → rudman
Severity: normal → major
Component: DOM Events → Web Developer
OS: Windows XP → All
Product: Browser → Documentation
QA Contact: desale → rudman
Hardware: PC → All
Version: Trunk → unspecified
OK, it works when passing an actual event object (although it barfs up an
exception if I try to predeclare an 'new Event', it works fine handling a
createEvent()): http://randomfoo.net/sandbox/mozilla/dispatchEvent/dom.html

One thing that's curious, is that the MouseEvent click doesn't seem to actually
simulate a mouseclick in the interface.  It'll trigger the onclick listener, but
it won't for example, cause say a select form element to expand.  Is it supposed
to? (and if it's not can anyone point me in a direction of how/if to do it [ie,
a different event type I should be specifying in initEvent()?])
-> Ian
moving stuff over to an outside-the-firewall email for the time being, looking
for people to pick these Help and doc bugs up for me.
Assignee: oeschger → oeschger
taking over some of Ian's bugs
Assignee: oeschger → stolenclover
-> Doron
Assignee: stolenclover → doronr
I'm pretty sure something has changed recently because I have code that used to
work and I've had to modify it to get it to work correctly again.  I have
commented out what used to work.  Now I have to create a new event otherwise I
get this error.

Error: uncaught exception: [Exception... "Component returned failure code:
0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMEventTarget.dispatchEvent]" 
nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame ::
http://u-web-dev.karta.com/interface/pages/author/v2/includes/page/UiPopupMenuItem.js
:: anonymous :: line 46"  data: no]


UiPopupMenuItem.prototype.handleClick = function(mouseEvent) {
  var i = UiUtil.childIterator(this.pTd);
  if (i.hasNext()) {
    if (mouseEvent.target == this.pTd) {
      var firstChild = i.next();
      if (firstChild.nodeType == UiUtil.ELEMENT_NODE) {
        if (firstChild.dispatchEvent) {

          var e = document.createEvent("MouseEvents");
          e.initEvent("click", true, false);
          firstChild.dispatchEvent(e);
          //firstChild.dispatchEvent(mouseEvent);
        }
      }
    }
  }
}

I don't know if that makes it a bug or not.  Maybe it was never supposed to work
in the first place.  If you want me to pair this down to a working example that
doesn't function I can.
Redispatch of an event that is currently being dispatch was disabled for
security reasons.
documentation is already fixed:
http://developer.mozilla.org/en/docs/DOM:element.dispatchEvent
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.