Prevent crash when console.error is used - Fixes #833 (#834)

This commit is contained in:
Oliver Wright 2019-02-20 20:57:37 +00:00 committed by Cassie Tarakajian
parent 3f821ffb32
commit d0832ea4b7
1 changed files with 7 additions and 2 deletions

View File

@ -192,10 +192,15 @@ class Editor extends React.Component {
if (this.props.runtimeErrorWarningVisible && this._cm.getDoc().modeOption === 'javascript') {
this.props.consoleEvents.forEach((consoleEvent) => {
if (consoleEvent.method === 'error') {
if (consoleEvent.data[0].indexOf(')') > -1) {
if (consoleEvent.data &&
consoleEvent.data[0] &&
consoleEvent.data[0].indexOf &&
consoleEvent.data[0].indexOf(')') > -1) {
const n = consoleEvent.data[0].replace(')', '').split(' ');
const lineNumber = parseInt(n[n.length - 1], 10) - 1;
this._cm.addLineClass(lineNumber, 'background', 'line-runtime-error');
if (!Number.isNaN(lineNumber)) {
this._cm.addLineClass(lineNumber, 'background', 'line-runtime-error');
}
}
}
});