Comparing version 0.4.1 to 0.4.2
(function() { | ||
var Promise = require("bluebird"); | ||
var self = this; | ||
var serverRequire; | ||
var serverRequire, pogoWrappers; | ||
serverRequire = function(path) { | ||
@@ -11,2 +11,5 @@ if (path[0] === ".") { | ||
}; | ||
pogoWrappers = function() { | ||
return "\n //TODO it would be nice if we could just get these from pogo\n var gen1_promisify = function(fn) {\n return new Promise(function(onFulfilled, onRejected) {\n fn(function(error, result) {\n if (error) {\n onRejected(error);\n } else {\n onFulfilled(result);\n }\n });\n });\n };\n\n var gen2_asyncFor = function(test, incr, loop) {\n return new Promise(function(success, failure) {\n function testAndLoop(loopResult) {\n Promise.resolve(test()).then(function(testResult) {\n if (testResult) {\n Promise.resolve(loop()).then(incrTestAndLoop, failure);\n } else {\n success(loopResult);\n }\n }, failure);\n }\n function incrTestAndLoop(loopResult) {\n Promise.resolve(incr()).then(function() {\n testAndLoop(loopResult);\n }, failure);\n }\n testAndLoop();\n });\n };"; | ||
}; | ||
module.exports = function(port) { | ||
@@ -33,11 +36,17 @@ var self = this; | ||
runWithPromise = function(options) { | ||
options.context.Promise = require("bluebird"); | ||
options.context.gen1_promisify = function(callback) { | ||
var self = this; | ||
return callback(function(error, result) { | ||
return emitResult(options, result); | ||
return convertErrorToEmit(options, function() { | ||
var func, context, runFunc, gen3_asyncResult, result; | ||
return new Promise(function(gen2_onFulfilled) { | ||
func = options.func; | ||
context = options.context; | ||
context.Promise = require("bluebird"); | ||
context.process = process; | ||
context.require = require; | ||
context.serverRequire = serverRequire; | ||
runFunc = Function("context", "callback", "\n for (var property in context) {\n eval ('var '+property+'= context.'+property);\n }\n\n " + pogoWrappers() + "\n\n return (" + func + ")();\n "); | ||
gen2_onFulfilled(Promise.resolve(runFunc(context)).then(function(gen3_asyncResult) { | ||
result = gen3_asyncResult; | ||
return emitResult(options, result); | ||
})); | ||
}); | ||
}; | ||
return convertErrorToEmit(options, function() { | ||
return exec(options.context, options.func); | ||
}); | ||
@@ -70,15 +79,19 @@ }; | ||
socket.on("runTask", function(options) { | ||
var context, runFunc, result; | ||
context = options.context; | ||
context.Promise = require("bluebird"); | ||
context.process = process; | ||
context.require = require; | ||
context.serverRequire = serverRequire; | ||
runFunc = Function("context", "\n for (var property in context) {\n eval ('var '+property+'= context.'+property);\n }\n\n // in a task we just need to swallow root level promises that complete\n var gen1_promisify = function(fn) {\n return new Promise(function(onFulfilled, onRejected) {\n fn(function(error, result) {\n if (error) {\n onRejected(error);\n } else {\n onFulfilled(result);\n }\n });\n });\n };\n\n return (" + options.func + ")();\n "); | ||
result = runFunc(context); | ||
tasks.push({ | ||
id: options.id, | ||
stop: result.stop | ||
var context, runFunc, gen4_asyncResult, result; | ||
return new Promise(function(gen2_onFulfilled) { | ||
context = options.context; | ||
context.Promise = require("bluebird"); | ||
context.process = process; | ||
context.require = require; | ||
context.serverRequire = serverRequire; | ||
runFunc = Function("context", "\n for (var property in context) {\n eval ('var '+property+'= context.'+property);\n }\n\n " + pogoWrappers() + "\n\n return (" + options.func + ")();\n "); | ||
gen2_onFulfilled(Promise.resolve(runFunc(context)).then(function(gen4_asyncResult) { | ||
result = gen4_asyncResult; | ||
tasks.push({ | ||
id: options.id, | ||
stop: result.stop | ||
}); | ||
return socket.emit("running:" + options.id, result); | ||
})); | ||
}); | ||
return socket.emit("running:" + options.id, result); | ||
}); | ||
@@ -99,14 +112,14 @@ socket.on("run", function(options) { | ||
runningTask = function() { | ||
var gen3_results, gen4_items, gen5_i, task; | ||
gen3_results = []; | ||
gen4_items = tasks; | ||
for (gen5_i = 0; gen5_i < gen4_items.length; ++gen5_i) { | ||
task = gen4_items[gen5_i]; | ||
var gen5_results, gen6_items, gen7_i, task; | ||
gen5_results = []; | ||
gen6_items = tasks; | ||
for (gen7_i = 0; gen7_i < gen6_items.length; ++gen7_i) { | ||
task = gen6_items[gen7_i]; | ||
(function(task) { | ||
if (task.id === options.id) { | ||
return gen3_results.push(task); | ||
return gen5_results.push(task); | ||
} | ||
})(task); | ||
} | ||
return gen3_results; | ||
return gen5_results; | ||
}()[0]; | ||
@@ -113,0 +126,0 @@ if (runningTask) { |
{ | ||
"name": "censeo", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Run arbitrary JavaScript or PogoScript on a server", | ||
@@ -5,0 +5,0 @@ "author": "Derek Ekins <derek@spathi.com>", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
15635
230
5
3