Merge pull request #213 from ethereum/fixsource

Parse source into json for event.
pull/1/head
chriseth 9 years ago committed by GitHub
commit 0fcf0ca021
  1. 2
      src/app/compiler-worker.js
  2. 17
      src/app/compiler.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);

@ -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});
}

Loading…
Cancel
Save