Commit f738864d authored by chriseth's avatar chriseth

Merge pull request #51 from ethereum/use-standard-js

Use formatting according to 'istandard'
parents 7cd61b16 60ebbee3
chrome.browserAction.onClicked.addListener(function(tab) {
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) {
chrome.tabs.create({ 'url': chrome.extension.getURL('index.html') }, function (tab) {
// tab opened
});
......
This diff is collapsed.
......@@ -4,7 +4,7 @@ var Renderer = require('./renderer');
var Base64 = require('js-base64').Base64;
function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles) {
function Compiler (editor, handleGithubCall, outputField, hidingRHP, updateFiles) {
var renderer = new Renderer(editor, this, updateFiles);
var compileJSON;
......@@ -18,22 +18,25 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
var compileTimeout = null;
function onChange() {
function onChange () {
var input = editor.getValue();
if (input === "") {
if (input === '') {
editor.setCacheFileContent('');
return;
}
if (input === previousInput)
if (input === previousInput) {
return;
}
previousInput = input;
if (compileTimeout) window.clearTimeout(compileTimeout);
if (compileTimeout) {
window.clearTimeout(compileTimeout);
}
compileTimeout = window.setTimeout(compile, 300);
}
editor.onChangeSetup(onChange);
var compile = function(missingInputs) {
var compile = function (missingInputs) {
editor.clearAnnotations();
sourceAnnotations = [];
outputField.empty();
......@@ -42,7 +45,7 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
var files = {};
files[editor.getCacheFile()] = input;
gatherImports(files, missingInputs, function(input, error) {
gatherImports(files, missingInputs, function (input, error) {
outputField.empty();
if (input === null) {
renderer.error(error);
......@@ -54,52 +57,52 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
};
this.compile = compile;
this.addAnnotation = function(annotation) {
this.addAnnotation = function (annotation) {
sourceAnnotations[sourceAnnotations.length] = annotation;
editor.setAnnotations(sourceAnnotations);
};
this.setCompileJSON = function() {
compileJSON = function(source, optimize) { compilationFinished('{}'); };
this.setCompileJSON = function () {
compileJSON = function (source, optimize) { compilationFinished('{}'); };
};
function onCompilerLoaded(setVersionText) {
function onCompilerLoaded (setVersionText) {
if (worker === null) {
var compile;
var missingInputs = [];
if ('_compileJSONCallback' in Module) {
compilerAcceptsMultipleFiles = true;
var missingInputsCallback = Module.Runtime.addFunction(function(path, contents, error) {
var missingInputsCallback = Module.Runtime.addFunction(function (path, contents, error) {
missingInputs.push(Module.Pointer_stringify(path));
});
var compileInternal = Module.cwrap("compileJSONCallback", "string", ["string", "number", "number"]);
compile = function(input, optimize) {
var compileInternal = Module.cwrap('compileJSONCallback', 'string', [ 'string', 'number', 'number' ]);
compile = function (input, optimize) {
missingInputs.length = 0;
return compileInternal(input, optimize, missingInputsCallback);
};
} else if ('_compileJSONMulti' in Module) {
compilerAcceptsMultipleFiles = true;
compile = Module.cwrap("compileJSONMulti", "string", ["string", "number"]);
compile = Module.cwrap('compileJSONMulti', 'string', [ 'string', 'number' ]);
} else {
compilerAcceptsMultipleFiles = false;
compile = Module.cwrap("compileJSON", "string", ["string", "number"]);
compile = Module.cwrap('compileJSON', 'string', [ 'string', 'number' ]);
}
compileJSON = function(source, optimize, cb) {
compileJSON = function (source, optimize, cb) {
try {
var result = compile(source, optimize);
} catch (exception) {
result = JSON.stringify({error: 'Uncaught JavaScript exception:\n' + exception});
result = JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception });
}
compilationFinished(result, missingInputs);
};
setVersionText(Module.cwrap("version", "string", [])());
setVersionText(Module.cwrap('version', 'string', [])());
}
previousInput = '';
onChange();
};
this.onCompilerLoaded = onCompilerLoaded;
function compilationFinished(result, missingInputs) {
function compilationFinished (result, missingInputs) {
var data;
var noFatalErrors = true; // ie warnings are ok
......@@ -112,26 +115,32 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
if (data['error'] !== undefined) {
renderer.error(data['error']);
if (utils.errortype(data['error']) !== 'warning') noFatalErrors = false;
if (utils.errortype(data['error']) !== 'warning') {
noFatalErrors = false;
}
}
if (data['errors'] != undefined) {
data['errors'].forEach(function(err) {
if (data['errors'] !== undefined) {
data['errors'].forEach(function (err) {
renderer.error(err);
if (utils.errortype(err) !== 'warning') noFatalErrors = false;
if (utils.errortype(err) !== 'warning') {
noFatalErrors = false;
}
});
}
if (missingInputs !== undefined && missingInputs.length > 0)
if (missingInputs !== undefined && missingInputs.length > 0) {
compile(missingInputs);
else if (noFatalErrors && !hidingRHP())
} else if (noFatalErrors && !hidingRHP()) {
renderer.contracts(data, editor.getValue());
}
}
this.initializeWorker = function(version, setVersionText) {
if (worker !== null)
this.initializeWorker = function (version, setVersionText) {
if (worker !== null) {
worker.terminate();
}
worker = new Worker('worker.js');
worker.addEventListener('message', function(msg) {
worker.addEventListener('message', function (msg) {
var data = msg.data;
switch (data.cmd) {
case 'versionLoaded':
......@@ -144,18 +153,17 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
break;
};
});
worker.onerror = function(msg) { console.log(msg.data); };
worker.addEventListener('error', function(msg) { console.log(msg.data); });
compileJSON = function(source, optimize) {
worker.onerror = function (msg) { console.log(msg.data); };
worker.addEventListener('error', function (msg) { console.log(msg.data); });
compileJSON = function (source, optimize) {
worker.postMessage({cmd: 'compile', source: source, optimize: optimize});
};
worker.postMessage({cmd: 'loadVersion', data: 'https://ethereum.github.io/solc-bin/bin/' + version});
};
function gatherImports(files, importHints, cb) {
function gatherImports (files, importHints, cb) {
importHints = importHints || [];
if (!compilerAcceptsMultipleFiles)
{
if (!compilerAcceptsMultipleFiles) {
cb(files[editor.getCacheFile()]);
return;
}
......@@ -166,12 +174,15 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
reloop = false;
for (var fileName in files) {
var match;
while (match = importRegex.exec(files[fileName]))
while (match = importRegex.exec(files[fileName])) {
importHints.push(match[1]);
}
}
while (importHints.length > 0) {
var m = importHints.pop();
if (m in files) continue;
if (m in files) {
continue;
}
if (editor.hasFile(m)) {
files[m] = window.localStorage[utils.fileKey(m)];
reloop = true;
......@@ -182,27 +193,26 @@ function Compiler(editor, handleGithubCall, outputField, hidingRHP, updateFiles)
files[m] = cachedRemoteFiles[m];
reloop = true;
} else if (githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^\/]*\/[^\/]*)\/(.*)/.exec(m)) {
handleGithubCall(githubMatch[3], githubMatch[4], function(result) {
if ('content' in result)
{
handleGithubCall(githubMatch[3], githubMatch[4], function (result) {
if ('content' in result) {
var content = Base64.decode(result.content);
cachedRemoteFiles[m] = content;
files[m] = content;
gatherImports(files, importHints, cb);
} else {
cb(null, 'Unable to import "' + m + '"');
}
else
cb(null, "Unable to import \"" + m + "\"");
}).fail(function(){
cb(null, "Unable to import \"" + m + "\"");
}).fail(function () {
cb(null, 'Unable to import "' + m + '"');
});
return;
} else {
cb(null, "Unable to import \"" + m + "\"");
cb(null, 'Unable to import "' + m + '"');
return;
}
}
} while (reloop);
cb(JSON.stringify({'sources':files}));
cb(JSON.stringify({ 'sources': files }));
}
}
......
......@@ -3,51 +3,52 @@ var utils = require('./utils');
var ace = require('brace');
require('../mode-solidity.js');
function Editor(loadingFromGist) {
function Editor (loadingFromGist) {
this.newFile = function() {
this.newFile = function () {
untitledCount = '';
while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount])
while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount]) {
untitledCount = (untitledCount - 0) + 1;
}
SOL_CACHE_FILE = SOL_CACHE_UNTITLED + untitledCount;
sessions[SOL_CACHE_FILE] = null;
this.setCacheFileContent('');
};
this.setCacheFileContent = function(content) {
this.setCacheFileContent = function (content) {
window.localStorage.setItem(SOL_CACHE_FILE, content);
};
this.setCacheFile = function(cacheFile) {
this.setCacheFile = function (cacheFile) {
SOL_CACHE_FILE = utils.fileKey(cacheFile);
};
this.getCacheFile = function() {
this.getCacheFile = function () {
return utils.fileNameFromKey(SOL_CACHE_FILE);
};
this.cacheFileIsPresent = function() {
this.cacheFileIsPresent = function () {
return !!SOL_CACHE_FILE;
};
this.setNextFile = function(fileKey) {
var index = this.getFiles().indexOf( fileKey );
this.setCacheFile(this.getFiles()[ Math.max(0, index - 1)]);
this.setNextFile = function (fileKey) {
var index = this.getFiles().indexOf(fileKey);
this.setCacheFile(this.getFiles()[ Math.max(0, index - 1) ]);
};
this.resetSession = function() {
editor.setSession( sessions[SOL_CACHE_FILE] );
this.resetSession = function () {
editor.setSession(sessions[SOL_CACHE_FILE]);
editor.focus();
};
this.hasFile = function(name) {
this.hasFile = function (name) {
return this.getFiles().indexOf(utils.fileKey(name)) !== -1
};
this.getFiles = function() {
this.getFiles = function () {
var files = [];
for (var f in localStorage ) {
if (f.indexOf( utils.getCacheFilePrefix(), 0 ) === 0) {
for (var f in localStorage) {
if (f.indexOf(utils.getCacheFilePrefix(), 0) === 0) {
files.push(f);
if (!sessions[f]) sessions[f] = newEditorSession(f);
}
......@@ -55,7 +56,7 @@ function Editor(loadingFromGist) {
return files;
}
this.packageFiles = function() {
this.packageFiles = function () {
var files = {};
var filesArr = this.getFiles();
......@@ -67,47 +68,47 @@ function Editor(loadingFromGist) {
return files;
};
this.resize = function() {
this.resize = function () {
editor.resize();
var session = editor.getSession();
session.setUseWrapMode(document.querySelector('#editorWrap').checked);
if(session.getUseWrapMode()) {
if (session.getUseWrapMode()) {
var characterWidth = editor.renderer.characterWidth;
var contentWidth = editor.container.ownerDocument.getElementsByClassName("ace_scroller")[0].clientWidth;
var contentWidth = editor.container.ownerDocument.getElementsByClassName('ace_scroller')[0].clientWidth;
if(contentWidth > 0) {
if (contentWidth > 0) {
session.setWrapLimit(parseInt(contentWidth / characterWidth, 10));
}
}
};
this.getValue = function() {
this.getValue = function () {
return editor.getValue();
};
this.clearAnnotations = function() {
this.clearAnnotations = function () {
editor.getSession().clearAnnotations();
};
this.setAnnotations = function(sourceAnnotations) {
this.setAnnotations = function (sourceAnnotations) {
editor.getSession().setAnnotations(sourceAnnotations);
};
this.onChangeSetup = function(onChange) {
this.onChangeSetup = function (onChange) {
editor.getSession().on('change', onChange);
editor.on('changeSession', function(){
editor.on('changeSession', function () {
editor.getSession().on('change', onChange);
onChange();
})
};
this.handleErrorClick = function(errLine, errCol) {
this.handleErrorClick = function (errLine, errCol) {
editor.focus();
editor.gotoLine(errLine + 1, errCol - 1, true);
};
function newEditorSession(filekey) {
var s = new ace.EditSession(window.localStorage[filekey], "ace/mode/javascript")
function newEditorSession (filekey) {
var s = new ace.EditSession(window.localStorage[filekey], 'ace/mode/javascript')
s.setUndoManager(new ace.UndoManager());
s.setTabSize(4);
s.setUseSoftTabs(true);
......@@ -115,13 +116,14 @@ function Editor(loadingFromGist) {
return s;
}
function setupStuff(files) {
function setupStuff (files) {
var untitledCount = '';
if (!files.length || window.localStorage['sol-cache']) {
if(loadingFromGist) return;
if (loadingFromGist) return;
// Backwards-compatibility
while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount])
while (window.localStorage[SOL_CACHE_UNTITLED + untitledCount]) {
untitledCount = (untitledCount - 0) + 1;
}
SOL_CACHE_FILE = SOL_CACHE_UNTITLED + untitledCount;
window.localStorage[SOL_CACHE_FILE] = window.localStorage['sol-cache'] || BALLOT_EXAMPLE;
window.localStorage.removeItem('sol-cache');
......@@ -133,14 +135,14 @@ function Editor(loadingFromGist) {
sessions[files[x]] = newEditorSession(files[x])
}
editor.setSession( sessions[SOL_CACHE_FILE] );
editor.setSession(sessions[SOL_CACHE_FILE]);
editor.resize(true);
}
var SOL_CACHE_UNTITLED = utils.getCacheFilePrefix() + 'Untitled';
var SOL_CACHE_FILE = null;
var editor = ace.edit("input");
var editor = ace.edit('input');
var sessions = {};
setupStuff(this.getFiles());
......
var queryParams = require('./query-params');
function handleLoad(cb) {
function handleLoad (cb) {
var params = queryParams.get();
var loadingFromGist = false;
if (typeof params['gist'] != undefined) {
if (typeof params['gist'] !== undefined) {
var gistId;
if (params['gist'] === '') {
var str = prompt("Enter the URL or ID of the Gist you would like to load.");
var str = prompt('Enter the URL or ID of the Gist you would like to load.');
if (str !== '') {
gistId = getGistId( str );
gistId = getGistId(str);
loadingFromGist = !!gistId;
}
} else {
gistId = params['gist'];
loadingFromGist = !!gistId;
}
if (loadingFromGist) cb(gistId);
if (loadingFromGist) {
cb(gistId);
}
}
return loadingFromGist;
}
function getGistId(str) {
function getGistId (str) {
var idr = /[0-9A-Fa-f]{8,}/;
var match = idr.exec(str);
return match ? match[0] : null;
......
function getQueryParams() {
function getQueryParams () {
var qs = window.location.hash.substr(1);
if (window.location.search.length > 0) {
// use legacy query params instead of hash
window.location.hash = window.location.search.substr(1);
window.location.search = "";
window.location.search = '';
}
var params = {};
var parts = qs.split("&");
var parts = qs.split('&');
for (var x in parts) {
var keyValue = parts[x].split("=");
if (keyValue[0] !== "") params[keyValue[0]] = keyValue[1];
var keyValue = parts[x].split('=');
if (keyValue[0] !== '') {
params[keyValue[0]] = keyValue[1];
}
}
return params;
}
function updateQueryParams(params) {
function updateQueryParams (params) {
var currentParams = getQueryParams();
var keys = Object.keys(params);
for (var x in keys) {
currentParams[keys[x]] = params[keys[x]];
}
var queryString = "#";
var queryString = '#';
var updatedKeys = Object.keys(currentParams);
for( var y in updatedKeys) {
queryString += updatedKeys[y] + "=" + currentParams[updatedKeys[y]] + "&";
for (var y in updatedKeys) {
queryString += updatedKeys[y] + '=' + currentParams[updatedKeys[y]] + '&';
}
window.location.hash = queryString.slice(0, -1);
}
......
This diff is collapsed.
var utils = require('./utils');
function StorageHandler(updateFiles) {
function StorageHandler (updateFiles) {
this.sync = function() {
this.sync = function () {
if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) return;
if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) {
return;
}
var obj = {};
var done = false;
var count = 0
var dont = 0;
function check(key){
chrome.storage.sync.get( key, function(resp){
console.log("comparing to cloud", key, resp);
if (typeof resp[key] != 'undefined' && obj[key] !== resp[key] && confirm("Overwrite '" + fileNameFromKey(key) + "'? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.")) {
console.log("Overwriting", key );
localStorage.setItem( key, resp[key] );
function check (key) {
chrome.storage.sync.get(key, function (resp) {
console.log('comparing to cloud', key, resp);
if (typeof resp[key] !== 'undefined' && obj[key] !== resp[key] && confirm('Overwrite "' + fileNameFromKey(key) + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) {
console.log('Overwriting', key);
localStorage.setItem(key, resp[key]);
updateFiles();
} else {
console.log( "add to obj", obj, key);
console.log('add to obj', obj, key);
obj[key] = localStorage[key];
}
done++;
if (done >= count) chrome.storage.sync.set( obj, function(){
console.log( "updated cloud files with: ", obj, this, arguments);
})
if (done >= count) {
chrome.storage.sync.set(obj, function () {
console.log('updated cloud files with: ', obj, this, arguments);
})
}
})
}
for (var y in window.localStorage) {
console.log("checking", y);
console.log('checking', y);
obj[y] = window.localStorage.getItem(y);
if (y.indexOf(utils.getCacheFilePrefix()) !== 0) continue;
if (y.indexOf(utils.getCacheFilePrefix()) !== 0) {
continue;
}
count++;
check(y);
}
......
var SOL_CACHE_FILE_PREFIX = 'sol-cache-file-';
function getCacheFilePrefix() {
function getCacheFilePrefix () {
return SOL_CACHE_FILE_PREFIX;
}
function fileKey( name ) {
function fileKey (name) {
return getCacheFilePrefix() + name;
}
function fileNameFromKey(key) {
return key.replace( getCacheFilePrefix(), '' );
function fileNameFromKey (key) {
return key.replace(getCacheFilePrefix(), '');
}
function errortype(message) {
function errortype (message) {
return message.match(/^.*:[0-9]*:[0-9]* Warning: /) ? 'warning' : 'error';
}
......
require('es6-shim');
var app = require("./app.js");
var $ = require("jquery");
var app = require('./app.js');
var $ = require('jquery');
$(document).ready(function() { app.run(); });
\ No newline at end of file
$(document).ready(function () { app.run(); });
\ No newline at end of file
This diff is collapsed.
// This mainly extracts the provider that might be
// supplied through mist.
var Web3 = require("web3");
var Web3 = require('web3');
if (typeof web3 !== 'undefined')
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
else
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
} else {
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
}
module.exports = web3;
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