From bd0842606202a8bdc2b8da47eb9fc0e9787fb2ff Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Mon, 12 Sep 2016 07:24:24 -0500 Subject: [PATCH] Handle case of not having a compiler set --- static/compiler.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/static/compiler.js b/static/compiler.js index 4ad44d7b0..5177b2c9e 100644 --- a/static/compiler.js +++ b/static/compiler.js @@ -85,17 +85,20 @@ define(function (require) { this.updateCompilerName(); } - Compiler.prototype.compile = function (fromEditor) { + Compiler.prototype.compile = function () { var self = this; - if (!this.source || !this.compiler) return; // TODO blank out the output? var request = { - fromEditor: fromEditor, - source: this.source, - compiler: this.compiler.id, + source: this.source || "", + compiler: this.compiler ? this.compiler.id : "", options: this.options, filters: this.filters.get() }; + if (!this.compiler) { + this.onCompileResponse(request, errorResult("Please select a compiler")); + return; + } + var cacheableRequest = JSON.stringify(request); if (cacheableRequest === this.lastRequestRespondedTo) return; // only set the request timestamp after checking cache; else we'll always fetch @@ -241,7 +244,7 @@ define(function (require) { Compiler.prototype.saveState = function () { this.container.setState({ - compiler: this.compiler.id, + compiler: this.compiler ? this.compiler.id : "", options: this.options, source: this.editor, filters: this.filters.get() @@ -259,8 +262,10 @@ define(function (require) { }; Compiler.prototype.updateCompilerName = function () { - this.container.setTitle("#" + this.sourceEditorId + " with " + this.compiler.name); - this.domRoot.find(".full-compiler-name").text(this.compiler.version); + var compilerName = this.compiler ? this.compiler.name : "no compiler set"; + var compilerVersion = this.compiler ? this.compiler.version : ""; + this.container.setTitle("#" + this.sourceEditorId + " with " + compilerName); + this.domRoot.find(".full-compiler-name").text(compilerVersion); }; return {