1
0
Fork 0

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

This commit is contained in:
Michael Hackstein 2014-04-24 00:44:40 +02:00
commit 258f5afd99
18 changed files with 174 additions and 90 deletions

View File

@ -345,6 +345,7 @@ examples:
@srcdir@/js/actions/*.js \ @srcdir@/js/actions/*.js \
@srcdir@/Documentation/DbaManual/*.md \ @srcdir@/Documentation/DbaManual/*.md \
@srcdir@/Documentation/UserManual/*.md \ @srcdir@/Documentation/UserManual/*.md \
@srcdir@/Documentation/ImplementorManual/*.md \
@srcdir@/arangod/RestHandler/*.cpp \ @srcdir@/arangod/RestHandler/*.cpp \
@srcdir@/lib/Admin/*.cpp \ @srcdir@/lib/Admin/*.cpp \
> /tmp/arangosh.examples > /tmp/arangosh.examples

View File

@ -169,7 +169,7 @@ PUBLIC_FUNCTION(ReadIntoSharedMem)
TCHAR * szName = SHARED_MEM_SEGMENT; TCHAR * szName = SHARED_MEM_SEGMENT;
hMapFile = OpenFileMapping( hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access FILE_MAP_WRITE, // read/write access
FALSE, // do not inherit the name FALSE, // do not inherit the name
szName); // name of mapping object szName); // name of mapping object

View File

@ -226,9 +226,6 @@ describe ArangoDB do
cmd = "/_api/job/" + id cmd = "/_api/job/" + id
doc = ArangoDB.log_put("#{prefix}-create-cursor-check-status-408", cmd) doc = ArangoDB.log_put("#{prefix}-create-cursor-check-status-408", cmd)
# TODO: sometimes this call returns HTTP 500, not 408
# TODO: remove the print statement when fail reason is known
p doc
doc.code.should eq(408) doc.code.should eq(408)
end end

View File

@ -109,7 +109,6 @@ SERVER_OPT := \
--database.maximal-journal-size 1048576 \ --database.maximal-journal-size 1048576 \
--database.force-sync-properties false \ --database.force-sync-properties false \
--javascript.app-path @top_srcdir@/js/apps \ --javascript.app-path @top_srcdir@/js/apps \
--javascript.gc-interval 1 \
--javascript.startup-directory @top_srcdir@/js \ --javascript.startup-directory @top_srcdir@/js \
--log.file "" \ --log.file "" \
--ruby.action-directory @top_srcdir@/mr/actions \ --ruby.action-directory @top_srcdir@/mr/actions \

View File

@ -665,8 +665,8 @@ static TRI_aql_node_t* OptimiseFcall (TRI_aql_context_t* const context,
TRI_js_exec_context_t* execContext; TRI_js_exec_context_t* execContext;
TRI_string_buffer_t* code; TRI_string_buffer_t* code;
TRI_json_t* json; TRI_json_t* json;
size_t i; size_t i, n;
size_t n; int res;
function = (TRI_aql_function_t*) TRI_AQL_NODE_DATA(node); function = (TRI_aql_function_t*) TRI_AQL_NODE_DATA(node);
assert(function); assert(function);
@ -697,15 +697,30 @@ static TRI_aql_node_t* OptimiseFcall (TRI_aql_context_t* const context,
// execute the function code // execute the function code
execContext = TRI_CreateExecutionContext(code->_buffer); execContext = TRI_CreateExecutionContext(code->_buffer);
TRI_FreeStringBuffer(TRI_UNKNOWN_MEM_ZONE, code); TRI_FreeStringBuffer(TRI_UNKNOWN_MEM_ZONE, code);
if (! execContext) { if (execContext == NULL) {
TRI_SetErrorContextAql(__FILE__, __LINE__, context, TRI_ERROR_OUT_OF_MEMORY, NULL); TRI_SetErrorContextAql(__FILE__, __LINE__, context, TRI_ERROR_OUT_OF_MEMORY, NULL);
return node; return node;
} }
res = TRI_GetErrorExecutionContext(execContext);
if (res != TRI_ERROR_NO_ERROR) {
TRI_FreeExecutionContext(execContext);
TRI_SetErrorContextAql(__FILE__, __LINE__, context, res, NULL);
return node;
}
json = TRI_ExecuteResultContext(execContext); json = TRI_ExecuteResultContext(execContext);
res = TRI_GetErrorExecutionContext(execContext);
TRI_FreeExecutionContext(execContext); TRI_FreeExecutionContext(execContext);
if (! json) {
if (res != TRI_ERROR_NO_ERROR) {
return node;
}
if (json == NULL) {
// cannot optimise the function call due to an internal error // cannot optimise the function call due to an internal error
// TODO: check whether we can validate the arguments here already and return an error early // TODO: check whether we can validate the arguments here already and return an error early
@ -715,7 +730,8 @@ static TRI_aql_node_t* OptimiseFcall (TRI_aql_context_t* const context,
// use the constant values instead of the function call node // use the constant values instead of the function call node
node = TRI_JsonNodeAql(context, json); node = TRI_JsonNodeAql(context, json);
if (! node) {
if (node == NULL) {
TRI_SetErrorContextAql(__FILE__, __LINE__, context, TRI_ERROR_OUT_OF_MEMORY, NULL); TRI_SetErrorContextAql(__FILE__, __LINE__, context, TRI_ERROR_OUT_OF_MEMORY, NULL);
} }
@ -1154,6 +1170,7 @@ static TRI_aql_node_t* OptimiseBinaryRelationalOperation (TRI_aql_context_t* con
TRI_string_buffer_t* code; TRI_string_buffer_t* code;
TRI_json_t* json; TRI_json_t* json;
char* func; char* func;
int res;
if (! lhs || ! TRI_IsConstantValueNodeAql(lhs) || ! rhs || ! TRI_IsConstantValueNodeAql(rhs)) { if (! lhs || ! TRI_IsConstantValueNodeAql(lhs) || ! rhs || ! TRI_IsConstantValueNodeAql(rhs)) {
return node; return node;
@ -1207,9 +1224,36 @@ static TRI_aql_node_t* OptimiseBinaryRelationalOperation (TRI_aql_context_t* con
return node; return node;
} }
// check if an error occurred during context creation
res = TRI_GetErrorExecutionContext(execContext);
if (res != TRI_ERROR_NO_ERROR) {
TRI_FreeExecutionContext(execContext);
if (res != TRI_ERROR_REQUEST_CANCELED) {
// we need to return this specific error code
res = TRI_ERROR_QUERY_SCRIPT;
}
TRI_SetErrorContextAql(__FILE__, __LINE__, context, res, NULL);
return node;
}
json = TRI_ExecuteResultContext(execContext); json = TRI_ExecuteResultContext(execContext);
res = TRI_GetErrorExecutionContext(execContext);
TRI_FreeExecutionContext(execContext); TRI_FreeExecutionContext(execContext);
if (res != TRI_ERROR_NO_ERROR) {
if (res != TRI_ERROR_REQUEST_CANCELED) {
// we need to return this specific error code
res = TRI_ERROR_QUERY_SCRIPT;
}
TRI_SetErrorContextAql(__FILE__, __LINE__, context, res, NULL);
return NULL;
}
if (json == NULL) { if (json == NULL) {
TRI_SetErrorContextAql(__FILE__, __LINE__, context, TRI_ERROR_QUERY_SCRIPT, NULL); TRI_SetErrorContextAql(__FILE__, __LINE__, context, TRI_ERROR_QUERY_SCRIPT, NULL);
return NULL; return NULL;

View File

@ -728,8 +728,7 @@ int Syncer::handleStateResponse (TRI_json_t const* json,
if (major < 1 || if (major < 1 ||
major > 2 || major > 2 ||
(major == 1 && minor < 4) || (major == 1 && minor < 4)) {
(major == 2 && minor > 0)) {
// we can connect to 1.4, 2.0 and higher only // we can connect to 1.4, 2.0 and higher only
errorMsg = "got incompatible master version" + endpointString + ": '" + versionString + "'"; errorMsg = "got incompatible master version" + endpointString + ": '" + versionString + "'";

View File

@ -857,17 +857,19 @@ int ArangoServer::startupServer () {
OperationMode::server_operation_mode_e mode = OperationMode::determineMode(_applicationServer->programOptions()); OperationMode::server_operation_mode_e mode = OperationMode::determineMode(_applicationServer->programOptions());
int res;
if (mode == OperationMode::MODE_CONSOLE) { if (mode == OperationMode::MODE_CONSOLE) {
runConsole(vocbase); res = runConsole(vocbase);
} }
else if (mode == OperationMode::MODE_UNITTESTS) { else if (mode == OperationMode::MODE_UNITTESTS) {
runUnitTests(vocbase); res = runUnitTests(vocbase);
} }
else if (mode == OperationMode::MODE_SCRIPT) { else if (mode == OperationMode::MODE_SCRIPT) {
runScript(vocbase); res = runScript(vocbase);
} }
else { else {
runServer(vocbase); res = runServer(vocbase);
} }
_applicationServer->stop(); _applicationServer->stop();
@ -878,7 +880,7 @@ int ArangoServer::startupServer () {
cout << endl << TRI_BYE_MESSAGE << endl; cout << endl << TRI_BYE_MESSAGE << endl;
} }
return 0; return res;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -890,7 +892,6 @@ int ArangoServer::startupServer () {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int ArangoServer::runServer (TRI_vocbase_t* vocbase) { int ArangoServer::runServer (TRI_vocbase_t* vocbase) {
// just wait until we are signalled // just wait until we are signalled
_applicationServer->wait(); _applicationServer->wait();

View File

@ -935,7 +935,7 @@ int main (int argc, char* argv[]) {
int minor = 0; int minor = 0;
if (sscanf(versionString.c_str(), "%d.%d", &major, &minor) != 2) { if (sscanf(versionString.c_str(), "%d.%d", &major, &minor) != 2) {
cerr << "Invalid server version '" << versionString << "'" << endl; cerr << "invalid server version '" << versionString << "'" << endl;
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL); TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
} }
@ -943,7 +943,7 @@ int main (int argc, char* argv[]) {
major > 2 || major > 2 ||
(major == 1 && minor < 4)) { (major == 1 && minor < 4)) {
// we can connect to 1.4, 2.0 and higher only // we can connect to 1.4, 2.0 and higher only
cerr << "Got an incompatible server version '" << versionString << "'" << endl; cerr << "got incompatible server version '" << versionString << "'" << endl;
if (! Force) { if (! Force) {
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL); TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
} }

View File

@ -918,7 +918,7 @@ int main (int argc, char* argv[]) {
int minor = 0; int minor = 0;
if (sscanf(versionString.c_str(), "%d.%d", &major, &minor) != 2) { if (sscanf(versionString.c_str(), "%d.%d", &major, &minor) != 2) {
cerr << "Invalid server version '" << versionString << "'" << endl; cerr << "invalid server version '" << versionString << "'" << endl;
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL); TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
} }
@ -926,7 +926,7 @@ int main (int argc, char* argv[]) {
major > 2 || major > 2 ||
(major == 1 && minor < 4)) { (major == 1 && minor < 4)) {
// we can connect to 1.4, 2.0 and higher only // we can connect to 1.4, 2.0 and higher only
cerr << "Got an incompatible server version '" << versionString << "'" << endl; cerr << "got incompatible server version '" << versionString << "'" << endl;
if (! Force) { if (! Force) {
TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL); TRI_EXIT_FUNCTION(EXIT_FAILURE, NULL);
} }

View File

@ -138,7 +138,7 @@ actions.defineHttp({
callback : function (req, res) { callback : function (req, res) {
internal.executeGlobalContextFunction("reloadRouting"); internal.executeGlobalContextFunction("reloadRouting");
console.warn("about to flush the routing cache"); console.debug("about to flush the routing cache");
actions.resultOk(req, res, actions.HTTP_OK); actions.resultOk(req, res, actions.HTTP_OK);
} }
}); });
@ -182,7 +182,7 @@ actions.defineHttp({
callback : function (req, res) { callback : function (req, res) {
internal.executeGlobalContextFunction("flushModuleCache"); internal.executeGlobalContextFunction("flushModuleCache");
console.warn("about to flush the modules cache"); console.debug("about to flush the modules cache");
actions.resultOk(req, res, actions.HTTP_OK); actions.resultOk(req, res, actions.HTTP_OK);
} }
}); });

View File

@ -3675,7 +3675,7 @@ function SLEEP (duration) {
THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "SLEEP"); THROW(INTERNAL.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "SLEEP");
} }
INTERNAL.wait(duration); INTERNAL.sleep(duration);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -119,7 +119,6 @@ function makeTestingArgs () {
"--server.keyfile", fs.join(topDir,"UnitTests","server.pem"), "--server.keyfile", fs.join(topDir,"UnitTests","server.pem"),
"--database.maximal-journal-size", "1048576", "--database.maximal-journal-size", "1048576",
"--database.force-sync-properties", "false", "--database.force-sync-properties", "false",
"--javascript.gc-interval", "1",
"--javascript.app-path", fs.join(topDir,"js","apps"), "--javascript.app-path", fs.join(topDir,"js","apps"),
"--javascript.startup-directory", fs.join(topDir,"js"), "--javascript.startup-directory", fs.join(topDir,"js"),
"--ruby.action-directory", fs.join(topDir,"mr","actions"), "--ruby.action-directory", fs.join(topDir,"mr","actions"),

View File

@ -36,38 +36,38 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static const uint64_t Primes[251] = { static const uint64_t Primes[251] = {
7, 11, 13, 17, 19, 23, 29, 31, 7ULL, 11ULL, 13ULL, 17ULL, 19ULL, 23ULL, 29ULL, 31ULL,
37, 41, 47, 53, 59, 67, 73, 79, 37ULL, 41ULL, 47ULL, 53ULL, 59ULL, 67ULL, 73ULL, 79ULL,
89, 97, 107, 127, 137, 149, 163, 179, 89ULL, 97ULL, 107ULL, 127ULL, 137ULL, 149ULL, 163ULL, 179ULL,
193, 211, 227, 251, 271, 293, 317, 347, 193ULL, 211ULL, 227ULL, 251ULL, 271ULL, 293ULL, 317ULL, 347ULL,
373, 401, 431, 467, 503, 541, 587, 641, 373ULL, 401ULL, 431ULL, 467ULL, 503ULL, 541ULL, 587ULL, 641ULL,
691, 751, 809, 877, 947, 1019, 1097, 1181, 691ULL, 751ULL, 809ULL, 877ULL, 947ULL, 1019ULL, 1097ULL, 1181ULL,
1277, 1381, 1487, 1601, 1733, 1867, 2011, 2179, 1277ULL, 1381ULL, 1487ULL, 1601ULL, 1733ULL, 1867ULL, 2011ULL, 2179ULL,
2347, 2531, 2729, 2939, 3167, 3413, 3677, 3967, 2347ULL, 2531ULL, 2729ULL, 2939ULL, 3167ULL, 3413ULL, 3677ULL, 3967ULL,
4273, 4603, 4957, 5347, 5779, 6229, 6709, 7229, 4273ULL, 4603ULL, 4957ULL, 5347ULL, 5779ULL, 6229ULL, 6709ULL, 7229ULL,
7789, 8389, 9041, 9739, 10499, 11311, 12197, 13147, 7789ULL, 8389ULL, 9041ULL, 9739ULL, 10499ULL, 11311ULL, 12197ULL, 13147ULL,
14159, 15259, 16433, 17707, 19069, 20543, 22123, 23827, 14159ULL, 15259ULL, 16433ULL, 17707ULL, 19069ULL, 20543ULL, 22123ULL, 23827ULL,
25667, 27647, 29789, 32083, 34583, 37243, 40111, 43201, 25667ULL, 27647ULL, 29789ULL, 32083ULL, 34583ULL, 37243ULL, 40111ULL, 43201ULL,
46549, 50129, 53987, 58147, 62627, 67447, 72643, 78233, 46549ULL, 50129ULL, 53987ULL, 58147ULL, 62627ULL, 67447ULL, 72643ULL, 78233ULL,
84263, 90749, 97729, 105251, 113357, 122081, 131477, 141601, 84263ULL, 90749ULL, 97729ULL, 105251ULL, 113357ULL, 122081ULL, 131477ULL, 141601ULL,
152501, 164231, 176887, 190507, 205171, 220973, 237971, 256279, 152501ULL, 164231ULL, 176887ULL, 190507ULL, 205171ULL, 220973ULL, 237971ULL, 256279ULL,
275999, 297233, 320101, 344749, 371281, 399851, 430649, 463781, 275999ULL, 297233ULL, 320101ULL, 344749ULL, 371281ULL, 399851ULL, 430649ULL, 463781ULL,
499459, 537883, 579259, 623839, 671831, 723529, 779189, 839131, 499459ULL, 537883ULL, 579259ULL, 623839ULL, 671831ULL, 723529ULL, 779189ULL, 839131ULL,
903691, 973213, 1048123, 1128761, 1215623, 1309163, 1409869, 1518329, 903691ULL, 973213ULL, 1048123ULL, 1128761ULL, 1215623ULL, 1309163ULL, 1409869ULL, 1518329ULL,
1635133, 1760917, 1896407, 2042297, 2199401, 2368589, 2550791, 2747021, 1635133ULL, 1760917ULL, 1896407ULL, 2042297ULL, 2199401ULL, 2368589ULL, 2550791ULL, 2747021ULL,
2958331, 3185899, 3431009, 3694937, 3979163, 4285313, 4614959, 4969961, 2958331ULL, 3185899ULL, 3431009ULL, 3694937ULL, 3979163ULL, 4285313ULL, 4614959ULL, 4969961ULL,
5352271, 5763991, 6207389, 6684907, 7199147, 7752929, 8349311, 8991599, 5352271ULL, 5763991ULL, 6207389ULL, 6684907ULL, 7199147ULL, 7752929ULL, 8349311ULL, 8991599ULL,
9683263, 10428137, 11230309, 12094183, 13024507, 14026393, 15105359, 16267313, 9683263ULL, 10428137ULL, 11230309ULL, 12094183ULL, 13024507ULL, 14026393ULL, 15105359ULL, 16267313ULL,
17518661, 18866291, 20317559, 21880459, 23563571, 25376179, 27328211, 29430391, 17518661ULL, 18866291ULL, 20317559ULL, 21880459ULL, 23563571ULL, 25376179ULL, 27328211ULL, 29430391ULL,
31694281, 34132321, 36757921, 39585457, 42630499, 45909769, 49441289, 53244481, 31694281ULL, 34132321ULL, 36757921ULL, 39585457ULL, 42630499ULL, 45909769ULL, 49441289ULL, 53244481ULL,
57340211, 61750999, 66501077, 71616547, 77125553, 83058289, 89447429, 96328003, 57340211ULL, 61750999ULL, 66501077ULL, 71616547ULL, 77125553ULL, 83058289ULL, 89447429ULL, 96328003ULL,
103737857, 111717757, 120311453, 129566201, 139532831, 150266159, 161825107, 174273193, 103737857ULL, 111717757ULL, 120311453ULL, 129566201ULL, 139532831ULL, 150266159ULL, 161825107ULL, 174273193ULL,
187678831, 202115701, 217663079, 234406397, 252437677, 271855963, 292767983, 315288607, 187678831ULL, 202115701ULL, 217663079ULL, 234406397ULL, 252437677ULL, 271855963ULL, 292767983ULL, 315288607ULL,
339541597, 365660189, 393787907, 424079291, 456700789, 491831621, 529664827, 570408281, 339541597ULL, 365660189ULL, 393787907ULL, 424079291ULL, 456700789ULL, 491831621ULL, 529664827ULL, 570408281ULL,
614285843, 661538611, 712426213, 767228233, 826245839, 889803241, 958249679, 1031961197, 614285843ULL, 661538611ULL, 712426213ULL, 767228233ULL, 826245839ULL, 889803241ULL, 958249679ULL, 1031961197ULL,
1111342867, 1196830801, 1288894709, 1388040461, 1494812807, 1609798417, 1733629067, 1866985157, 1111342867ULL, 1196830801ULL, 1288894709ULL, 1388040461ULL, 1494812807ULL, 1609798417ULL, 1733629067ULL, 1866985157ULL,
2010599411, 2165260961, 2331819499, 2511190229, 2704358747, 2912386343, 3136416067, 3377678861, 2010599411ULL, 2165260961ULL, 2331819499ULL, 2511190229ULL, 2704358747ULL, 2912386343ULL, 3136416067ULL, 3377678861ULL,
3637500323, 3917308049, 4218639443 3637500323ULL, 3917308049ULL, 4218639443ULL
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@ -1596,10 +1596,8 @@ static bool StringifyJsonShapeDataShortString (TRI_shaper_t* shaper,
TRI_shape_t const* shape, TRI_shape_t const* shape,
char const* data, char const* data,
uint64_t size) { uint64_t size) {
TRI_shape_length_short_string_t l;
int res; int res;
l = * (TRI_shape_length_short_string_t const*) data;
data += sizeof(TRI_shape_length_short_string_t); data += sizeof(TRI_shape_length_short_string_t);
res = TRI_AppendCharStringBuffer(buffer, '"'); res = TRI_AppendCharStringBuffer(buffer, '"');
@ -1632,10 +1630,8 @@ static bool StringifyJsonShapeDataLongString (TRI_shaper_t* shaper,
TRI_shape_t const* shape, TRI_shape_t const* shape,
char const* data, char const* data,
uint64_t size) { uint64_t size) {
TRI_shape_length_long_string_t l;
int res; int res;
l = * (TRI_shape_length_long_string_t const*) data;
data += sizeof(TRI_shape_length_long_string_t); data += sizeof(TRI_shape_length_long_string_t);
res = TRI_AppendCharStringBuffer(buffer, '"'); res = TRI_AppendCharStringBuffer(buffer, '"');

View File

@ -52,6 +52,7 @@ typedef struct js_exec_context_s {
v8::Isolate* _isolate; v8::Isolate* _isolate;
v8::Persistent<v8::Function> _func; v8::Persistent<v8::Function> _func;
v8::Persistent<v8::Object> _arguments; v8::Persistent<v8::Object> _arguments;
int _error;
} }
js_exec_context_t; js_exec_context_t;
@ -59,13 +60,21 @@ js_exec_context_t;
// --SECTION-- constructors and destructors // --SECTION-- constructors and destructors
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief fetch the error code from an execution context
////////////////////////////////////////////////////////////////////////////////
int TRI_GetErrorExecutionContext (TRI_js_exec_context_t const context) {
return ((js_exec_context_t const*) context)->_error;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief creates a new execution context /// @brief creates a new execution context
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TRI_js_exec_context_t TRI_CreateExecutionContext (char const* script) { TRI_js_exec_context_t TRI_CreateExecutionContext (char const* script) {
v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Isolate* isolate = v8::Isolate::GetCurrent();
js_exec_context_t* ctx; js_exec_context_t* ctx = new js_exec_context_t;
// execute script inside the context // execute script inside the context
v8::Handle<v8::Script> compiled = v8::Script::Compile(v8::String::New(script), v8::Handle<v8::Script> compiled = v8::Script::Compile(v8::String::New(script),
@ -73,21 +82,33 @@ TRI_js_exec_context_t TRI_CreateExecutionContext (char const* script) {
// compilation failed, return // compilation failed, return
if (compiled.IsEmpty()) { if (compiled.IsEmpty()) {
return 0; ctx->_error = TRI_ERROR_INTERNAL;
return (TRI_js_exec_context_t) ctx;
} }
// compute the function // compute the function
v8::TryCatch tryCatch;
v8::Handle<v8::Value> val = compiled->Run(); v8::Handle<v8::Value> val = compiled->Run();
if (val.IsEmpty()) { if (tryCatch.HasCaught()) {
return 0; if (tryCatch.CanContinue()) {
ctx->_error = TRI_ERROR_INTERNAL;
}
else {
ctx->_error = TRI_ERROR_REQUEST_CANCELED;
}
return (TRI_js_exec_context_t) ctx;
} }
ctx = new js_exec_context_t; if (val.IsEmpty()) {
ctx->_error = TRI_ERROR_INTERNAL;
return (TRI_js_exec_context_t) ctx;
}
ctx->_func = v8::Persistent<v8::Function>::New(isolate, v8::Handle<v8::Function>::Cast(val)); ctx->_func = v8::Persistent<v8::Function>::New(isolate, v8::Handle<v8::Function>::Cast(val));
ctx->_arguments = v8::Persistent<v8::Object>::New(isolate, v8::Object::New()); ctx->_arguments = v8::Persistent<v8::Object>::New(isolate, v8::Object::New());
ctx->_isolate = isolate; ctx->_isolate = isolate;
ctx->_error = TRI_ERROR_NO_ERROR;
// return the handle // return the handle
return (TRI_js_exec_context_t) ctx; return (TRI_js_exec_context_t) ctx;
@ -102,11 +123,13 @@ void TRI_FreeExecutionContext (TRI_js_exec_context_t context) {
ctx = (js_exec_context_t*) context; ctx = (js_exec_context_t*) context;
ctx->_func.Dispose(ctx->_isolate); if (ctx->_error == TRI_ERROR_NO_ERROR) {
ctx->_func.Clear(); ctx->_func.Dispose(ctx->_isolate);
ctx->_func.Clear();
ctx->_arguments.Dispose(ctx->_isolate); ctx->_arguments.Dispose(ctx->_isolate);
ctx->_arguments.Clear(); ctx->_arguments.Clear();
}
delete ctx; delete ctx;
} }
@ -123,14 +146,30 @@ TRI_json_t* TRI_ExecuteResultContext (TRI_js_exec_context_t context) {
js_exec_context_t* ctx; js_exec_context_t* ctx;
ctx = (js_exec_context_t*) context; ctx = (js_exec_context_t*) context;
assert(ctx->_error == TRI_ERROR_NO_ERROR);
// convert back into a handle // convert back into a handle
v8::Persistent<v8::Function> func = ctx->_func; v8::Persistent<v8::Function> func = ctx->_func;
v8::TryCatch tryCatch;
// and execute the function // and execute the function
v8::Handle<v8::Value> args[] = { ctx->_arguments }; v8::Handle<v8::Value> args[] = { ctx->_arguments };
v8::Handle<v8::Value> result = func->Call(func, 1, args); v8::Handle<v8::Value> result = func->Call(func, 1, args);
if (tryCatch.HasCaught()) {
if (tryCatch.CanContinue()) {
ctx->_error = TRI_ERROR_INTERNAL;
}
else {
ctx->_error = TRI_ERROR_REQUEST_CANCELED;
}
return NULL;
}
if (result.IsEmpty()) { if (result.IsEmpty()) {
ctx->_error = TRI_ERROR_INTERNAL;
return NULL; return NULL;
} }

View File

@ -54,6 +54,12 @@ typedef void* TRI_js_exec_context_t;
// --SECTION-- constructors and destructors // --SECTION-- constructors and destructors
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief fetch the error code from an execution context
////////////////////////////////////////////////////////////////////////////////
int TRI_GetErrorExecutionContext (TRI_js_exec_context_t const);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief creates a new execution context /// @brief creates a new execution context
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -121,29 +121,32 @@ static v8::Handle<v8::Object> CreateErrorObject (int errorNumber,
const char* file, const char* file,
int line) { int line) {
v8::HandleScope scope; v8::HandleScope scope;
if (errorNumber == 3) { if (errorNumber == TRI_ERROR_OUT_OF_MEMORY) {
LOG_ERROR("encountered out-of-memory error in %s at line %d", file, line); LOG_ERROR("encountered out-of-memory error in %s at line %d", file, line);
}
v8::Handle<v8::String> errorMessage = v8::String::New(message.c_str(), (int) message.size());
if (errorMessage.IsEmpty()) {
return scope.Close(v8::Object::New()); return scope.Close(v8::Object::New());
} }
else {
TRI_v8_global_t* v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData();
v8::Handle<v8::String> errorMessage = v8::String::New(message.c_str(), (int) message.size()); v8::Handle<v8::Object> errorObject = v8::Exception::Error(errorMessage)->ToObject();
if (errorObject.IsEmpty()) {
v8::Handle<v8::Object> errorObject = v8::Exception::Error(errorMessage)->ToObject(); return scope.Close(v8::Object::New());
errorObject->Set(v8::String::New("errorNum"), v8::Number::New(errorNumber));
errorObject->Set(v8::String::New("errorMessage"), errorMessage);
v8::Handle<v8::Value> proto = v8g->ArangoErrorTempl->NewInstance();
if (! proto.IsEmpty()) {
errorObject->SetPrototype(proto);
}
return scope.Close(errorObject);
} }
errorObject->Set(v8::String::New("errorNum"), v8::Number::New(errorNumber));
errorObject->Set(v8::String::New("errorMessage"), errorMessage);
TRI_v8_global_t* v8g = (TRI_v8_global_t*) v8::Isolate::GetCurrent()->GetData();
v8::Handle<v8::Value> proto = v8g->ArangoErrorTempl->NewInstance();
if (! proto.IsEmpty()) {
errorObject->SetPrototype(proto);
}
return scope.Close(errorObject);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////