Provide one external API for loading the compiler: compiler.loadVersion

pull/1/head
Alex Beregszaszi 9 years ago
parent 671a90c06d
commit 0824a6a0ef
  1. 4
      src/app.js
  2. 14
      src/app/compiler.js

@ -422,9 +422,9 @@ var run = function () {
// Workers cannot load js on "file:"-URLs and we get a // Workers cannot load js on "file:"-URLs and we get a
// "Uncaught RangeError: Maximum call stack size exceeded" error on Chromium, // "Uncaught RangeError: Maximum call stack size exceeded" error on Chromium,
// resort to non-worker version in that case. // resort to non-worker version in that case.
compiler.initializeWorker(version, setVersionText); compiler.loadVersion(true, version, setVersionText);
} else { } else {
compiler.loadVersion(version, setVersionText); compiler.loadVersion(false, version, setVersionText);
} }
}; };

@ -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; Module = null;
// Set a safe fallback until the new one is loaded // Set a safe fallback until the new one is loaded
compileJSON = function(source, optimize) { compilationFinished('{}'); }; compileJSON = function(source, optimize) { compilationFinished('{}'); };
@ -148,9 +156,9 @@ function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles
window.clearInterval(check); window.clearInterval(check);
onCompilerLoaded(setVersionText); onCompilerLoaded(setVersionText);
}, 200); }, 200);
}; }
this.initializeWorker = function (version, setVersionText) { function loadWorker (version, setVersionText) {
if (worker !== null) { if (worker !== null) {
worker.terminate(); worker.terminate();
} }

Loading…
Cancel
Save