From 877489135224d7833026933d4a21a01c45bc5f89 Mon Sep 17 00:00:00 2001 From: Chris Armstrong Date: Tue, 18 Jun 2019 17:31:31 +1000 Subject: [PATCH] fix: generation of Error class --- jmespath.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/jmespath.js b/jmespath.js index d3993a2..1ed4609 100644 --- a/jmespath.js +++ b/jmespath.js @@ -234,12 +234,23 @@ } function createErrorClass(className) { - var ExtendedError = function (message) { - Error.call(this, message); - this.name = className; + function ExtendedError(message) { + var instance = new Error(message); + instance.name = className; + Object.setPrototypeOf(instance, Object.getPrototypeOf(this)); + if (Error.captureStackTrace) { + Error.captureStackTrace(instance, ExtendedError) + } + return instance; }; - ExtendedError.prototype = Object.create(Error.prototype); - ExtendedError.prototype.constructor = ExtendedError; + ExtendedError.prototype = Object.create(Error.prototype, { + constructor: { + value: Error, + enumerable: false, + writeable: true, + configurable: true, + }, + }); return ExtendedError; }