Skip to content

Commit 90f4af5

Browse files
committed
fix: gracefully handle read-only "column"-property of the Error class
- this is the case in Safari starting with version 9.0 - see 07511e0 - also see #1285
1 parent a7744f8 commit 90f4af5

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

lib/handlebars/exception.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,28 @@ function Exception(message, node) {
1919
this[errorProps[idx]] = tmp[errorProps[idx]];
2020
}
2121

22+
/* istanbul ignore else */
2223
if (Error.captureStackTrace) {
2324
Error.captureStackTrace(this, Exception);
2425
}
2526

26-
if (loc) {
27-
this.lineNumber = line;
28-
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+
/* istanbul ignore next */
33+
if (Object.defineProperty) {
34+
Object.defineProperty(this, 'column', {
35+
value: column,
36+
enumerable: true
37+
});
38+
} else {
39+
this.column = column;
40+
}
41+
}
42+
} catch (nop) {
43+
/* Ignore if the browser is very particular */
2944
}
3045
}
3146

0 commit comments

Comments
 (0)