register event in inner class

pull/1/head
yann300 9 years ago
parent d172d68b71
commit afa87c9626
  1. 41
      src/app.js
  2. 12
      src/app/compiler.js
  3. 10
      src/app/debugger.js
  4. 2
      src/app/execution-context.js
  5. 27
      src/app/formalVerification.js
  6. 18
      src/app/renderer.js
  7. 9
      src/lib/util.js
  8. 3
      src/universal-dapp.js
  9. 3
      test/compiler-test.js

@ -28,7 +28,7 @@ window.addEventListener('message', function (ev) {
}
}, false);
/*
trigger selectTab
trigger tabChanged
*/
var run = function () {
var self = this;
@ -411,7 +411,6 @@ var run = function () {
setEditorSize(hidingRHP ? 0 : storage.getEditorSize());
$('.toggleRHP i').toggleClass('fa-angle-double-right', !hidingRHP);
$('.toggleRHP i').toggleClass('fa-angle-double-left', hidingRHP);
if (!hidingRHP) compiler.compile();
});
// ----------------- editor resize ---------------
@ -436,9 +435,9 @@ var run = function () {
$('#output').append($('<div/>').append($('<pre/>').text('Loading github.com/' + root + '/' + path + ' ...')));
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.switchProvider('VM');
transactionDebugger.addProvider('INTERNAL', executionContext.web3());
@ -456,44 +455,26 @@ var run = function () {
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 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) {
$('#output').empty();
context = context === 'vm' ? 'VM' : context;
context = context === 'injected' ? 'EXTERNAL' : context;
context = context === 'web3' ? 'INTERNAL' : context;
transactionDebugger.switchProvider(context);
compiler.compile();
});
executionContext.event.register('web3EndpointChanged', this, function (context) {
$('#output').empty();
compiler.compile();
});
executionContext.event.register('compilerLoaded', this, function (context) {
compiler.compile();
});
compiler.event.register('compilerLoaded', this, function (version) {
setVersionText(version);
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) {
$('#version').text(text);

@ -8,7 +8,7 @@ var Base64 = require('js-base64').Base64;
var EventManager = require('../lib/eventManager');
/*
trigger compilationError, compilationSucceed, compilerLoaded, isCompiling
trigger compilationFinished, compilerLoaded, compilationStarted
*/
function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
var self = this;
@ -44,7 +44,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
var compile = function (missingInputs) {
editor.clearAnnotations();
self.event.trigger('isCompiling', []);
self.event.trigger('compilationStarted', []);
var input = editor.getValue();
editor.setCacheFileContent(input);
@ -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) {
this.event.trigger('compilationError', [error]);
this.event.trigger('compilationFinished', [false, error, editor.getValue()]);
} else {
var optimize = queryParams.get().optimize;
compileJSON(input, optimize ? 1 : 0);
@ -102,14 +102,14 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
var noFatalErrors = true; // ie warnings are ok
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') {
noFatalErrors = false;
}
}
if (data['errors'] !== undefined) {
self.event.trigger('compilationFinished', [false, data['errors'], editor.getValue()]);
data['errors'].forEach(function (err) {
self.event.trigger('compilationError', [err]);
if (utils.errortype(err) !== 'warning') {
noFatalErrors = false;
}
@ -119,7 +119,7 @@ function Compiler (editor, queryParams, handleGithubCall, updateFiles) {
if (missingInputs !== undefined && missingInputs.length > 0) {
compile(missingInputs);
} else if (noFatalErrors) {
self.event.trigger('compilationSucceed', [data, editor.getValue()]);
self.event.trigger('compilationFinished', [true, data, editor.getValue()]);
}
}

@ -1,9 +1,17 @@
var remix = require('ethereum-remix');
function Debugger (id) {
function Debugger (id, executionContextEvent) {
this.el = document.querySelector(id);
this.debugger = new remix.ui.Debugger();
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) {

@ -19,7 +19,7 @@ var vm = new EthJSVM(null, null, { activatePrecompiles: true, enableHomestead: t
vm.stateManager.checkpoint();
/*
trigger contextChanged
trigger contextChanged, web3EndpointChanged
*/
function ExecutionContext () {

@ -2,23 +2,28 @@ var $ = require('jquery');
var EventManager = require('../lib/eventManager');
/*
trigger compilationError
trigger compilationFinished
*/
function FormalVerification (outputElement) {
function FormalVerification (outputElement, compilerEvent) {
this.event = new EventManager();
this.outputElement = outputElement;
}
FormalVerification.prototype.compiling = function () {
$('#formalVerificationInput', this.outputElement)
var self = this;
compilerEvent.register('compilationFinished', this, function (success, data, source) {
if (success) {
self.compilationFinished(data);
}
});
compilerEvent.register('compilationStarted', this, function () {
$('#formalVerificationInput', self.outputElement)
.val('')
.hide();
$('#formalVerificationErrors').empty();
};
$('#formalVerificationErrors').empty();
});
}
FormalVerification.prototype.compilationFinished = function (compilationResult) {
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 {
if (compilationResult.formal['why3'] !== undefined) {
$('#formalVerificationInput', this.outputElement).val(
@ -30,8 +35,10 @@ FormalVerification.prototype.compilationFinished = function (compilationResult)
if (compilationResult.formal.errors !== undefined) {
var errors = compilationResult.formal.errors;
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');
var utils = require('./utils');
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.web3 = web3;
this.updateFiles = updateFiles;
this.udapp = udapp;
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) {

@ -1,9 +0,0 @@
'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');
var BN = ethJSUtil.BN;
var EventManager = require('./lib/eventManager');
/*
trigger debugRequested
*/
function UniversalDApp (executionContext, options, txdebugger) {
this.event = new EventManager();
var self = this;

@ -1,6 +1,7 @@
var test = require('tape');
var Compiler = require('../src/app/compiler');
var EventManager = require('../src/lib/eventManager');
test('compiler.compile smoke', function (t) {
t.plan(1);
@ -9,7 +10,7 @@ test('compiler.compile smoke', function (t) {
var getCacheFile = function () { return 'fakeCacheFile'; };
var fakeEditor = {onChangeSetup: noop, clearAnnotations: noop, getValue: noop, setCacheFileContent: noop, getCacheFile: getCacheFile};
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.compile();
t.ok(compiler);

Loading…
Cancel
Save