From eed6e708399f22b3e01db2a077a8b020abfccab5 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 28 Nov 2018 12:52:24 +1100 Subject: [PATCH] fix Error.captureStackTrace is undef error on browsers --- errors.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/errors.js b/errors.js index 0dba7ff..52b4ee2 100644 --- a/errors.js +++ b/errors.js @@ -15,6 +15,12 @@ function getValue (value) { return value } +function captureStackTrace (e, t) { + if (Error.captureStackTrace) { + Error.captureStackTrace(e, t) + } +} + function tfJSON (type) { if (native.Function(type)) return type.toJSON ? type.toJSON() : getTypeName(type) if (native.Array(type)) return 'Array' @@ -35,7 +41,7 @@ function TfTypeError (type, value, valueTypeName) { valueTypeName = valueTypeName || getValueTypeName(value) this.message = tfErrorString(type, value, valueTypeName) - Error.captureStackTrace(this, TfTypeError) + captureStackTrace(this, TfTypeError) this.__type = type this.__value = value this.__valueTypeName = valueTypeName @@ -59,7 +65,7 @@ function TfPropertyTypeError (type, property, label, value, valueTypeName) { this.message = 'Unexpected property "' + property + '"' } - Error.captureStackTrace(this, TfTypeError) + captureStackTrace(this, TfTypeError) this.__label = label this.__property = property this.__type = type @@ -90,7 +96,7 @@ function tfSubError (e, property, label) { ) } - Error.captureStackTrace(e) + captureStackTrace(e) return e }