-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjsrepl.js
More file actions
26 lines (26 loc) · 12 KB
/
jsrepl.js
File metadata and controls
26 lines (26 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
window.__BAKED_JSREPL_BUILD__ = true;
(function(){var n,k,l,o,r,p,s,t,q=[].slice,j=function(h,a){return function(){return h.apply(a,arguments)}},v={}.hasOwnProperty,u=function(h,a){function d(){this.constructor=h}for(var b in a)v.call(a,b)&&(h[b]=a[b]);d.prototype=a.prototype;h.prototype=new d;h.__super__=a.prototype;return h};k=document.getElementById("jsrepl-script");if(k!=null)n=k.src.split("/").slice(0,-1).join("/"),r=""+n+"/sandbox.html";else throw Error('JSREPL script element cannot be found. Make sure you have the ID "jsrepl-script" on it.');
o=function(){function h(){var a,d=this;a=function(){d.head=document.getElementsByTagName("head")[0];return d.body=document.getElementsByTagName("body")[0]};a();this.loadfns=[a];window.onload=function(){var b,a,e,f,g;f=d.loadfns;g=[];for(a=0,e=f.length;a<e;a++)b=f[a],g.push(b());return g};this.iframe=null}h.name="Loader";h.prototype._appendChild=function(a,d){var b,c=this;b=function(){return c[a].appendChild(d)};return this[a]!=null?b():this.loadfns.push(b)};h.prototype.createSandbox=function(a){var d=
this;this.iframe!=null&&this.body.removeChild(this.iframe);this.iframe=document.createElement("iframe");this.iframe.src=r;this.iframe.style.display="none";this.iframe.onload=function(){return a(d.iframe.contentWindow)};return this._appendChild("body",this.iframe)};return h}();k=function(){function h(){this.listeners={}}h.name="EventEmitter";h.prototype.makeArray=function(a){Object.prototype.toString.call(a)!=="[object Array]"&&(a=[a]);return a};h.prototype.on=function(a,d){var b,c,e,f;if(typeof d===
"function"){a=this.makeArray(a);f=[];for(c=0,e=a.length;c<e;c++)b=a[c],this.listeners[b]==null?f.push(this.listeners[b]=[d]):f.push(this.listeners[b].push(d));return f}};h.prototype.off=function(a,d){var b,c,e,f,g,a=this.makeArray(a);g=[];for(e=0,f=a.length;e<f;e++)b=a[e],c=this.listeners[b],c!=null&&(d!=null?(b=c.indexOf(d),b>-1?g.push(c.splice(b,1)):g.push(void 0)):g.push(this.listeners[b]=[]));return g};h.prototype.fire=function(a,d){var b,c,e,f,d=this.makeArray(d);c=this.listeners[a];if(c!=null){d.push(a);
var g;g=[];for(e=0,f=c.length;e<f;e++)b=c[e],g.push(b);f=[];for(c=0,e=g.length;c<e;c++)b=g[c],f.push(b.apply(this,d));return f}};h.prototype.once=function(a,d){var b,c,e,f,g,h=this,a=this.makeArray(a);b=function(){var c,e,g,f;c=1<=arguments.length?q.call(arguments,0):[];for(g=0,f=a.length;g<f;g++)e=a[g],h.off(e,b);return d.apply(null,c)};g=[];for(e=0,f=a.length;e<f;e++)c=a[e],g.push(this.on(c,b));return g};return h}();t="Worker"in window;p=function(h){function a(a,b,c){var e;this.input_server=b;c==
null&&(c={});this.onmsg=j(this.onmsg,this);var f,g,h;h=[];for(f=0,g=a.length;f<g;f++)b=a[f],h.push(n+"/"+b);this.baseScripts=h;this.loader=new o;for(e in c)a=c[e],typeof a==="function"&&(c[e]=[a]);this.listeners=c}u(a,h);a.name="Sandbox";a.prototype.onmsg=function(a){var b;try{return b=JSON.parse(a.data),this.fire(b.type,[b.data])}catch(c){}};a.prototype.load=function(a,b){var c,e,f,g=this;b==null&&(b=true);c=this.baseScripts.concat(a);e=c.shift();this.worker!=null&&this.kill();f=function(){g.post({type:"importScripts",
data:c});if(g.input_server!=null)return g.post({type:"set_input_server",data:g.input_server})};window.removeEventListener("message",this.onmsg,false);return!t||!b?this.loader.createSandbox(function(a){g.worker=a;g.workerIsIframe=true;window.addEventListener("message",g.onmsg,false);return f()}):(this.worker=new Worker(e),this.workerIsIframe=false,this.worker.addEventListener("message",this.onmsg,false),f())};a.prototype.post=function(a){a=JSON.stringify(a);return this.workerIsIframe?this.worker.postMessage(a,
"*"):this.worker.postMessage(a)};a.prototype.kill=function(){var a;typeof(a=this.worker).terminate==="function"&&a.terminate();if(this.loader.body!=null&&this.loader.iframe)return this.loader.body.removeChild(this.loader.iframe),delete this.loader.iframe};return a}(k);s=function(){var h,a,d;h={firefox_3:/firefox\/3/i,opera:/opera/i,chrome:/chrome/i};for(a in h)if(d=h[a],d.test(window.navigator.userAgent))return a}();l=function(h){function a(d){var b,c,e,f,g,h,i,m=this;b=d!=null?d:{};i=b.result;d=
b.error;e=b.input;g=b.output;h=b.progress;this.timeout=b.timeout;f=b.input_server;this.getLangConfig=j(this.getLangConfig,this);this.rawEval=j(this.rawEval,this);this.eval=j(this.eval,this);this.checkLineEnd=j(this.checkLineEnd,this);this.loadLanguage=j(this.loadLanguage,this);this.off=j(this.off,this);this.on=j(this.on,this);a.__super__.constructor.call(this);window.openDatabase!=null&&(c=openDatabase("replit_input","1.0","Emscripted input",1024),c.transaction(function(a){a.executeSql("DROP TABLE IF EXISTS input");
return a.executeSql("CREATE TABLE input (text)")}));f==null&&(f={});f.input_id=Math.floor(Math.random()*9007199254740992)+1;this.lang=null;this.on("input",e);b=["sandbox.js"];window.__BAKED_JSREPL_BUILD__||(b=b.concat(["util/polyfills.js","util/mtwister.js"]));this.sandbox=new p(b,f,{output:g,input:function(){return m.fire("input",function(a){return m.sandbox.post({type:"input.write",data:a})})},error:d,result:i,progress:h,db_input:function(){return m.fire("input",function(a){m.sandbox.fire("recieved_input",
[a]);return c.transaction(function(b){return b.executeSql("INSERT INTO input (text) VALUES ('"+a+"')",[])})})},server_input:function(){return m.fire("input",function(a){var b,c;m.sandbox.fire("recieved_input",[a]);b=(f.url||"/emscripten/input/")+f.input_id;if(f.cors)if(c=new XMLHttpRequest,"withCredentials"in c)c.open("POST",b,true);else if(typeof XDomainRequest!=="undefined"&&XDomainRequest!==null)c=new XDomainRequest,c.open("POST",b);else throw Error("CORS not supported on your browser");else c=
new XMLHttpRequest,c.open("POST",b,true);return c.send("input="+a)})}})}u(a,h);a.name="JSREPL";a.prototype.on=function(d,b){var c,e,f,g,d=this.makeArray(d);g=[];for(e=0,f=d.length;e<f;e++)c=d[e],c==="input"?g.push(a.__super__.on.call(this,"input",b)):g.push(this.sandbox.on(c,b));return g};a.prototype.off=function(d,b){var c,e,f,g,d=this.makeArray(d);g=[];for(e=0,f=d.length;e<f;e++)c=d[e],c==="input"?g.push(a.__super__.off.call(this,"input",b)):g.push(this.sandbox.off(c,b));return g};a.prototype.loadLanguage=
function(d,b,c){var e,f;typeof b==="function"&&(f=[b,void 0],c=f[0],b=f[1]);if(a.prototype.Languages.prototype[d]==null)throw Error("Language "+d+" not supported.");this.current_lang_name=d;this.lang=a.prototype.Languages.prototype[d];if(c!=null)this.sandbox.once("ready",c);return this.sandbox.load(function(){var a,b,c,d;c=this.lang.scripts;d=[];for(a=0,b=c.length;a<b;a++)e=c[a],typeof e==="object"?d.push(e[s]||e["default"]):d.push(e);return d}.call(this).concat([this.lang.engine]),b)};a.prototype.checkLineEnd=
function(a,b){return/\n\s*$/.test(a)?b(false):(this.sandbox.once("indent",b),this.sandbox.post({type:"getNextLineIndent",data:a}))};a.prototype.eval=function(a,b){var c,e,f,g,h,i=this;!this.sandbox.workerIsIframe&&this.timeout!=null&&this.timeout.time&&this.timeout.callback&&(g=null,e=function(){i.sandbox.fire("timeout");return i.timeout.callback()?h():g=setTimeout(e,i.timeout.time)},g=setTimeout(e,this.timeout.time),f=function(){var a,b;2<=arguments.length?q.call(arguments,0,b=arguments.length-1):
b=0;a=arguments[b++];clearTimeout(g);if(a==="input")return i.once("recieved_input",function(){return g=setTimeout(e,i.timeout.time)}),c()},c=function(){return i.once(["result","error","input"],f)},h=function(){return i.off(["result","error","input"],f)},c());if(typeof b==="function")this.once(["result","error"],function(){var a,c,d;a=2<=arguments.length?q.call(arguments,0,d=arguments.length-1):(d=0,[]);c=arguments[d++];return c==="error"?b(a[0],null):b(null,a[0])});return this.sandbox.post({type:"engine.Eval",
data:a})};a.prototype.rawEval=function(a){return this.sandbox.post({type:"engine.RawEval",data:a})};a.prototype.getLangConfig=function(d){return a.prototype.Languages.prototype[d||this.current_lang_name]||null};return a}(k);l.prototype.Languages=function(){function h(){}h.name="Languages";return h}();l.prototype.__test__=function(){function h(){}h.name="__test__";return h}();l.prototype.__test__.prototype.Loader=o;l.prototype.__test__.prototype.EventEmitter=k;l.prototype.__test__.prototype.Sandbox=
p;this.JSREPL=l}).call(this);
JSREPL.prototype.Languages.prototype={qbasic:{system_name:"qbasic",name:"Quick Basic",extension:"bas",matchings:[],scripts:[{"default":["engines/qbasic-default.js"]}],includes:[],engine:"langs/qbasic/jsrepl_qbasic.js",minifier:"closure"},scheme:{system_name:"scheme",name:"Scheme",extension:"scm",matchings:[["(",")"],["[","]"]],scripts:[{"default":["engines/scheme-default.js"]}],includes:[],engine:"langs/scheme/jsrepl_scheme.js",minifier:"yui"},javascript:{system_name:"javascript",name:"JavaScript",
extension:"js",matchings:[["(",")"],["[","]"],["{","}"]],scripts:[{"default":["engines/javascript-default.js"]}],includes:[],engine:"langs/javascript/jsrepl_js.js",minifier:"closure"},coffeescript:{system_name:"coffeescript",name:"CoffeeScript",extension:"coffee",matchings:[["(",")"],["[","]"],["{","}"]],scripts:[{"default":["engines/coffeescript-default.js"]}],includes:[],engine:"langs/coffee-script/jsrepl_coffee.js",minifier:"closure"},brainfuck:{system_name:"brainfuck",name:"Brainfuck",extension:"bf",
matchings:[["[","]"]],scripts:[{"default":["engines/brainfuck-default.js"]}],includes:[],engine:"langs/brainfuck/jsrepl_brainfuck.js",minifier:"closure"},unlambda:{system_name:"unlambda",name:"Unlambda",extension:"unl",matchings:[],scripts:[{"default":["engines/unlambda-default.js"]}],includes:[],engine:"langs/unlambda/jsrepl_unlambda.js",minifier:"closure"},lolcode:{system_name:"lolcode",name:"LOLCODE",extension:"lol",matchings:[],scripts:[{"default":["engines/lolcode-default.js"]}],includes:[],
engine:"langs/lolcode/jsrepl_lolcode.js",minifier:"closure"},kaffeine:{system_name:"kaffeine",name:"Kaffeine",extension:"k",matchings:[["(",")"],["[","]"],["{","}"]],scripts:[{"default":["engines/kaffeine-default.js"]}],includes:[],engine:"langs/kaffeine/jsrepl_kaffeine.js",minifier:"closure"},move:{system_name:"move",name:"Move",extension:"mv",matchings:[["(",")"],["[","]"],["{","}"]],scripts:[{"default":["engines/move-default.js"]}],includes:[],engine:"langs/move/jsrepl_move.js",minifier:"closure"},
traceur:{system_name:"traceur",name:"Traceur",extension:"js",matchings:[["(",")"],["[","]"],["{","}"]],scripts:[{"default":["engines/traceur-default.js"]}],includes:[],engine:"langs/traceur/jsrepl_traceur.js",minifier:"closure_es5"},emoticon:{system_name:"emoticon",name:"Emoticon",extension:"emo",matchings:[["(",")"]],scripts:[{"default":["engines/emoticon-default.js"]}],includes:[],engine:"langs/emoticon/jsrepl_emoticon.js",minifier:"closure"},bloop:{system_name:"bloop",name:"Bloop/Floop",extensions:"bloop",
matchings:[],scripts:[{"default":["engines/bloop-default.js"]}],includes:[],engine:"langs/bloop/jsrepl_bloop.js",minifier:"closure"},forth:{system_name:"forth",name:"Forth",extensions:"4th",matchings:[["(",")"],[":",";"]],scripts:[{"default":["engines/forth-default.js"]}],includes:[],engine:"langs/forth/jsrepl_forth.js",minifier:"closure"},lua:{system_name:"lua",name:"Lua",extension:"lua",matchings:[["(",")"],["[","]"],["{","}"]],scripts:[{"default":["engines/lua-default.js"]}],includes:[],engine:"langs/lua/jsrepl_lua.js",
minifier:"none",emscripted:true},python:{system_name:"python",name:"Python",extension:"py",matchings:[["(",")"],["[","]"],["{","}"]],scripts:[{chrome:["engines/python-chrome.js"],opera:["engines/python-opera.js"],"default":["engines/python-default.js"]}],includes:["extern/python/unclosured","extern/python/closured","extern/python/reloop-closured"],engine:"langs/python/jsrepl_python.js",minifier:"none",emscripted:true},ruby:{system_name:"ruby",name:"Ruby",extension:"rb",matchings:[["(",")"],["[","]"],
["{","}"]],scripts:[{opera:["engines/ruby-opera.js"],firefox_3:["engines/ruby-firefox_3.js"],"default":["engines/ruby-default.js"]}],includes:["extern/ruby/dist/lib"],engine:"langs/ruby/jsrepl_ruby.js",minifier:"none",emscripted:true},roy:{system_name:"roy",name:"Roy",extension:"roy",matchings:[["(",")"],["[","]"],["{","}"]],scripts:[{"default":["engines/roy-default.js"]}],includes:[],engine:"langs/roy/jsrepl_roy.js",minifier:"closure"}};