1
0
Fork 0

Simplified 'createCallbackActionCallbackString' implementation.

This commit is contained in:
Alan Plum 2015-06-01 12:30:26 +02:00
parent d39a2d241b
commit 30b19cd760
1 changed files with 17 additions and 29 deletions

View File

@ -127,40 +127,28 @@ function notImplementedFunction (route, message) {
function createCallbackActionCallbackString (callback, foxxModule, route) { function createCallbackActionCallbackString (callback, foxxModule, route) {
'use strict'; 'use strict';
var sandbox = {}; var args = {
var key; module: module.root,
require: function (path) {
sandbox.module = module.root;
sandbox.require = function (path) {
return foxxModule.require(path); return foxxModule.require(path);
}
}; };
var content = "(function(__myenv__) {"; var keys = Object.keys(args);
var content = "return (" + callback + ");";
var script = Function.apply(null, keys.concat(content));
var fn = internal.executeScript("(" + script + ")", undefined, route);
for (key in sandbox) { if (fn) {
if (sandbox.hasOwnProperty(key)) { return fn.apply(null, keys.map(function (key) {
content += "var " + key + " = __myenv__['" + key + "'];"; return args[key];
} }));
} }
content += "delete __myenv__;" return notImplementedFunction(route, util.format(
+ "return (" + callback + ")" "could not generate callback for '%s'",
+ "\n});"; callback
));
var func = internal.executeScript(content, undefined, route);
if (func !== undefined) {
func = func(sandbox);
}
if (func === undefined) {
func = notImplementedFunction(
route,
"could not generate callback for '" + callback + "'");
}
return func;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////