summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-12-12 16:07:52 -0600
committerkpdecker <kpdecker@gmail.com>2015-12-12 16:07:52 -0600
commit2ea6119a83e6c59ce3b208f95fee604a1648670b (patch)
tree7260905118d33748cd7623cf99b3a1380f8a9f2d
parent8289c0bf3afff120b5fe7e90c08cac18a8166b9c (diff)
downloadhandlebars.js-2ea6119a83e6c59ce3b208f95fee604a1648670b.zip
handlebars.js-2ea6119a83e6c59ce3b208f95fee604a1648670b.tar.gz
handlebars.js-2ea6119a83e6c59ce3b208f95fee604a1648670b.tar.bz2
Fix throw when creating exception object in Safari
https://github.com/jquery/esprima/issues/1290
-rw-r--r--lib/handlebars/exception.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/handlebars/exception.js b/lib/handlebars/exception.js
index 52499c0..24734d4 100644
--- a/lib/handlebars/exception.js
+++ b/lib/handlebars/exception.js
@@ -12,7 +12,7 @@ function Exception(message, node) {
message += ' - ' + line + ':' + column;
}
- let tmp = Error.prototype.constructor.call(this, message);
+ let tmp = Error.prototype.constructor.call(this, message, loc && loc.source, line);
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
for (let idx = 0; idx < errorProps.length; idx++) {
@@ -24,9 +24,19 @@ function Exception(message, node) {
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
+ if (Object.defineProperty) {
+ Object.defineProperty(this, 'column', {value: column});
+ } else {
+ this.column = column;
+ }
+ }
+ } catch (nop) {
+ /* Ignore if the browser is very particular */
}
}