From 6b10fccd040a8d1a54d0d25fd9661c56d71ac8f3 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 6 Sep 2016 10:12:06 +0200 Subject: [PATCH 1/2] Parse source into json for event. --- src/app/compiler.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/compiler.js b/src/app/compiler.js index f3a06af4a0..c42a729397 100644 --- a/src/app/compiler.js +++ b/src/app/compiler.js @@ -52,7 +52,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { files[utils.fileNameFromKey(editor.getCacheFile())] = input; gatherImports(files, missingInputs, function (input, error) { if (input === null) { - self.event.trigger('compilationFinished', [false, [error], editor.getValue()]); + self.event.trigger('compilationFinished', [false, [error], files]); } else { var optimize = queryParams.get().optimize; compileJSON(input, optimize ? 1 : 0); @@ -144,7 +144,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { function loadInternal (url) { delete window.Module; // Set a safe fallback until the new one is loaded - setCompileJSON(function (source, optimize) { compilationFinished('{}'); }); + setCompileJSON(function (source, optimize) { compilationFinished({}); }); var newScript = document.createElement('script'); newScript.type = 'text/javascript'; @@ -173,12 +173,14 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { break; case 'compiled': var result; + var source; try { result = JSON.parse(data.data); + source = JSON.parse(data.source); } catch (exception) { result = { 'error': 'Invalid JSON output from the compiler: ' + exception }; } - compilationFinished(result, data.missingInputs, data.source); + compilationFinished(result, data.missingInputs, source); break; } }); From ff13c1024716c3538661192bd88a0ce8b7ee8af2 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 6 Sep 2016 12:21:37 +0200 Subject: [PATCH 2/2] Do not pass sources back and forth but retain them. --- src/app/compiler-worker.js | 2 +- src/app/compiler.js | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/app/compiler-worker.js b/src/app/compiler-worker.js index 424796bfb9..14c81f0905 100644 --- a/src/app/compiler-worker.js +++ b/src/app/compiler-worker.js @@ -34,7 +34,7 @@ module.exports = function (self) { break; case 'compile': missingInputs.length = 0; - self.postMessage({cmd: 'compiled', data: compileJSON(data.source, data.optimize), missingInputs: missingInputs, source: data.source}); + self.postMessage({cmd: 'compiled', job: data.job, data: compileJSON(data.source, data.optimize), missingInputs: missingInputs}); break; } }, false); diff --git a/src/app/compiler.js b/src/app/compiler.js index c42a729397..bdc04c4415 100644 --- a/src/app/compiler.js +++ b/src/app/compiler.js @@ -144,7 +144,9 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { function loadInternal (url) { delete window.Module; // Set a safe fallback until the new one is loaded - setCompileJSON(function (source, optimize) { compilationFinished({}); }); + setCompileJSON(function (source, optimize) { + compilationFinished({error: 'Compiler not yet loaded.'}); + }); var newScript = document.createElement('script'); newScript.type = 'text/javascript'; @@ -164,6 +166,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { worker.terminate(); } worker = webworkify(require('./compiler-worker.js')); + var jobs = []; worker.addEventListener('message', function (msg) { var data = msg.data; switch (data.cmd) { @@ -173,14 +176,17 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { break; case 'compiled': var result; - var source; try { result = JSON.parse(data.data); - source = JSON.parse(data.source); } catch (exception) { result = { 'error': 'Invalid JSON output from the compiler: ' + exception }; } - compilationFinished(result, data.missingInputs, source); + var sources = {}; + if (data.job in jobs !== undefined) { + sources = jobs[data.job].sources; + delete jobs[data.job]; + } + compilationFinished(result, data.missingInputs, sources); break; } }); @@ -191,7 +197,8 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { compilationFinished({ error: 'Worker error: ' + msg.data }); }); compileJSON = function (source, optimize) { - worker.postMessage({cmd: 'compile', source: JSON.stringify(source), optimize: optimize}); + jobs.push({sources: source}); + worker.postMessage({cmd: 'compile', job: jobs.length - 1, source: JSON.stringify(source), optimize: optimize}); }; worker.postMessage({cmd: 'loadVersion', data: url}); }