diff --git a/lib/compiler/passes/generate-javascript.js b/lib/compiler/passes/generate-javascript.js index e941806..9d86220 100644 --- a/lib/compiler/passes/generate-javascript.js +++ b/lib/compiler/passes/generate-javascript.js @@ -778,8 +778,11 @@ function generateJavascript(ast, options) { ' this.expected = expected;', ' this.found = found;', ' this.location = location;', - '', ' this.name = "SyntaxError";', + '', + ' if (typeof Error.captureStackTrace === "function") {', + ' Error.captureStackTrace(this, peg$SyntaxError);', + ' }', ' }', '', ' peg$subclass(peg$SyntaxError, Error);', diff --git a/lib/grammar-error.js b/lib/grammar-error.js index 753aedc..7844b10 100644 --- a/lib/grammar-error.js +++ b/lib/grammar-error.js @@ -5,6 +5,10 @@ function GrammarError(message, location) { this.name = "GrammarError"; this.message = message; this.location = location; + + if (typeof Error.captureStackTrace === "function") { + Error.captureStackTrace(this, GrammarError); + } } classes.subclass(GrammarError, Error); diff --git a/lib/parser.js b/lib/parser.js index 290c013..926ee6e 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -16,8 +16,11 @@ module.exports = (function() { this.expected = expected; this.found = found; this.location = location; - this.name = "SyntaxError"; + + if (typeof Error.captureStackTrace === "function") { + Error.captureStackTrace(this, peg$SyntaxError); + } } peg$subclass(peg$SyntaxError, Error);