From 3572ecd12dabbab6fafa2ee027ba43123c72b329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 23 Jun 2014 14:39:37 +0200 Subject: [PATCH] validations: support non-V8 browsers Call `Error.captureStackTrace()` only when it is available. Use `this.stack = (new Error).stack` when `captureStackTrace` is not available but the `stack` property is (Firefox). --- lib/validations.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/validations.js b/lib/validations.js index a12a81271..aba9c276a 100644 --- a/lib/validations.js +++ b/lib/validations.js @@ -703,11 +703,21 @@ function ValidationError(obj) { messages: obj.errors }; - Error.captureStackTrace(this, this.constructor); + if (Error.captureStackTrace) { + // V8 (Chrome, Opera, Node) + Error.captureStackTrace(this, this.constructor); + } else if (errorHasStackProperty) { + // Firefox + this.stack = (new Error).stack; + } + // Safari and PhantomJS initializes `error.stack` on throw + // Internet Explorer does not support `error.stack` } util.inherits(ValidationError, Error); +var errorHasStackProperty = !!(new Error).stack; + function formatErrors(errors) { var DELIM = '; '; errors = errors || {};