main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
543 bytes
|
Rev | Line | |
---|
[d565449] | 1 | module.exports = function createCustomError(name, message) {
|
---|
| 2 | // use Object.create(), because some VMs prevent setting line/column otherwise
|
---|
| 3 | // (iOS Safari 10 even throws an exception)
|
---|
| 4 | var error = Object.create(SyntaxError.prototype);
|
---|
| 5 | var errorStack = new Error();
|
---|
| 6 |
|
---|
| 7 | error.name = name;
|
---|
| 8 | error.message = message;
|
---|
| 9 |
|
---|
| 10 | Object.defineProperty(error, 'stack', {
|
---|
| 11 | get: function() {
|
---|
| 12 | return (errorStack.stack || '').replace(/^(.+\n){1,3}/, name + ': ' + message + '\n');
|
---|
| 13 | }
|
---|
| 14 | });
|
---|
| 15 |
|
---|
| 16 | return error;
|
---|
| 17 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.