Setup prototype chain for |SyntaxError| in generated parsers correctly

redux
David Majda 12 years ago
parent 143924357b
commit 277fb23411

@ -273,6 +273,13 @@ PEG.compiler.passes.generateCode = function(ast, options) {
' * http://pegjs.majda.cz/', ' * http://pegjs.majda.cz/',
' */', ' */',
' ', ' ',
/* This needs to be in sync with |subclass| in utils.js. */
' function subclass(child, parent) {',
' function ctor() { this.constructor = child; }',
' ctor.prototype = parent.prototype;',
' child.prototype = new ctor();',
' }',
' ',
/* This needs to be in sync with |quote| in utils.js. */ /* This needs to be in sync with |quote| in utils.js. */
' function quote(s) {', ' function quote(s) {',
' /*', ' /*',
@ -546,7 +553,7 @@ PEG.compiler.passes.generateCode = function(ast, options) {
' this.column = column;', ' this.column = column;',
' };', ' };',
' ', ' ',
' result.SyntaxError.prototype = Error.prototype;', ' subclass(result.SyntaxError, Error);',
' ', ' ',
' return result;', ' return result;',
'})()' '})()'

@ -87,6 +87,10 @@ function defaults(object, defaults) {
} }
} }
/*
* The code needs to be in sync with the code template in the compilation
* function for "action" nodes.
*/
function subclass(child, parent) { function subclass(child, parent) {
function ctor() { this.constructor = child; } function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype; ctor.prototype = parent.prototype;

Loading…
Cancel
Save