Deprecation notice: This project is no longer actively maintained because we're moving language sandboxes to the server for a faster, complete, and up-to-date implementations. You can use our API.
A sandboxed polyglot browser REPL.
JavaScript Variants
Esoteric
Classic
Serious
curl http://npmjs.org/install.sh | sh
Using npm :
sudo npm install -g coffee-script
Using npm :
sudo npm install -g uglify-js
git clone git://github.com/replit/jsrepl.git
git submodule update --init --recursive
cake bake
Include the built jsrepl script with the id "jsrepl-script".
<script src="https://github.com/replit-archive/jsrepl/raw/master/jsrepl.js" id="jsrepl-script"></script>
var jsrepl = new JSREPL({
input: inputCallback,
output: outputCallback,
result: resultCallback,
error: errorCallback,
progress: progressCallback,
timeout: {
time: 30000,
callback: timeoutCallback
}
});
inputCallback
: A callback function that is called when the language interpreteroutputCallback
: An optional callback function that is called when the engineresultCallback
: An optional callback function that is called when the interpretererrorCallback
: An optional callback function that is called if evaluatiing aprogress
: An optional callback function that is called repeatedly while loadingtimeout
: Sets a timeout for running a program.
time
: Milliseconds to wait. callback
: The callback function that is called when a program times out. Thistrue
to stop the timeout from firing again. Loads a language interpreter. Takes three arguments:
Example:
jsrepl.loadLanguage('python', function () {
alert('Python loaded');
});
Evaluates a program in the currently loaded language interpreter. Takes one argument:
Example:
jsrepl.eval('1+1');
Returns the configuration object for a given language. Takes one argument:
Given a command, decides whether it is ready for execution, as opposed to being
unfinished, such as missing a closing brace.
Attaches a listener to one or more events. Takes two arguments:
Detaches a listener or all listeners to one or more events. Arguments:
Attaches a listener to one or more events that will only be called once. Arguments:
Fired when the current language interpreter asks for input.
Arguments:
Fired each time the current language interpreter has output to standard out.
Arguments:
Fired when the language interpreter has a result from the latest eval.
Arguments:
Fired when the language interpreter has an error from the latest eval.
Arguments:
Fired when JSREPL has load progress percentage from loading a language
interpreter to report.
Arguments:
If JSREPL was instantiated with the timeout
option that includes the time
to wait on a running program before calling the specified callback (see
Instantiating JSREPL) and firing this event.
Fired when a language is loaded and is ready to eval.
Language interpreters that are compiled with Emscripten expect input to be
to be a blocking call (synchronous). The only way to get blocking input
prompts in browsers is by using window.prompt
. While suboptimal, it
works. However, that way we lose the ability to load interpreters in Web
Workers (because Workers have no access to dialog boxes).
Loading interpreters in workers has many benefits including not blocking
the main UI thread while the interpreter is intializing or working and the
ability to catch infinite loops (see timeout event). Despite these
advantages, until recently we avoided Workers in order to support input,
so we loaded languages which expect blocking input calls in an iframe
instead of a web worker. However in recent builds of Firefox and Chrome
that approach was broken for us because we could no longer do synchronous
binary XHRs, e.g. to read library files.
In WebKit-based browsers, we have leveraged the non-standard Web SQL Database
to share resources between the main thread and the worker thread, as they
provide a synchronization mechanism that can be accessed from both the main
page thread and from a worker. (See repl.coffee and sandbox.js).
Unfortunately we couldn't do the same in Firefox, as it does not implement Web
SQL, and still does not support the standard IndexedDB Sync API. Instead, we
have used XHR to synchronously communicate between the worker and the main
thread using our server as a crude proxy. There is a sample server
implementation in the repl.it static server.
jsREPL is available under the MIT license. Language interpreters and the
modifications done to them by jsREPL developers have their own licenses, found
in their extern/{language}
folders or submodules.