mishoo/UglifyJS2 — pull request #176 by papandreou (2013-03-31 16:41:11+00:00)
Title: Fix error classes

Previously you would get output like this when a `DefaultError` was thrown:

```
/path/to/UglifyJS2/lib/utils.js:95
throw new DefaultsError("`" + i + "` is not a supported option", defs)
^
[object Object]
```

With this patch you get:

```
/home/andreas/work/UglifyJS2/lib/utils.js:98
throw new DefaultsError("`" + i + "` is not a supported option", defs)
^
Error: `toplevel` is not a supported option (defs: {"sequences":true,"properties":true,"dead_code":true,"drop_debugger":true,"unsafe":false,"unsafe_comps":false,"conditionals":true,"comparisons":true,"evaluate":true,"booleans":true,"loops":true,"unused":true,"hoist_funs":true,"hoist_vars":false,"if_return":true,"join_vars":true,"cascade":true,"side_effects":true,"warnings":true,"global_defs":{}})
at defaults (/path/to/UglifyJS2/lib/utils.js:98:15)
at Object.Compressor (/path/to/UglifyJS2/lib/compress.js:50:20)
at Object.Compressor (/path/to/UglifyJS2/lib/compress.js:48:16)
at theFunctionThatStartedTheCompressor (/path/to/yourProject/file.js:15:35)
```

The way I did it the `message` property of the error instances includes all the extra info (`defs` for `DefaultsError`, and `line`, `col` etc. for `JS_Parse_Error`) instead of being added to the output by a custom `toString` method. If that's a problem I can try another approach.

I wasn't sure whether you'd want the `defs` object to be included in the `DefaultsError` message itself, so I just put it in there.