Skip to content

Commit 20c965c

Browse files
kpdeckerlawnsea
authored andcommitted
Fix throw when creating exception object in Safari
jquery/esprima#1290
1 parent 6c9f98c commit 20c965c

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

lib/handlebars/exception.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function Exception(message, node) {
1212
message += ' - ' + line + ':' + column;
1313
}
1414

15-
let tmp = Error.prototype.constructor.call(this, message);
15+
let tmp = Error.prototype.constructor.call(this, message, loc && loc.source, line);
1616

1717
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
1818
for (let idx = 0; idx < errorProps.length; idx++) {
@@ -24,9 +24,19 @@ function Exception(message, node) {
2424
Error.captureStackTrace(this, Exception);
2525
}
2626

27-
if (loc) {
28-
this.lineNumber = line;
29-
this.column = column;
27+
try {
28+
if (loc) {
29+
this.lineNumber = line;
30+
31+
// Work around issue under safari where we can't directly set the column value
32+
if (Object.defineProperty) {
33+
Object.defineProperty(this, 'column', {value: column});
34+
} else {
35+
this.column = column;
36+
}
37+
}
38+
} catch (nop) {
39+
/* Ignore if the browser is very particular */
3040
}
3141
}
3242

0 commit comments

Comments
 (0)