From 143924357b224181da8d370b475130842bc90a0d Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 28 Oct 2012 19:06:47 +0100 Subject: [PATCH] Setup prototype chain for |PEG.GrammarError| correctly --- src/peg.js | 5 +++-- src/utils.js | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/peg.js b/src/peg.js index fd6522f..0150dca 100644 --- a/src/peg.js +++ b/src/peg.js @@ -8,6 +8,8 @@ */ var PEG = (function(undefined) { +// @include "utils.js" + var PEG = { /* PEG.js version (uses semantic versioning). */ VERSION: "@VERSION", @@ -35,9 +37,8 @@ PEG.GrammarError = function(message) { this.message = message; }; -PEG.GrammarError.prototype = Error.prototype; +subclass(PEG.GrammarError, Error); -// @include "utils.js" // @include "parser.js" // @include "compiler.js" diff --git a/src/utils.js b/src/utils.js index 24e2739..967168f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -87,6 +87,12 @@ function defaults(object, defaults) { } } +function subclass(child, parent) { + function ctor() { this.constructor = child; } + ctor.prototype = parent.prototype; + child.prototype = new ctor(); +} + /* * Returns a string padded on the left to a desired length with a character. *