Skip to content

Commit 9cbed55

Browse files
committed
Make SyntaxError properly inherit from Error.
This ensures that the superclass constructor is called and the `name` property is set appropriately. Fixes: #168, #169.
1 parent d27ee2b commit 9cbed55

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/util/SyntaxError.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @param {int} col The column at which the error occurred.
99
*/
1010
function SyntaxError(message, line, col){
11+
Error.call(this);
12+
this.name = this.constructor.name;
1113

1214
/**
1315
* The column at which the error occurred.
@@ -33,4 +35,5 @@ function SyntaxError(message, line, col){
3335
}
3436

3537
//inherit from Error
36-
SyntaxError.prototype = new Error();
38+
SyntaxError.prototype = Object.create(Error.prototype); // jshint ignore:line
39+
SyntaxError.prototype.constructor = SyntaxError; // jshint ignore:line

0 commit comments

Comments
 (0)