From 2126391e3c343573230bfea9ffac47c76ad3b91c Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 8 Oct 2016 14:28:51 +0100 Subject: [PATCH] Format using standard --- background.js | 8 +- ci/makeMockCompiler.js | 60 +-- src/app.js | 565 ++++++++++---------- src/app/compiler-worker.js | 44 +- src/app/compiler.js | 250 ++++----- src/app/debugger.js | 112 ++-- src/app/editor.js | 206 ++++---- src/app/example-contracts.js | 66 +-- src/app/execution-context.js | 118 ++--- src/app/formalVerification.js | 38 +- src/app/gist-handler.js | 32 +- src/app/query-params.js | 40 +- src/app/renderer.js | 148 +++--- src/app/storage.js | 98 ++-- src/app/ui-helper.js | 124 ++--- src/app/utils.js | 16 +- src/index.js | 10 +- src/lib/eventManager.js | 32 +- src/universal-dapp.js | 714 +++++++++++++------------- test-browser/helpers/contracts.js | 22 +- test-browser/mockcompiler/compiler.js | 24 +- test-browser/mockcompiler/requests.js | 64 +-- test-browser/tests/ballot.js | 33 +- test-browser/tests/debugger.js | 6 +- test-browser/tests/new-file-test.js | 6 +- test-browser/tests/simpleContract.js | 22 +- test-browser/tests/smoke-test.js | 6 +- test/compiler-test.js | 28 +- test/gist-handler-test.js | 79 ++- test/index.js | 8 +- test/query-params-test.js | 30 +- 31 files changed, 1508 insertions(+), 1501 deletions(-) diff --git a/background.js b/background.js index 001d137f37..8b9269f940 100644 --- a/background.js +++ b/background.js @@ -1,10 +1,10 @@ /* global chrome */ -'use strict'; +'use strict' chrome.browserAction.onClicked.addListener(function (tab) { - chrome.storage.sync.set({ 'chrome-app-sync': true }); + chrome.storage.sync.set({ 'chrome-app-sync': true }) chrome.tabs.create({ 'url': chrome.extension.getURL('index.html') }, function (tab) { // tab opened - }); -}); + }) +}) diff --git a/ci/makeMockCompiler.js b/ci/makeMockCompiler.js index a957754346..d409127b68 100644 --- a/ci/makeMockCompiler.js +++ b/ci/makeMockCompiler.js @@ -1,56 +1,56 @@ -var fs = require('fs'); -var solc = require('solc/wrapper'); -var soljson = require('../soljson'); -var compiler = solc(soljson); -var inputs = require('../test-browser/mockcompiler/requests.js'); -var compilationResult = gatherCompilationResults(inputs); -replaceSolCompiler(compilationResult); +var fs = require('fs') +var solc = require('solc/wrapper') +var soljson = require('../soljson') +var compiler = solc(soljson) +var inputs = require('../test-browser/mockcompiler/requests.js') +var compilationResult = gatherCompilationResults(inputs) +replaceSolCompiler(compilationResult) function gatherCompilationResults (sol) { - var compilationResult = {}; + var compilationResult = {} for (var k in sol) { - var item = sol[k]; - var result = compile(item, 1); - compilationResult[result.key] = result; - result = compile(item, 0); - compilationResult[result.key] = result; + var item = sol[k] + var result = compile(item, 1) + compilationResult[result.key] = result + result = compile(item, 0) + compilationResult[result.key] = result } - return compilationResult; + return compilationResult } function compile (source, optimization) { - var missingInputs = []; + var missingInputs = [] var result = compiler.compile(source, optimization, function (path) { - missingInputs.push(path); - }); - var key = optimization.toString(); + missingInputs.push(path) + }) + var key = optimization.toString() for (var k in source.sources) { - key += k + source.sources[k]; + key += k + source.sources[k] } - key = key.replace(/(\t)|(\n)|( )/g, ''); + key = key.replace(/(\t)|(\n)|( )/g, '') return { key: key, source: source, optimization: optimization, missingInputs: missingInputs, result: result - }; + } } function replaceSolCompiler (results) { fs.readFile('./test-browser/mockcompiler/compiler.js', 'utf8', function (error, data) { if (error) { - console.log(error); - process.exit(1); - return; + console.log(error) + process.exit(1) + return } - data = data + '\n\nvar mockData = ' + JSON.stringify(results) + ';\n'; + data = data + '\n\nvar mockData = ' + JSON.stringify(results) + ';\n' fs.writeFile('./soljson.js', data, 'utf8', function (error) { if (error) { - console.log(error); - process.exit(1); - return; + console.log(error) + process.exit(1) + return } - }); - }); + }) + }) } diff --git a/src/app.js b/src/app.js index 0188203cdb..8fab4021ee 100644 --- a/src/app.js +++ b/src/app.js @@ -1,63 +1,66 @@ /* global alert, confirm, prompt, Option, Worker */ -'use strict'; - -var $ = require('jquery'); -var base64 = require('js-base64').Base64; - -var utils = require('./app/utils'); -var QueryParams = require('./app/query-params'); -var queryParams = new QueryParams(); -var GistHandler = require('./app/gist-handler'); -var gistHandler = new GistHandler(); - -var Storage = require('./app/storage'); -var Editor = require('./app/editor'); -var Renderer = require('./app/renderer'); -var Compiler = require('./app/compiler'); -var ExecutionContext = require('./app/execution-context'); -var UniversalDApp = require('./universal-dapp.js'); -var Debugger = require('./app/debugger'); -var FormalVerification = require('./app/formalVerification'); -var EventManager = require('./lib/eventManager'); +'use strict' + +var $ = require('jquery') +var base64 = require('js-base64').Base64 + +var utils = require('./app/utils') +var QueryParams = require('./app/query-params') +var queryParams = new QueryParams() +var GistHandler = require('./app/gist-handler') +var gistHandler = new GistHandler() + +var Storage = require('./app/storage') +var Editor = require('./app/editor') +var Renderer = require('./app/renderer') +var Compiler = require('./app/compiler') +var ExecutionContext = require('./app/execution-context') +var UniversalDApp = require('./universal-dapp.js') +var Debugger = require('./app/debugger') +var FormalVerification = require('./app/formalVerification') +var EventManager = require('./lib/eventManager') + // The event listener needs to be registered as early as possible, because the // parent will send the message upon the "load" event. -var filesToLoad = null; -var loadFilesCallback = function (files) { filesToLoad = files; }; // will be replaced later +var filesToLoad = null +var loadFilesCallback = function (files) { filesToLoad = files } // will be replaced later + window.addEventListener('message', function (ev) { if (typeof ev.data === typeof [] && ev.data[0] === 'loadFiles') { - loadFilesCallback(ev.data[1]); + loadFilesCallback(ev.data[1]) } -}, false); +}, false) + /* trigger tabChanged */ var run = function () { - var self = this; - this.event = new EventManager(); - var storage = new Storage(updateFiles); + var self = this + this.event = new EventManager() + var storage = new Storage(updateFiles) function loadFiles (files) { for (var f in files) { - var key = utils.fileKey(f); - var content = files[f].content; - storage.loadFile(key, content); + var key = utils.fileKey(f) + var content = files[f].content + storage.loadFile(key, content) } - editor.setCacheFile(utils.fileKey(Object.keys(files)[0])); - updateFiles(); + editor.setCacheFile(utils.fileKey(Object.keys(files)[0])) + updateFiles() } loadFilesCallback = function (files) { - loadFiles(files); - }; + loadFiles(files) + } if (filesToLoad !== null) { - loadFiles(filesToLoad); + loadFiles(filesToLoad) } // -------- check file upload capabilities ------- if (!(window.File || window.FileReader || window.FileList || window.Blob)) { - $('.uploadFile').remove(); + $('.uploadFile').remove() } // ------------------ gist load ---------------- @@ -70,47 +73,47 @@ var run = function () { success: function (response) { if (response.data) { if (!response.data.files) { - alert('Gist load error: ' + response.data.message); - return; + alert('Gist load error: ' + response.data.message) + return } - loadFiles(response.data.files); + loadFiles(response.data.files) } } - }); - }); + }) + }) // ----------------- storage sync -------------------- - window.syncStorage = storage.sync; - storage.sync(); + window.syncStorage = storage.sync + storage.sync() // ----------------- editor ---------------------- - var editor = new Editor(loadingFromGist, storage); + var editor = new Editor(loadingFromGist, storage) // ----------------- tabbed menu ------------------- $('#options li').click(function (ev) { - var $el = $(this); - selectTab($el); - }); + var $el = $(this) + selectTab($el) + }) var selectTab = function (el) { - var match = /[a-z]+View/.exec(el.get(0).className); - if (!match) return; - var cls = match[0]; + var match = /[a-z]+View/.exec(el.get(0).className) + if (!match) return + var cls = match[0] if (!el.hasClass('active')) { - el.parent().find('li').removeClass('active'); - $('#optionViews').attr('class', '').addClass(cls); - el.addClass('active'); + el.parent().find('li').removeClass('active') + $('#optionViews').attr('class', '').addClass(cls) + el.addClass('active') } - self.event.trigger('tabChanged', [cls]); - }; + self.event.trigger('tabChanged', [cls]) + } // ------------------ gist publish -------------- $('#gist').click(function () { if (confirm('Are you sure you want to publish all your files anonymously as a public gist on github.com?')) { - var files = editor.packageFiles(); - var description = 'Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=' + queryParams.get().version + '&optimize=' + queryParams.get().optimize + '&gist='; + var files = editor.packageFiles() + var description = 'Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=' + queryParams.get().version + '&optimize=' + queryParams.get().optimize + '&gist=' $.ajax({ url: 'https://api.github.com/gists', @@ -122,159 +125,161 @@ var run = function () { }) }).done(function (response) { if (response.html_url && confirm('Created a gist at ' + response.html_url + ' Would you like to open it in a new window?')) { - window.open(response.html_url, '_blank'); + window.open(response.html_url, '_blank') } - }); + }) } - }); + }) $('#copyOver').click(function () { var target = prompt( 'To which other browser-solidity instance do you want to copy over all files?', 'https://ethereum.github.io/browser-solidity/' - ); + ) if (target === null) { - return; + return } - var files = editor.packageFiles(); - $('