From 9cbed55a937f31a05f7a85f134631cdd88122feb Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Fri, 29 Jan 2016 16:11:36 -0500 Subject: [PATCH] Make SyntaxError properly inherit from Error. This ensures that the superclass constructor is called and the `name` property is set appropriately. Fixes: #168, #169. --- src/util/SyntaxError.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/SyntaxError.js b/src/util/SyntaxError.js index eec3039c..edcba8c5 100644 --- a/src/util/SyntaxError.js +++ b/src/util/SyntaxError.js @@ -8,6 +8,8 @@ * @param {int} col The column at which the error occurred. */ function SyntaxError(message, line, col){ + Error.call(this); + this.name = this.constructor.name; /** * The column at which the error occurred. @@ -33,4 +35,5 @@ function SyntaxError(message, line, col){ } //inherit from Error -SyntaxError.prototype = new Error(); \ No newline at end of file +SyntaxError.prototype = Object.create(Error.prototype); // jshint ignore:line +SyntaxError.prototype.constructor = SyntaxError; // jshint ignore:line