lemming.js
v1.0.0
Published
Evaluate user-input JS code (original from dtao/lemming.js)
Downloads
1
Readme
This is a published version of https://github.com/dtao/lemming.js
Lemming.js
Lemming.js is a library to evaluate user-input JavaScript source code in the background using a web worker.
Options
// relative path to lemming.js
Lemming.options.fileName = 'lemming.js';
// how much time (in milliseconds) the lemming has to run the script
Lemming.options.timeout = 3000;
// array of external scripts (e.g., 'underscore.js') to depend on
Lemming.options.scripts = [];
// whether or not the lemming should be allowed to make AJAX requests
Lemming.options.enableXHR = false;
Usage
var lemming = new Lemming('source to evaluate');
lemming.onTimeout(function() {
// if the script doesn't complete within a specified timeout
});
lemming.onResult(function(result) {
// the result of evaluating the script, assuming it runs to completion
});
lemming.onError(function(error) {
// the error thrown by the script, if applicable
});
lemming.onCompleted(function() {
// a catch-all callback to run whether the script times out, throws, or finishes successfully
});
lemming.run({
// options to override Lemming.options
});