From 90f4af5776a4612e108988121e4121432531d58e Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Wed, 2 Jan 2019 00:29:18 +0100 Subject: [PATCH] fix: gracefully handle read-only "column"-property of the Error class - this is the case in Safari starting with version 9.0 - see 07511e0379dbdeea78f407065b0a3134a79a38a6 - also see #1285 --- lib/handlebars/exception.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/handlebars/exception.js b/lib/handlebars/exception.js index 46ce18eae..b9a5557b6 100644 --- a/lib/handlebars/exception.js +++ b/lib/handlebars/exception.js @@ -19,13 +19,28 @@ function Exception(message, node) { this[errorProps[idx]] = tmp[errorProps[idx]]; } + /* istanbul ignore else */ if (Error.captureStackTrace) { Error.captureStackTrace(this, Exception); } - if (loc) { - this.lineNumber = line; - this.column = column; + try { + if (loc) { + this.lineNumber = line; + + // Work around issue under safari where we can't directly set the column value + /* istanbul ignore next */ + if (Object.defineProperty) { + Object.defineProperty(this, 'column', { + value: column, + enumerable: true + }); + } else { + this.column = column; + } + } + } catch (nop) { + /* Ignore if the browser is very particular */ } }