From 0824a6a0efa00d33f9a0acd3211bb78f14c30dd6 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 3 Jun 2016 20:44:11 +0100 Subject: [PATCH] Provide one external API for loading the compiler: compiler.loadVersion --- src/app.js | 4 ++-- src/app/compiler.js | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/app.js b/src/app.js index 9f6cbd81ce..9e1c57b2f9 100644 --- a/src/app.js +++ b/src/app.js @@ -422,9 +422,9 @@ var run = function () { // Workers cannot load js on "file:"-URLs and we get a // "Uncaught RangeError: Maximum call stack size exceeded" error on Chromium, // resort to non-worker version in that case. - compiler.initializeWorker(version, setVersionText); + compiler.loadVersion(true, version, setVersionText); } else { - compiler.loadVersion(version, setVersionText); + compiler.loadVersion(false, version, setVersionText); } }; diff --git a/src/app/compiler.js b/src/app/compiler.js index c34be42d88..6c0699e83d 100644 --- a/src/app/compiler.js +++ b/src/app/compiler.js @@ -132,7 +132,15 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles } } - this.loadVersion = function (version, setVersionText) { + this.loadVersion = function (usingWorker, version, setVersionText) { + if (usingWorker) { + loadWorker(version, setVersionText); + } else { + loadInternal(version, setVersionText); + } + }; + + function loadInternal (version, setVersionText) { Module = null; // Set a safe fallback until the new one is loaded compileJSON = function(source, optimize) { compilationFinished('{}'); }; @@ -148,9 +156,9 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles window.clearInterval(check); onCompilerLoaded(setVersionText); }, 200); - }; + } - this.initializeWorker = function (version, setVersionText) { + function loadWorker (version, setVersionText) { if (worker !== null) { worker.terminate(); }