Skip to content

Commit

Permalink
Fix throw when creating exception object in Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker authored and lawnsea committed Nov 11, 2016
1 parent 6c9f98c commit 20c965c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/handlebars/exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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 */
}
}

Expand Down

0 comments on commit 20c965c

Please sign in to comment.