|
|
|
@ -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,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) { |
|
|
|
@ -178,7 +181,12 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { |
|
|
|
|
} catch (exception) { |
|
|
|
|
result = { 'error': 'Invalid JSON output from the compiler: ' + exception }; |
|
|
|
|
} |
|
|
|
|
compilationFinished(result, data.missingInputs, data.source); |
|
|
|
|
var sources = {}; |
|
|
|
|
if (data.job in jobs !== undefined) { |
|
|
|
|
sources = jobs[data.job].sources; |
|
|
|
|
delete jobs[data.job]; |
|
|
|
|
} |
|
|
|
|
compilationFinished(result, data.missingInputs, sources); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
@ -189,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}); |
|
|
|
|
} |
|
|
|
|