From 940a66fb384fc0f4d2ea1556df156b74fdd03c9b Mon Sep 17 00:00:00 2001 From: Marco Baumgartl Date: Thu, 18 Jun 2015 10:15:10 +0200 Subject: [PATCH] Add stack trace in engines based on V8. Fixes #331 --- lib/compiler/passes/generate-javascript.js | 5 ++++- lib/grammar-error.js | 4 ++++ lib/parser.js | 5 ++++- 3 files changed, 12 insertions(+), 2 deletions(-) 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);