Last active
August 29, 2015 13:56
-
-
Save justinvdm/8954053 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/vumi/application/sandboxer.js b/vumi/application/sandboxer.js | |
index 8b89904..4e997a8 100644 | |
--- a/vumi/application/sandboxer.js | |
+++ b/vumi/application/sandboxer.js | |
@@ -11,14 +11,14 @@ var SandboxApi = function () { | |
self.next_id = function () { | |
self.id += 1; | |
return self.id.toString(); | |
- } | |
+ }; | |
self.populate_command = function (command, msg) { | |
msg.cmd = command; | |
msg.reply = false; | |
msg.cmd_id = self.next_id(); | |
return msg; | |
- } | |
+ }; | |
self.request = function (command, msg, callback) { | |
// * callback is optional and is called once a reply to | |
@@ -31,27 +31,27 @@ var SandboxApi = function () { | |
msg._callback = callback; | |
} | |
self.waiting_requests.push(msg); | |
- } | |
+ }; | |
self.pop_requests = function () { | |
var requests = self.waiting_requests.splice(0, | |
self.waiting_requests.length); | |
return requests; | |
- } | |
+ }; | |
self.log_info = function (msg, callback) { | |
self.request('log.info', {'msg': msg}, callback); | |
- } | |
+ }; | |
self.done = function () { | |
self.request('log.info', {'_last': true, 'msg': "Done."}); | |
- } | |
+ }; | |
// handlers: | |
// * on_unknown_command is the default message handler | |
// * other handlers are looked up based on the command name | |
- self.on_unknown_command = function(command) {} | |
-} | |
+ self.on_unknown_command = function(command) {}; | |
+}; | |
var SandboxRunner = function (api) { | |
// Runner for a sandboxed app | |
@@ -90,9 +90,10 @@ var SandboxRunner = function (api) { | |
self.load_code = function (command) { | |
self.log("Loading sandboxed code ..."); | |
var ctxt; | |
- var loaded_module = vm.createScript(command['javascript']); | |
- if (command['app_context']) { | |
- eval("ctxt = " + command['app_context'] + ";"); | |
+ var loaded_module = vm.createScript(command.javascript); | |
+ if (command.app_context) { | |
+ // TODO use vm stuff instead of eval | |
+ eval("ctxt = " + command.app_context + ";"); // jshint ignore:line | |
} else { | |
ctxt = {}; | |
} | |
@@ -101,7 +102,7 @@ var SandboxRunner = function (api) { | |
self.loaded = true; | |
// process any requests created when the app module was loaded. | |
self.process_requests(api.pop_requests()); | |
- } | |
+ }; | |
self.process_requests = function (requests) { | |
requests.forEach(function (msg) { | |
@@ -117,17 +118,17 @@ var SandboxRunner = function (api) { | |
self.pending_requests[msg.cmd_id] = {'callback': callback}; | |
} | |
}); | |
- } | |
+ }; | |
self.send_command = function (cmd) { | |
process.stdout.write(JSON.stringify(cmd)); | |
process.stdout.write("\n"); | |
- } | |
+ }; | |
self.log = function(msg) { | |
var cmd = self.api.populate_command("log.info", {"msg": msg}); | |
self.send_command(cmd); | |
- } | |
+ }; | |
self.data_from_stdin = function (data) { | |
var parts = data.split("\n"); | |
@@ -150,14 +151,14 @@ var SandboxRunner = function (api) { | |
} | |
} | |
self.chunk = parts[parts.length - 1]; | |
- } | |
+ }; | |
self.run = function () { | |
process.stdin.resume(); | |
process.stdin.setEncoding('ascii'); | |
process.stdin.on('data', function(data) { | |
self.data_from_stdin(data); }); | |
- } | |
+ }; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍