1
0
Fork 0

Merge branch 'devel' of github.com:triAGENS/ArangoDB into devel

This commit is contained in:
Michael Hackstein 2013-05-17 15:26:59 +02:00
commit 9cd77a7829
8 changed files with 56 additions and 11 deletions

View File

@ -832,7 +832,7 @@ static v8::Handle<v8::Value> JS_ExecuteGlobalContextFunction (v8::Arguments cons
v8::String::Utf8Value utf8def(argv[0]);
if (*utf8def == 0) {
TRI_V8_TYPE_ERROR(scope, "<defition> must be a UTF-8 function definition");
TRI_V8_TYPE_ERROR(scope, "<definition> must be a UTF-8 function definition");
}
string def = *utf8def;

View File

@ -171,8 +171,6 @@ static void UnlinkHeader (TRI_headers_t* h,
TRI_doc_mptr_t* header) {
simple_headers_t* headers = (simple_headers_t*) h;
//printf("UNLINK\n-------------\n");
//h->dump(h);
TRI_ASSERT_MAINTAINER(header != NULL);
TRI_ASSERT_MAINTAINER(header->_prev != header);
TRI_ASSERT_MAINTAINER(header->_next != header);

View File

@ -247,7 +247,7 @@ var unregisterFunctionsGroup = function (group) {
/// @fn JSF_aqlfunctions_register
/// @brief register an AQL user function
///
/// @FUN{aqlfunctions.register(@FA{name}, @FA{code})}
/// @FUN{aqlfunctions.register(@FA{name}, @FA{code}, @FA{isDeterministic}, @FA{testValues})}
///
/// Registers an AQL user function, identified by a fully qualified function
/// name. The function code in @FA{code} must be specified as a Javascript
@ -256,6 +256,11 @@ var unregisterFunctionsGroup = function (group) {
/// If a function identified by @FA{name} already exists, the previous function
/// definition will be updated.
///
/// The @FA{isDeterministic} attribute can be used to specify whether the
/// function results are fully deterministic (i.e. depend solely on the input
/// and are the same for repeated calls with the same input values). It is not
/// used at the moment but may be used for optimisations later.
///
/// @EXAMPLES
///
/// @code
@ -269,15 +274,27 @@ var unregisterFunctionsGroup = function (group) {
var registerFunction = function (name, code, isDeterministic) {
// validate input
validateName(name);
code = stringifyFunction(code, name);
var testCode = "(function() { var callback = " + code + "; return callback; })()";
try {
var res = INTERNAL.executeScript(testCode, undefined, "(user function " + name + ")");
}
catch (err1) {
var err = new ArangoError();
err.errorNum = arangodb.errors.ERROR_QUERY_FUNCTION_INVALID_CODE.code;
err.errorMessage = arangodb.errors.ERROR_QUERY_FUNCTION_INVALID_CODE.message;
}
var exists = false;
try {
unregisterFunction(name);
exists = true;
}
catch (err) {
catch (err2) {
}
var data = {

View File

@ -87,6 +87,12 @@ function GET_api_aqlfunction (req, res) {
/// - `name`: the fully qualified name of the user functions.
///
/// - `code`: a string representation of the function body.
///
/// - `isDeterministic`: an optional boolean value to indicate that the function
/// results are fully deterministic (function return value solely depends on
/// the input value and return value is the same for repeated calls with same
/// input). The `isDeterministic` attribute is currently not used but may be
/// used later for optimisations.
///
/// If the function can be registered by the server, the server will respond with
/// `HTTP 201`. If the function already existed and was replaced by the
@ -125,7 +131,7 @@ function POST_api_aqlfunction (req, res) {
return;
}
var result = aqlfunctions.register(json.name, json.code);
var result = aqlfunctions.register(json.name, json.code, json.isDeterministic);
actions.resultOk(req, res, result ? actions.HTTP_OK : actions.HTTP_CREATED, { });
}

View File

@ -246,7 +246,7 @@ var unregisterFunctionsGroup = function (group) {
/// @fn JSF_aqlfunctions_register
/// @brief register an AQL user function
///
/// @FUN{aqlfunctions.register(@FA{name}, @FA{code})}
/// @FUN{aqlfunctions.register(@FA{name}, @FA{code}, @FA{isDeterministic})}
///
/// Registers an AQL user function, identified by a fully qualified function
/// name. The function code in @FA{code} must be specified as a Javascript
@ -255,6 +255,11 @@ var unregisterFunctionsGroup = function (group) {
/// If a function identified by @FA{name} already exists, the previous function
/// definition will be updated.
///
/// The @FA{isDeterministic} attribute can be used to specify whether the
/// function results are fully deterministic (i.e. depend solely on the input
/// and are the same for repeated calls with the same input values). It is not
/// used at the moment but may be used for optimisations later.
///
/// @EXAMPLES
///
/// @code
@ -268,15 +273,27 @@ var unregisterFunctionsGroup = function (group) {
var registerFunction = function (name, code, isDeterministic) {
// validate input
validateName(name);
code = stringifyFunction(code, name);
var testCode = "(function() { var callback = " + code + "; return callback; })()";
try {
var res = internal.executeScript(testCode, undefined, "(user function " + name + ")");
}
catch (err1) {
var err = new ArangoError();
err.errorNum = arangodb.errors.ERROR_QUERY_FUNCTION_INVALID_CODE.code;
err.errorMessage = arangodb.errors.ERROR_QUERY_FUNCTION_INVALID_CODE.message;
}
var exists = false;
try {
unregisterFunction(name);
exists = true;
}
catch (err) {
catch (err2) {
}
var data = {

View File

@ -185,7 +185,7 @@
}
else {
internal.reloadAqlFunctions = function () {
internal.executeGlobalContextFunction("require(\"org/arangodb/ahuacatl\").reload();");
internal.executeGlobalContextFunction("try { require(\"org/arangodb/ahuacatl\").reload(); } catch (err) { }");
require("org/arangodb/ahuacatl").reload();
};
}

View File

@ -3424,10 +3424,13 @@ function reloadUserFunctions () {
UserFunctions = { };
c = INTERNAL.db._collection("_aqlfunctions");
if (c === null) {
return;
}
var foundError = false;
c.toArray().forEach(function (f) {
var code;
@ -3444,9 +3447,13 @@ function reloadUserFunctions () {
}
catch (err) {
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_INVALID_CODE);
foundError = true;
}
});
if (foundError) {
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_INVALID_CODE);
}
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -66,7 +66,7 @@ static void WritePidFile (string const& pidFile, int pid) {
ofstream out(pidFile.c_str(), ios::trunc);
if (! out) {
LOGGER_FATAL_AND_EXIT("cannot write pid-file \"" << pidFile << "\"\n");
LOGGER_FATAL_AND_EXIT("cannot write pid-file \"" << pidFile << "\"");
}
out << pid;