Skip to content

Commit

Permalink
Workaround read-only Error#column in Safari >= 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Aug 22, 2015
1 parent 7bba2a8 commit 807fc45
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -2384,12 +2384,30 @@
extra.errors.push(error);
}

function constructError(msg, column) {
var error = new Error(msg);
try {
throw error;
} catch (base) {
/* istanbul ignore else */
if (Object.create && Object.defineProperty) {
error = Object.create(base);
Object.defineProperty(error, 'column', { value: column });
}
} finally {
return error;
}
}

function createError(line, pos, description) {
var error = new Error('Line ' + line + ': ' + description);
error.index = pos;
var msg, column, error;

msg = 'Line ' + line + ': ' + description;
column = pos - (scanning ? lineStart : lastLineStart) + 1;
error = constructError(msg, column);
error.lineNumber = line;
error.column = pos - (scanning ? lineStart : lastLineStart) + 1;
error.description = description;
error.index = pos;
return error;
}

Expand Down

0 comments on commit 807fc45

Please sign in to comment.