Newer
Older
const fs = require("fs"),
path = require("path"),
vm = require("vm"),
noop = require(path.join(__dirname, "noop.js")),
events = /^(error|message)$/;
var __worker_evaluated_function_ = null;
eval("__worker_evaluated_function_ = (" + arg + ")"); // eslint-disable-line no-eval
const exp = obj.isfn ? toFunction(obj.input) : fs.readFileSync(obj.input, "utf8");
process.exit(0);
},
process.send(JSON.stringify({data: msg}, null, 0));
onerror: err => {
process.send(JSON.stringify({error: err.message, stack: err.stack}, null, 0));
},
if (events.test(event)) {
global["on" + event] = global.self["on" + event] = fn;
}
global.__dirname = obj.cwd;
global.__filename = __filename;
Jason Mulligan
committed
global.require = require;
vm.createScript(files.map(file => fs.readFileSync(file, "utf8")).join("\n")).runInThisContext();
Object.keys(global.self).forEach(key => {
try {
(global.onmessage || global.self.onmessage || noop)(JSON.parse(msg));
} catch (err) {
(global.onerror || global.self.onerror || noop)(err);
}
(global.onerror || global.self.onerror || noop)(err);
});
if (typeof exp === "function") {
exp();
} else {
Jason Mulligan
committed
vm.createScript(exp).runInThisContext();