Skip to content

Commit 8774891

Browse files
author
Chris Armstrong
committed
fix: generation of Error class
1 parent d427ce8 commit 8774891

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

jmespath.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,23 @@
234234
}
235235

236236
function createErrorClass(className) {
237-
var ExtendedError = function (message) {
238-
Error.call(this, message);
239-
this.name = className;
237+
function ExtendedError(message) {
238+
var instance = new Error(message);
239+
instance.name = className;
240+
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
241+
if (Error.captureStackTrace) {
242+
Error.captureStackTrace(instance, ExtendedError)
243+
}
244+
return instance;
240245
};
241-
ExtendedError.prototype = Object.create(Error.prototype);
242-
ExtendedError.prototype.constructor = ExtendedError;
246+
ExtendedError.prototype = Object.create(Error.prototype, {
247+
constructor: {
248+
value: Error,
249+
enumerable: false,
250+
writeable: true,
251+
configurable: true,
252+
},
253+
});
243254

244255
return ExtendedError;
245256
}

0 commit comments

Comments
 (0)