This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 25522 - No need to special case onerror attribute event handler
Summary: No need to special case onerror attribute event handler
Status: RESOLVED WORKSFORME
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-30 20:57 UTC by contributor
Modified: 2014-06-05 22:57 UTC (History)
5 users (show)

See Also:


Attachments

Description contributor 2014-04-30 20:57:57 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html
Multipage: http://www.whatwg.org/C#event-handler-attributes
Complete: http://www.whatwg.org/c#event-handler-attributes
Referrer: 

Comment:
No need to special case onerror event handler

Posted from: 2620:0:1003:1017:2e41:38ff:fea6:f2aa
User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1951.5 Safari/537.36
Comment 1 Erik Arvidsson 2014-04-30 21:00:30 UTC
I don't think we need to add new warts to http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#getting-the-current-value-of-the-event-handler

window.onerror is pretty new to be consistently implemented in browsers and we (Blink & WebKit) do not expose source, lineno, colno, nor error as arguments.
Comment 2 Boris Zbarsky 2014-04-30 22:46:45 UTC
> and we (Blink & WebKit) do not expose source, lineno, colno, nor error as
> arguments.

Uh....

<script>
  onerror = function(a, b, c, d, e, f) {
    document.write(Array.prototype.slice.call(arguments));
  }
  throw new Error("haha");
</script>

shows

  Uncaught Error: haha,file:///Users/bzbarsky/test.html,5,9,Error: haha

for me in Blink.  It shows 

  Error: haha,file:///Users/bzbarsky/test.html,5

in Safari.  So both have the source location and line number.  Blink also has the column number and exception object.
Comment 3 Boris Zbarsky 2014-04-30 22:47:04 UTC
Oh, and the exception object is a common web author request here; Gecko recently added it because of that.
Comment 4 Erik Arvidsson 2014-04-30 23:13:43 UTC
Sorry, if this wasn't clear. I'm only talking about onerror as an attribute event handler.

http://jsbin.com/halilova/1/

<!DOCTYPE html>
<body onerror="console.log(source, lineno, colno, error)">
<script>
syntax error
</script>

Chrome 35: does not add any of the above.

Firefox 31: adds source and lineno but not colno or error.

IE11: Does not invoke the handle.

(Don't have access to a Mac at the moment)
Comment 5 Boris Zbarsky 2014-04-30 23:56:28 UTC
I'm somewhat opposed to there being a difference between the "attribute event handler" case and the function being assigned to .onerror case.  All that happens with the attribute is a function is compiled and then assigned, and they should behave identically.

Current Firefox nightlies show a column number and exception object in your example.  Safari 7.0.3 seems to not invoke the handler at all.
Comment 6 Boris Zbarsky 2014-05-01 00:01:48 UTC
And in particular, consider this testcase:

<body onerror="document.write(Array.prototype.slice.call(arguments));">
<script>
  onerror = onerror;
  throw new Error("haha");
</script>
</body>

Blink has different behavior depending on whether the "onerror = onerror" line is there, which seems pretty weird.
Comment 7 Simon Pieters 2014-05-02 12:26:51 UTC
I agree with Boris here. I think it's good to be consistent between attribute event handler and IDL event handler.

If you don't like <body onerror> then it seems more sane to argue that it shouldn't reflect window.onerror at all. (But then that would affect document.body.onerror also I guess...)

In webdevdata data set 2013-09-01 102,000 pages I found one match for grep -Ei "<body\s+[^>]*onerror\s*=[^>]+>":

http://www.lmt.lv/lv
<body id="page-sakumlapa" class="lv" onerror="js_error_reporter(event, source, lineno);">

so it's not high usage but it's not zero either.
Comment 8 Ian 'Hixie' Hickson 2014-06-05 21:40:08 UTC
arv, are zcorpan and bz's comments sufficiently convincing for you here?
Comment 9 Erik Arvidsson 2014-06-05 21:59:59 UTC
Yeah. bz has me convinced.
Comment 10 Ian 'Hixie' Hickson 2014-06-05 22:57:01 UTC
Cool.