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

View file

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