Commit afa87c96 authored by yann300's avatar yann300

register event in inner class

parent d172d68b
...@@ -28,7 +28,7 @@ window.addEventListener('message', function (ev) { ...@@ -28,7 +28,7 @@ window.addEventListener('message', function (ev) {
} }
}, false); }, false);
/* /*
trigger selectTab trigger tabChanged
*/ */
var run = function () { var run = function () {
var self = this; var self = this;
...@@ -411,7 +411,6 @@ var run = function () { ...@@ -411,7 +411,6 @@ var run = function () {
setEditorSize(hidingRHP ? 0 : storage.getEditorSize()); setEditorSize(hidingRHP ? 0 : storage.getEditorSize());
$('.toggleRHP i').toggleClass('fa-angle-double-right', !hidingRHP); $('.toggleRHP i').toggleClass('fa-angle-double-right', !hidingRHP);
$('.toggleRHP i').toggleClass('fa-angle-double-left', hidingRHP); $('.toggleRHP i').toggleClass('fa-angle-double-left', hidingRHP);
if (!hidingRHP) compiler.compile();
}); });
// ----------------- editor resize --------------- // ----------------- editor resize ---------------
...@@ -436,9 +435,9 @@ var run = function () { ...@@ -436,9 +435,9 @@ var run = function () {
$('#output').append($('<div/>').append($('<pre/>').text('Loading github.com/' + root + '/' + path + ' ...'))); $('#output').append($('<div/>').append($('<pre/>').text('Loading github.com/' + root + '/' + path + ' ...')));
return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path, cb); return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path, cb);
} }
var transactionDebugger = new Debugger('#debugger');
var executionContext = new ExecutionContext();
var executionContext = new ExecutionContext();
var transactionDebugger = new Debugger('#debugger', executionContext.event);
transactionDebugger.addProvider('VM', executionContext.vm()); transactionDebugger.addProvider('VM', executionContext.vm());
transactionDebugger.switchProvider('VM'); transactionDebugger.switchProvider('VM');
transactionDebugger.addProvider('INTERNAL', executionContext.web3()); transactionDebugger.addProvider('INTERNAL', executionContext.web3());
...@@ -456,44 +455,26 @@ var run = function () { ...@@ -456,44 +455,26 @@ var run = function () {
transactionDebugger.debug(data); transactionDebugger.debug(data);
}); });
var renderer = new Renderer(editor, executionContext.web3(), updateFiles, udapp, executionContext);
var formalVerification = new FormalVerification($('#verificationView'));
formalVerification.event.register('compilationError', this, function (message, container, noAnnotations) {
renderer.error(message, container, noAnnotations);
});
var compiler = new Compiler(editor, queryParams, handleGithubCall, updateFiles); var compiler = new Compiler(editor, queryParams, handleGithubCall, updateFiles);
var formalVerification = new FormalVerification($('#verificationView'), compiler.event);
var renderer = new Renderer(editor, executionContext.web3(), updateFiles, udapp, executionContext, formalVerification.event, compiler.event); // eslint-disable-line
executionContext.event.register('contextChanged', this, function (context) { executionContext.event.register('contextChanged', this, function (context) {
$('#output').empty();
context = context === 'vm' ? 'VM' : context;
context = context === 'injected' ? 'EXTERNAL' : context;
context = context === 'web3' ? 'INTERNAL' : context;
transactionDebugger.switchProvider(context);
compiler.compile(); compiler.compile();
}); });
executionContext.event.register('web3EndpointChanged', this, function (context) { executionContext.event.register('web3EndpointChanged', this, function (context) {
$('#output').empty();
compiler.compile(); compiler.compile();
}); });
executionContext.event.register('compilerLoaded', this, function (context) {
compiler.compile();
});
compiler.event.register('compilerLoaded', this, function (version) { compiler.event.register('compilerLoaded', this, function (version) {
setVersionText(version); setVersionText(version);
compiler.compile(); compiler.compile();
}); });
compiler.event.register('compilationError', this, function (data) {
renderer.error(data);
});
compiler.event.register('compilationSucceed', this, function (data, source) {
if (!hidingRHP) {
renderer.contracts(data, source);
formalVerification.compilationFinished(data);
}
});
compiler.event.register('isCompiling', this, function () {
$('#output').empty();
formalVerification.compiling();
});
function setVersionText (text) { function setVersionText (text) {
$('#version').text(text); $('#version').text(text);
......
...@@ -8,7 +8,7 @@ var Base64 = require('js-base64').Base64; ...@@ -8,7 +8,7 @@ var Base64 = require('js-base64').Base64;
var EventManager = require('../lib/eventManager'); var EventManager = require('../lib/eventManager');
/* /*
trigger compilationError, compilationSucceed, compilerLoaded, isCompiling trigger compilationFinished, compilerLoaded, compilationStarted
*/ */
function Compiler (editor, queryParams, handleGithubCall, updateFiles) { function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
var self = this; var self = this;
...@@ -44,7 +44,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { ...@@ -44,7 +44,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
var compile = function (missingInputs) { var compile = function (missingInputs) {
editor.clearAnnotations(); editor.clearAnnotations();
self.event.trigger('isCompiling', []); self.event.trigger('compilationStarted', []);
var input = editor.getValue(); var input = editor.getValue();
editor.setCacheFileContent(input); editor.setCacheFileContent(input);
...@@ -52,7 +52,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { ...@@ -52,7 +52,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
files[utils.fileNameFromKey(editor.getCacheFile())] = input; files[utils.fileNameFromKey(editor.getCacheFile())] = input;
gatherImports(files, missingInputs, function (input, error) { gatherImports(files, missingInputs, function (input, error) {
if (input === null) { if (input === null) {
this.event.trigger('compilationError', [error]); this.event.trigger('compilationFinished', [false, error, editor.getValue()]);
} else { } else {
var optimize = queryParams.get().optimize; var optimize = queryParams.get().optimize;
compileJSON(input, optimize ? 1 : 0); compileJSON(input, optimize ? 1 : 0);
...@@ -102,14 +102,14 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { ...@@ -102,14 +102,14 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
var noFatalErrors = true; // ie warnings are ok var noFatalErrors = true; // ie warnings are ok
if (data['error'] !== undefined) { if (data['error'] !== undefined) {
self.event.trigger('compilationError', [data['error']]); self.event.trigger('compilationFinished', [false, [data['error']], editor.getValue()]);
if (utils.errortype(data['error']) !== 'warning') { if (utils.errortype(data['error']) !== 'warning') {
noFatalErrors = false; noFatalErrors = false;
} }
} }
if (data['errors'] !== undefined) { if (data['errors'] !== undefined) {
self.event.trigger('compilationFinished', [false, data['errors'], editor.getValue()]);
data['errors'].forEach(function (err) { data['errors'].forEach(function (err) {
self.event.trigger('compilationError', [err]);
if (utils.errortype(err) !== 'warning') { if (utils.errortype(err) !== 'warning') {
noFatalErrors = false; noFatalErrors = false;
} }
...@@ -119,7 +119,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) { ...@@ -119,7 +119,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
if (missingInputs !== undefined && missingInputs.length > 0) { if (missingInputs !== undefined && missingInputs.length > 0) {
compile(missingInputs); compile(missingInputs);
} else if (noFatalErrors) { } else if (noFatalErrors) {
self.event.trigger('compilationSucceed', [data, editor.getValue()]); self.event.trigger('compilationFinished', [true, data, editor.getValue()]);
} }
} }
......
var remix = require('ethereum-remix'); var remix = require('ethereum-remix');
function Debugger (id) { function Debugger (id, executionContextEvent) {
this.el = document.querySelector(id); this.el = document.querySelector(id);
this.debugger = new remix.ui.Debugger(); this.debugger = new remix.ui.Debugger();
this.el.appendChild(this.debugger.render()); this.el.appendChild(this.debugger.render());
var self = this;
executionContextEvent.register('contextChanged', this, function (context) {
context = context === 'vm' ? 'VM' : context;
context = context === 'injected' ? 'EXTERNAL' : context;
context = context === 'web3' ? 'INTERNAL' : context;
self.switchProvider(context);
});
} }
Debugger.prototype.debug = function (receipt) { Debugger.prototype.debug = function (receipt) {
......
...@@ -19,7 +19,7 @@ var vm = new EthJSVM(null, null, { activatePrecompiles: true, enableHomestead: t ...@@ -19,7 +19,7 @@ var vm = new EthJSVM(null, null, { activatePrecompiles: true, enableHomestead: t
vm.stateManager.checkpoint(); vm.stateManager.checkpoint();
/* /*
trigger contextChanged trigger contextChanged, web3EndpointChanged
*/ */
function ExecutionContext () { function ExecutionContext () {
......
...@@ -2,23 +2,28 @@ var $ = require('jquery'); ...@@ -2,23 +2,28 @@ var $ = require('jquery');
var EventManager = require('../lib/eventManager'); var EventManager = require('../lib/eventManager');
/* /*
trigger compilationError trigger compilationFinished
*/ */
function FormalVerification (outputElement) { function FormalVerification (outputElement, compilerEvent) {
this.event = new EventManager(); this.event = new EventManager();
this.outputElement = outputElement; this.outputElement = outputElement;
} var self = this;
compilerEvent.register('compilationFinished', this, function (success, data, source) {
FormalVerification.prototype.compiling = function () { if (success) {
$('#formalVerificationInput', this.outputElement) self.compilationFinished(data);
}
});
compilerEvent.register('compilationStarted', this, function () {
$('#formalVerificationInput', self.outputElement)
.val('') .val('')
.hide(); .hide();
$('#formalVerificationErrors').empty(); $('#formalVerificationErrors').empty();
}; });
}
FormalVerification.prototype.compilationFinished = function (compilationResult) { FormalVerification.prototype.compilationFinished = function (compilationResult) {
if (compilationResult.formal === undefined) { if (compilationResult.formal === undefined) {
this.event.trigger('compilationError', ['Formal verification not supported by this compiler version.', $('#formalVerificationErrors'), true]); this.event.trigger('compilationFinished', [false, 'Formal verification not supported by this compiler version.', $('#formalVerificationErrors'), true]);
} else { } else {
if (compilationResult.formal['why3'] !== undefined) { if (compilationResult.formal['why3'] !== undefined) {
$('#formalVerificationInput', this.outputElement).val( $('#formalVerificationInput', this.outputElement).val(
...@@ -30,8 +35,10 @@ FormalVerification.prototype.compilationFinished = function (compilationResult) ...@@ -30,8 +35,10 @@ FormalVerification.prototype.compilationFinished = function (compilationResult)
if (compilationResult.formal.errors !== undefined) { if (compilationResult.formal.errors !== undefined) {
var errors = compilationResult.formal.errors; var errors = compilationResult.formal.errors;
for (var i = 0; i < errors.length; i++) { for (var i = 0; i < errors.length; i++) {
this.event.trigger('compilationError', [errors[i], $('#formalVerificationErrors'), true]); this.event.trigger('compilationFinished', [false, errors[i], $('#formalVerificationErrors'), true]);
} }
} else {
this.event.trigger('compilationFinished', [true, null, null, true]);
} }
} }
}; };
......
...@@ -3,12 +3,28 @@ var $ = require('jquery'); ...@@ -3,12 +3,28 @@ var $ = require('jquery');
var utils = require('./utils'); var utils = require('./utils');
var uiHelper = require('./ui-helper'); var uiHelper = require('./ui-helper');
function Renderer (editor, web3, updateFiles, udapp, executionContext) { function Renderer (editor, web3, updateFiles, udapp, executionContext, formalVerificationEvent, compilerEvent) {
this.editor = editor; this.editor = editor;
this.web3 = web3; this.web3 = web3;
this.updateFiles = updateFiles; this.updateFiles = updateFiles;
this.udapp = udapp; this.udapp = udapp;
this.executionContext = executionContext; this.executionContext = executionContext;
var self = this;
formalVerificationEvent.register('compilationFinished', this, function (success, message, container, noAnnotations) {
if (!success) {
self.error(message, container, noAnnotations);
}
});
compilerEvent.register('compilationFinished', this, function (success, data, source) {
$('#output').empty();
if (success) {
self.contracts(data, source);
} else {
data.forEach(function (err) {
self.error(err);
});
}
});
} }
Renderer.prototype.error = function (message, container, noAnnotations) { Renderer.prototype.error = function (message, container, noAnnotations) {
......
'use strict';
module.exports = {
extend: function (destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}
};
...@@ -8,6 +8,9 @@ var EthJSBlock = require('ethereumjs-block'); ...@@ -8,6 +8,9 @@ var EthJSBlock = require('ethereumjs-block');
var BN = ethJSUtil.BN; var BN = ethJSUtil.BN;
var EventManager = require('./lib/eventManager'); var EventManager = require('./lib/eventManager');
/*
trigger debugRequested
*/
function UniversalDApp (executionContext, options, txdebugger) { function UniversalDApp (executionContext, options, txdebugger) {
this.event = new EventManager(); this.event = new EventManager();
var self = this; var self = this;
......
var test = require('tape'); var test = require('tape');
var Compiler = require('../src/app/compiler'); var Compiler = require('../src/app/compiler');
var EventManager = require('../src/lib/eventManager');
test('compiler.compile smoke', function (t) { test('compiler.compile smoke', function (t) {
t.plan(1); t.plan(1);
...@@ -9,7 +10,7 @@ test('compiler.compile smoke', function (t) { ...@@ -9,7 +10,7 @@ test('compiler.compile smoke', function (t) {
var getCacheFile = function () { return 'fakeCacheFile'; }; var getCacheFile = function () { return 'fakeCacheFile'; };
var fakeEditor = {onChangeSetup: noop, clearAnnotations: noop, getValue: noop, setCacheFileContent: noop, getCacheFile: getCacheFile}; var fakeEditor = {onChangeSetup: noop, clearAnnotations: noop, getValue: noop, setCacheFileContent: noop, getCacheFile: getCacheFile};
var fakeQueryParams = {get: function () { return {}; }}; var fakeQueryParams = {get: function () { return {}; }};
var compiler = new Compiler(fakeEditor, fakeQueryParams, null, null); var compiler = new Compiler(fakeEditor, fakeQueryParams, null, null, new EventManager());
compiler.setCompileJSON(noop); compiler.setCompileJSON(noop);
compiler.compile(); compiler.compile();
t.ok(compiler); t.ok(compiler);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment