Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
543 bytes
|
Line | |
---|
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.