Status: New
Owner: ----

New issue 2138 by [email protected]: Error toString is not invoked on custom errors.
http://code.google.com/p/v8/issues/detail?id=2138

I ran into this issue as I was working on making DOM exceptions have Error.prototype in their prototype chain: https://bugs.webkit.org/show_bug.cgi?id=85078

The problem is that the function IsNativeErrorObject (in messages.js) is not correct. It incorrectly checks instanceof instead of the [[Class]]. Therefore when we generate the error message we call Error.prototype.toString.call(obj) instead of obj.toString() for non native error objects.

The following implementation fixes the issue and makes our output match JSC.

// To check if something is a native error we need to check the
// concrete native error types. It is not sufficient to use instanceof
// since it possible to create an object that has Error.prototype on
// its prototype chain. This is the case for DOMException for example.
function IsNativeErrorObject(obj) {
  switch (%_ClassOf(obj)) {
    case 'Error':
    case 'EvalError':
    case 'RangeError':
    case 'ReferenceError':
    case 'SyntaxError':
    case 'TypeError':
    case 'URIError':
      return true;
  }
  return false;
}

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to