mirror of https://gitee.com/bigwinds/arangodb
Simplified 'createCallbackActionCallbackString' implementation.
This commit is contained in:
parent
d39a2d241b
commit
30b19cd760
|
@ -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;
|
return foxxModule.require(path);
|
||||||
|
}
|
||||||
sandbox.require = function (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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Reference in New Issue