Add new currying challenge to bonfires and allow inspectlet through protective helmet

This commit is contained in:
terakilobyte
2015-04-14 23:04:54 -04:00
parent be00c7e402
commit 9c67d4988f
7 changed files with 114 additions and 88 deletions

4
app.js
View File

@ -158,7 +158,9 @@ var trusted = [
'wss://hub.togetherjs.com', 'wss://hub.togetherjs.com',
'*.ytimg.com', '*.ytimg.com',
'wss://fcctogether.herokuapp.com', 'wss://fcctogether.herokuapp.com',
'*.bitly.com' '*.bitly.com',
'http://cdn.inspectlet.com/',
'http://hn.inspectlet.com/'
]; ];
app.use(helmet.contentSecurityPolicy({ app.use(helmet.contentSecurityPolicy({

View File

@ -67,7 +67,7 @@ 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_v0.1.4.js', api); plugin = new jailed.Plugin(path+'plugin_v0.1.5.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() {

View File

@ -1,82 +0,0 @@
// executes the given code and handles the result
var run = function(code) {
var result = {
input: code,
output: null,
error: null,
type: null
};
try {
var codeExec = runHidden(code);
result.type = typeof codeExec;
result.output = stringify(codeExec);
} catch(e) {
result.error = e.message;
}
application.remote.output(result);
self.close();
};
// protects even the worker scope from being accessed
var runHidden = function(code) {
var importScript = function(url) {
var error = null;
try {
importScripts(url);
} catch (e) {
error = e;
console.log('Unable to load ramda!');
}
};
var indexedDB = null;
var location = null;
var navigator = null;
var onerror = null;
var onmessage = null;
var performance = null;
var self = null;
var webkitIndexedDB = null;
var postMessage = null;
var close = null;
var openDatabase = null;
var openDatabaseSync = null;
var webkitRequestFileSystem = null;
var webkitRequestFileSystemSync = null;
var webkitResolveLocalFileSystemSyncURL = null;
var webkitResolveLocalFileSystemURL = null;
var addEventListener = null;
var dispatchEvent = null;
var removeEventListener = null;
var dump = null;
var onoffline = null;
var ononline = null;
importScript("https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js");
var _ = R;
return eval(code);
}
// converts the output into a string
var stringify = function(output) {
var result;
if (typeof output == 'undefined') {
result = 'undefined';
} else if (output === null) {
result = 'null';
} else {
result = JSON.stringify(output) || output.toString();
}
return result;
}
application.setInterface({run:run});

View File

@ -0,0 +1,88 @@
// executes the given code and handles the result
var run = function(code) {
var result = {
input: code,
output: null,
error: null,
type: null
};
try {
var codeExec = runHidden(code);
result.type = typeof codeExec;
result.output = stringify(codeExec);
} catch(e) {
result.error = e.message;
}
application.remote.output(result);
self.close();
};
// protects even the worker scope from being accessed
var runHidden = function(code) {
var importScript = function(url) {
var error = null;
try {
importScripts(url);
} catch (e) {
error = e;
console.log('Unable to load %s!', url);
}
};
var indexedDB = null;
var location = null;
var navigator = null;
var onerror = null;
var onmessage = null;
var performance = null;
var self = null;
var webkitIndexedDB = null;
var postMessage = null;
var close = null;
var openDatabase = null;
var openDatabaseSync = null;
var webkitRequestFileSystem = null;
var webkitRequestFileSystemSync = null;
var webkitResolveLocalFileSystemSyncURL = null;
var webkitResolveLocalFileSystemURL = null;
var addEventListener = null;
var dispatchEvent = null;
var removeEventListener = null;
var dump = null;
var onoffline = null;
var ononline = null;
importScripts(
"https://cdnjs.cloudflare.com/ajax/libs/ramda/0.13.0/ramda.min.js");
importScripts(
"https://cdnjs.cloudflare.com/ajax/libs/chai/2.2.0/chai.min.js"
)
var expect = chai.expect;
var assert = chai.assert;
return eval(code);
}
// converts the output into a string
var stringify = function(output) {
var result;
if (typeof output == 'undefined') {
result = 'undefined';
} else if (output === null) {
result = 'null';
} else {
result = JSON.stringify(output) || output.toString();
}
return result;
}
application.setInterface({run:run});

View File

@ -14,6 +14,7 @@ var links =
"Global String Object" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String", "Global String Object" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String",
"Boolean Objects" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean", "Boolean Objects" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean",
"RegExp" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp", "RegExp" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp",
"Global Function Object": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function",
"Arguments object" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments", "Arguments object" : "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments",
// ========= PROPERTIES/MISC // ========= PROPERTIES/MISC

View File

@ -562,6 +562,23 @@
], ],
"MDNlinks" : ["Object.hasOwnProperty()", "Object.getOwnPropertyNames()"] "MDNlinks" : ["Object.hasOwnProperty()", "Object.getOwnPropertyNames()"]
}, },
{
"_id": "a97fd23d9b809dac9921074f",
"name": "Arguments Optional",
"difficulty": "2.22",
"description": [
"Create a function that sums two arguments together. If only one argument is provided, return a function that expects one additional argument and will return the sum.",
"For example, add(2, 3) should return 5, and add(2) should return a function that is waiting for an argument so that <code>var sum2And = add(2); return sum2And(3); // 5</code>",
"If either argument isn't a valid numbers, return undefined"
],
"challengeSeed": "function add() {\n return false;\n}\n\nadd(2,3);",
"tests": [
"expect(add(2, 3)).to.equal(5);",
"expect(add(2)(3)).to.equal(5);",
"expect(add('http://bit.ly/IqT6zt')).to.be.undefined;"
],
"MDNlinks": ["Global Function Object", "Arguments object"]
},
{ {
"_id": "a2f1d72d9b908d0bd72bb9f6", "_id": "a2f1d72d9b908d0bd72bb9f6",
"name": "Make a Person", "name": "Make a Person",

View File

@ -15,7 +15,7 @@ block content
script(src='/js/lib/codemirror/mode/javascript/javascript.js') script(src='/js/lib/codemirror/mode/javascript/javascript.js')
script(src='/js/lib/jailed/jailed.js') script(src='/js/lib/jailed/jailed.js')
script(src='/js/lib/bonfire/bonfireInit.js') script(src='/js/lib/bonfire/bonfireInit.js')
script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js") script(src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.13.0/ramda.min.js")
.row .row