[whatwg] onerror

Jonas Sicking jonas at sicking.cc
Fri Jan 16 19:04:19 PST 2009

Hi All,

Not sure if I should be posting this to the whatwg list or the webapps
list, given that the spec is in process of transitioning between the
two groups. So I'm posting to both in the hope that this thread won't
generate too much related traffic. So please stay on topic :)

Currently the webapps spec define that the onerror property should
start out as undefined, rather than other onX properties which start
out as null. The reason for this is parity with the window object
where the onerror property behaves the same.

However there is very little parity anyway between the window onerror
and the worker onerror. The former isn't a normal event handler but
rather a special function that receives 3 arguments and returns a
special value to suppress the error. The latter is a normal event
handler which receives an error event and suppresses the error by
calling .preventDefault() on the event.

Further, the fact that onerror is undefined at the start is to prevent
breaking existing scripts, of which there are none for workers.

So I think it'd be nicer to have parity with other onX properties,
than to have parity on this one aspect with window.onerror.

Second, does the spec define what happens if an error is thrown from
'error' event handler? We have found it useful to prevent firing an
'error' event same scope again. We'll still fire an error event in the
parent scope worker, but we don't call onerror again in the same
scope. Otherwise the risk of infinite recursion is very big. While we
have other things that prevents such runaway recursions from causing
the crash, each recursion would cause onerror to be called on the
parent which means that a torrent of error events would be fired on
the parent.

The result is that the following script alerts twice, first 'inside
onerror' and then 'throwing':

  w = new Worker('w.js');
  c = 1;
  w.onerror = function(e) {

function onerror(e) {
  throw "inside onerror";
throw "throwing";

/ Jonas

More information about the whatwg mailing list