lint sandbox

This commit is contained in:
Berkeley Martinez
2015-08-27 11:40:06 -07:00
parent ce364b472f
commit 45c0c710e0

View File

@ -1,88 +1,90 @@
/* global jailed */
var printCallback; var printCallback;
// sends the input to the plugin for evaluation
var submit = function(code,callback) {
printCallback = callback;
// postpone the evaluation until the plugin is initialized
plugin.whenConnected(
function() {
if (requests == 0) {
startLoading();
}
requests++; // sends the input to the plugin for evaluation
plugin.remote.run(code); function submit(code, callback) {
} printCallback = callback;
);
}; // postpone the evaluation until the plugin is initialized
plugin.whenConnected(function() {
if (requests === 0) {
startLoading();
}
requests++;
plugin.remote.run(code);
});
}
// puts the message on the terminal // puts the message on the terminal
var print = function(cls, msg) { var print = function(cls, msg) {
printCallback(cls,msg); printCallback(cls, msg);
}; };
// will restart the plugin if it does not respond // will restart the plugin if it does not respond
var disconnectTimeout = null; var disconnectTimeout = null;
var startLoading = function() { var startLoading = function() {
disconnectTimeout = setTimeout(disconnect, 3000); disconnectTimeout = setTimeout(disconnect, 3000);
}; };
var endLoading = function() { var endLoading = function() {
clearTimeout(disconnectTimeout); clearTimeout(disconnectTimeout);
}; };
var disconnect = function() { var disconnect = function() {
plugin.disconnect(); plugin.disconnect();
}; };
// interface provided to the plugin // interface provided to the plugin
var api = { var api = {
output: function(data) { output: function(data) {
endLoading(); endLoading();
//print('input', data.input); // print('input', data.input);
if (data.error) {
print('Error', data); if (data.error) {
reset(); print('Error', data);
} else { reset();
print(null, data); } else {
reset(); print(null, data);
} reset();
} }
}
}; };
// obtaining absolute path of this script // obtaining absolute path of this script
var scripts = document.getElementsByTagName('script'); var scripts = document.getElementsByTagName('script');
var path = scripts[scripts.length-1].src var path = scripts[scripts.length - 1].src
.split('?')[0] .split('?')[0]
.split('/') .split('/')
.slice(0, -1) .slice(0, -1)
.join('/')+'/'; .join('/') + '/';
var requests; var requests;
// (re)initializes the plugin // (re)initializes the plugin
var reset = function() { var reset = function() {
requests = 0; requests = 0;
plugin = new jailed.Plugin(path + 'plugin.js', api); plugin = new jailed.Plugin(path + 'plugin.js', api);
plugin.whenDisconnected( function() { plugin.whenDisconnected( function() {
// give some time to handle the last responce // give some time to handle the last responce
setTimeout( function() { setTimeout( function() {
endLoading(); endLoading();
console.log("resetting on fatal plugin error"); console.log('resetting on fatal plugin error');
if(challengeType === 0){
codeOutput.setValue("Sorry, your code is either too slow, has a fatal error, or contains an infinite loop."); if (challengeType === 0) {
} codeOutput.setValue(
reset(); 'Sorry, your code is either too slow, has a fatal error, ' +
}, 10); 'or contains an infinite loop.'
}); );
}
reset();
}, 10);
});
}; };
// initialize everything // initialize everything
var plugin = null; var plugin = null;