From a6b2998b5d295b6cf99ebc856836a78f7a55a35e Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Mon, 8 Jun 2015 16:04:42 +0200 Subject: [PATCH] added try...catch blocks for V8-to-CPP bindings --- arangod/Aql/Query.cpp | 8 + arangod/Aql/V8Expression.cpp | 1 + arangod/Cluster/v8-cluster.cpp | 206 +++++++------ arangod/RestServer/ArangoServer.cpp | 31 +- arangod/V8Server/ApplicationV8.cpp | 2 +- arangod/V8Server/V8Job.cpp | 13 +- arangod/V8Server/V8QueueJob.cpp | 31 +- arangod/V8Server/v8-actions.cpp | 78 +++-- arangod/V8Server/v8-collection.cpp | 104 +++++-- arangod/V8Server/v8-dispatcher.cpp | 15 +- arangod/V8Server/v8-query.cpp | 291 +++++++------------ arangod/V8Server/v8-replication.cpp | 28 +- arangod/V8Server/v8-user-structures.cpp | 113 ++++---- arangod/V8Server/v8-vocbase.cpp | 280 +++++++++--------- arangod/V8Server/v8-voccursor.cpp | 6 +- arangod/V8Server/v8-vocindex.cpp | 31 +- arangod/V8Server/v8-wrapshapedjson.cpp | 368 +++++++++++++----------- arangod/VocBase/document-collection.h | 2 +- arangosh/V8Client/arangosh.cpp | 45 ++- js/server/tests/aql-general-graph.js | 1 + lib/Basics/StringBuffer.h | 9 + lib/V8/V8LineEditor.cpp | 12 +- lib/V8/v8-globals.h | 24 ++ lib/V8/v8-shell.cpp | 7 +- lib/V8/v8-utils.cpp | 261 ++++++++++------- 25 files changed, 1105 insertions(+), 862 deletions(-) diff --git a/arangod/Aql/Query.cpp b/arangod/Aql/Query.cpp index cefb39504e..b8bc4775ca 100644 --- a/arangod/Aql/Query.cpp +++ b/arangod/Aql/Query.cpp @@ -809,6 +809,14 @@ QueryResult Query::parse () { catch (triagens::basics::Exception const& ex) { return QueryResult(ex.code(), ex.message()); } + catch (std::bad_alloc const&) { + cleanupPlanAndEngine(TRI_ERROR_OUT_OF_MEMORY); + return QueryResult(TRI_ERROR_OUT_OF_MEMORY, TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY)); + } + catch (std::exception const& ex) { + cleanupPlanAndEngine(TRI_ERROR_INTERNAL); + return QueryResult(TRI_ERROR_INTERNAL, ex.what()); + } catch (...) { return QueryResult(TRI_ERROR_OUT_OF_MEMORY, TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY)); } diff --git a/arangod/Aql/V8Expression.cpp b/arangod/Aql/V8Expression.cpp index 088e53fbee..6abd102ec5 100644 --- a/arangod/Aql/V8Expression.cpp +++ b/arangod/Aql/V8Expression.cpp @@ -142,6 +142,7 @@ AqlValue V8Expression::execute (v8::Isolate* isolate, } catch (...) { v8g->_query = old; + // bubble up exception throw; } diff --git a/arangod/Cluster/v8-cluster.cpp b/arangod/Cluster/v8-cluster.cpp index a00ce76a0c..a22f97f306 100644 --- a/arangod/Cluster/v8-cluster.cpp +++ b/arangod/Cluster/v8-cluster.cpp @@ -84,7 +84,7 @@ static void CreateAgencyException (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_CasAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 3) { @@ -136,6 +136,7 @@ static void JS_CasAgency (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -143,10 +144,9 @@ static void JS_CasAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_CreateDirectoryAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() != 1) { TRI_V8_THROW_EXCEPTION_USAGE("createDirectory()"); } @@ -161,6 +161,7 @@ static void JS_CreateDirectoryAgency (const v8::FunctionCallbackInfo& } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -168,7 +169,7 @@ static void JS_CreateDirectoryAgency (const v8::FunctionCallbackInfo& //////////////////////////////////////////////////////////////////////////////// static void JS_IsEnabledAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -180,10 +181,8 @@ static void JS_IsEnabledAgency (const v8::FunctionCallbackInfo& args) if (! prefix.empty()) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } - + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -191,7 +190,7 @@ static void JS_IsEnabledAgency (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_IncreaseVersionAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -206,6 +205,7 @@ static void JS_IncreaseVersionAgency (const v8::FunctionCallbackInfo& } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -213,7 +213,7 @@ static void JS_IncreaseVersionAgency (const v8::FunctionCallbackInfo& //////////////////////////////////////////////////////////////////////////////// static void JS_GetAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() < 1) { @@ -279,6 +279,7 @@ static void JS_GetAgency (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(l); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -286,7 +287,7 @@ static void JS_GetAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ListAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() < 1) { @@ -346,6 +347,7 @@ static void JS_ListAgency (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(l); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -353,7 +355,7 @@ static void JS_ListAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_LockReadAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1) { @@ -378,6 +380,7 @@ static void JS_LockReadAgency (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -385,7 +388,7 @@ static void JS_LockReadAgency (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_LockWriteAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1) { @@ -410,6 +413,7 @@ static void JS_LockWriteAgency (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -417,7 +421,7 @@ static void JS_LockWriteAgency (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_UnlockReadAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 2) { @@ -437,6 +441,7 @@ static void JS_UnlockReadAgency (const v8::FunctionCallbackInfo& args } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -444,7 +449,7 @@ static void JS_UnlockReadAgency (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_UnlockWriteAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 2) { @@ -464,6 +469,7 @@ static void JS_UnlockWriteAgency (const v8::FunctionCallbackInfo& arg } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -471,7 +477,7 @@ static void JS_UnlockWriteAgency (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_RemoveAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1) { @@ -493,6 +499,7 @@ static void JS_RemoveAgency (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -500,7 +507,7 @@ static void JS_RemoveAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_SetAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 2) { @@ -530,6 +537,7 @@ static void JS_SetAgency (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -537,7 +545,7 @@ static void JS_SetAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_WatchAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1) { @@ -588,6 +596,7 @@ static void JS_WatchAgency (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(l); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -595,7 +604,7 @@ static void JS_WatchAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_EndpointsAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -616,6 +625,7 @@ static void JS_EndpointsAgency (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN(l); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -623,7 +633,7 @@ static void JS_EndpointsAgency (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_PrefixAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 1) { @@ -642,6 +652,7 @@ static void JS_PrefixAgency (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_STD_STRING(prefix); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -649,7 +660,7 @@ static void JS_PrefixAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_SetPrefixAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -662,6 +673,7 @@ static void JS_SetPrefixAgency (const v8::FunctionCallbackInfo& args) TRI_V8_RETURN_TRUE(); } TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -669,7 +681,7 @@ static void JS_SetPrefixAgency (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_UniqidAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1 || args.Length() > 3) { @@ -702,6 +714,7 @@ static void JS_UniqidAgency (const v8::FunctionCallbackInfo& args) { const std::string value = StringUtils::itoa(result._index); TRI_V8_RETURN_STD_STRING(value); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -709,7 +722,7 @@ static void JS_UniqidAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_VersionAgency (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -720,6 +733,7 @@ static void JS_VersionAgency (const v8::FunctionCallbackInfo& args) { const std::string version = comm.getVersion(); TRI_V8_RETURN_STD_STRING(version); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -731,7 +745,7 @@ static void JS_VersionAgency (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_DoesDatabaseExistClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -743,9 +757,8 @@ static void JS_DoesDatabaseExistClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -768,6 +781,7 @@ static void JS_ListDatabases (const v8::FunctionCallbackInfo& args) { a->Set((uint32_t) count++, TRI_V8_STD_STRING((*it))); } TRI_V8_RETURN(a); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -775,7 +789,7 @@ static void JS_ListDatabases (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_FlushClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -785,6 +799,7 @@ static void JS_FlushClusterInfo (const v8::FunctionCallbackInfo& args ClusterInfo::instance()->flush(); TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -792,7 +807,7 @@ static void JS_FlushClusterInfo (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_GetCollectionInfoClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 2) { @@ -842,6 +857,7 @@ static void JS_GetCollectionInfoClusterInfo (const v8::FunctionCallbackInfo indexes = v8::Array::New(isolate); result->Set(TRI_V8_ASCII_STRING("indexes"), indexes); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -849,7 +865,7 @@ static void JS_GetCollectionInfoClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 3) { @@ -905,6 +921,7 @@ static void JS_GetCollectionInfoCurrentClusterInfo (const v8::FunctionCallbackIn } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -912,7 +929,7 @@ static void JS_GetCollectionInfoCurrentClusterInfo (const v8::FunctionCallbackIn //////////////////////////////////////////////////////////////////////////////// static void JS_GetResponsibleServerClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -922,6 +939,7 @@ static void JS_GetResponsibleServerClusterInfo (const v8::FunctionCallbackInfogetResponsibleServer(TRI_ObjectToString(args[0])); TRI_V8_RETURN_STD_STRING(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -929,7 +947,7 @@ static void JS_GetResponsibleServerClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 2 || args.Length() > 3) { @@ -949,7 +967,7 @@ static void JS_GetResponsibleShardClusterInfo (const v8::FunctionCallbackInfo json(TRI_ObjectToJson(isolate, args[1])); if (json == nullptr) { TRI_V8_THROW_EXCEPTION_MEMORY(); @@ -958,9 +976,7 @@ static void JS_GetResponsibleShardClusterInfo (const v8::FunctionCallbackInfogetResponsibleShard(collectionId, json, documentIsComplete, shardId, usesDefaultShardingAttributes); - - TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); + int res = ClusterInfo::instance()->getResponsibleShard(collectionId, json.get(), documentIsComplete, shardId, usesDefaultShardingAttributes); if (res != TRI_ERROR_NO_ERROR) { TRI_V8_THROW_EXCEPTION(res); @@ -971,6 +987,7 @@ static void JS_GetResponsibleShardClusterInfo (const v8::FunctionCallbackInfoSet(TRI_V8_ASCII_STRING("usesDefaultShardingAttributes"), v8::Boolean::New(isolate, usesDefaultShardingAttributes)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -978,7 +995,7 @@ static void JS_GetResponsibleShardClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -988,6 +1005,7 @@ static void JS_GetServerEndpointClusterInfo (const v8::FunctionCallbackInfogetServerEndpoint(TRI_ObjectToString(args[0])); TRI_V8_RETURN_STD_STRING(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -995,7 +1013,7 @@ static void JS_GetServerEndpointClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -1005,6 +1023,7 @@ static void JS_GetServerNameClusterInfo (const v8::FunctionCallbackInfogetServerName(TRI_ObjectToString(args[0])); TRI_V8_RETURN_STD_STRING(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1012,7 +1031,7 @@ static void JS_GetServerNameClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1030,6 +1049,7 @@ static void JS_GetDBServers (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(l); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1037,7 +1057,7 @@ static void JS_GetDBServers (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ReloadDBServers (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1046,6 +1066,7 @@ static void JS_ReloadDBServers (const v8::FunctionCallbackInfo& args) ClusterInfo::instance()->loadCurrentDBServers(); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1053,7 +1074,7 @@ static void JS_ReloadDBServers (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_GetCoordinators (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1071,6 +1092,7 @@ static void JS_GetCoordinators (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN(l); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1078,7 +1100,7 @@ static void JS_GetCoordinators (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_UniqidClusterInfo (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 1) { @@ -1103,6 +1125,7 @@ static void JS_UniqidClusterInfo (const v8::FunctionCallbackInfo& arg const std::string id = StringUtils::itoa(value); TRI_V8_RETURN_STD_STRING(id); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -1114,7 +1137,7 @@ static void JS_UniqidClusterInfo (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_AddressServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1123,6 +1146,7 @@ static void JS_AddressServerState (const v8::FunctionCallbackInfo& ar const std::string address = ServerState::instance()->getAddress(); TRI_V8_RETURN_STD_STRING(address); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1130,7 +1154,7 @@ static void JS_AddressServerState (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_FlushServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1140,6 +1164,7 @@ static void JS_FlushServerState (const v8::FunctionCallbackInfo& args ServerState::instance()->flush(); TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1147,7 +1172,7 @@ static void JS_FlushServerState (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_LocalInfoServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1156,6 +1181,7 @@ static void JS_LocalInfoServerState (const v8::FunctionCallbackInfo& const std::string li = ServerState::instance()->getLocalInfo(); TRI_V8_RETURN_STD_STRING(li); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1163,7 +1189,7 @@ static void JS_LocalInfoServerState (const v8::FunctionCallbackInfo& //////////////////////////////////////////////////////////////////////////////// static void JS_IdServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1172,6 +1198,7 @@ static void JS_IdServerState (const v8::FunctionCallbackInfo& args) { const std::string id = ServerState::instance()->getId(); TRI_V8_RETURN_STD_STRING(id); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1179,7 +1206,7 @@ static void JS_IdServerState (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_DescriptionServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1188,6 +1215,7 @@ static void JS_DescriptionServerState (const v8::FunctionCallbackInfo const std::string description = ServerState::instance()->getDescription(); TRI_V8_RETURN_STD_STRING(description); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1195,7 +1223,7 @@ static void JS_DescriptionServerState (const v8::FunctionCallbackInfo //////////////////////////////////////////////////////////////////////////////// static void JS_DataPathServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1204,6 +1232,7 @@ static void JS_DataPathServerState (const v8::FunctionCallbackInfo& a const std::string path = ServerState::instance()->getDataPath(); TRI_V8_RETURN_STD_STRING(path); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1211,7 +1240,7 @@ static void JS_DataPathServerState (const v8::FunctionCallbackInfo& a //////////////////////////////////////////////////////////////////////////////// static void JS_LogPathServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1220,6 +1249,7 @@ static void JS_LogPathServerState (const v8::FunctionCallbackInfo& ar const std::string path = ServerState::instance()->getLogPath(); TRI_V8_RETURN_STD_STRING(path); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1227,7 +1257,7 @@ static void JS_LogPathServerState (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_AgentPathServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1236,6 +1266,7 @@ static void JS_AgentPathServerState (const v8::FunctionCallbackInfo& const std::string path = ServerState::instance()->getAgentPath(); TRI_V8_RETURN_STD_STRING(path); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1243,7 +1274,7 @@ static void JS_AgentPathServerState (const v8::FunctionCallbackInfo& //////////////////////////////////////////////////////////////////////////////// static void JS_ArangodPathServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1252,6 +1283,7 @@ static void JS_ArangodPathServerState (const v8::FunctionCallbackInfo const std::string path = ServerState::instance()->getArangodPath(); TRI_V8_RETURN_STD_STRING(path); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1259,7 +1291,7 @@ static void JS_ArangodPathServerState (const v8::FunctionCallbackInfo //////////////////////////////////////////////////////////////////////////////// static void JS_JavaScriptPathServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1268,6 +1300,7 @@ static void JS_JavaScriptPathServerState (const v8::FunctionCallbackInfogetJavaScriptPath(); TRI_V8_RETURN_STD_STRING(path); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1275,7 +1308,7 @@ static void JS_JavaScriptPathServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1284,6 +1317,7 @@ static void JS_DBserverConfigServerState (const v8::FunctionCallbackInfogetDBserverConfig(); TRI_V8_RETURN_STD_STRING(path); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1291,7 +1325,7 @@ static void JS_DBserverConfigServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1300,6 +1334,7 @@ static void JS_CoordinatorConfigServerState (const v8::FunctionCallbackInfogetCoordinatorConfig(); TRI_V8_RETURN_STD_STRING(path); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1307,7 +1342,7 @@ static void JS_CoordinatorConfigServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1317,9 +1352,8 @@ static void JS_DisableDipatcherFrontendServerState (const v8::FunctionCallbackIn if (ServerState::instance()->getDisableDispatcherFrontend()) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1327,7 +1361,7 @@ static void JS_DisableDipatcherFrontendServerState (const v8::FunctionCallbackIn //////////////////////////////////////////////////////////////////////////////// static void JS_DisableDipatcherKickstarterServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1337,9 +1371,8 @@ static void JS_DisableDipatcherKickstarterServerState (const v8::FunctionCallbac if (ServerState::instance()->getDisableDispatcherKickstarter()) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1347,7 +1380,7 @@ static void JS_DisableDipatcherKickstarterServerState (const v8::FunctionCallbac //////////////////////////////////////////////////////////////////////////////// static void JS_InitialisedServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1357,9 +1390,8 @@ static void JS_InitialisedServerState (const v8::FunctionCallbackInfo if (ServerState::instance()->initialised()) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1367,7 +1399,7 @@ static void JS_InitialisedServerState (const v8::FunctionCallbackInfo //////////////////////////////////////////////////////////////////////////////// static void JS_IsCoordinatorServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1377,9 +1409,8 @@ static void JS_IsCoordinatorServerState (const v8::FunctionCallbackInfogetRole() == ServerState::ROLE_COORDINATOR) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1387,7 +1418,7 @@ static void JS_IsCoordinatorServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1397,6 +1428,7 @@ static void JS_RoleServerState (const v8::FunctionCallbackInfo& args) const std::string role = ServerState::roleToString(ServerState::instance()->getRole()); TRI_V8_RETURN_STD_STRING(role); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1404,7 +1436,7 @@ static void JS_RoleServerState (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_SetLocalInfoServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -1415,6 +1447,7 @@ static void JS_SetLocalInfoServerState (const v8::FunctionCallbackInfosetLocalInfo(li); TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1422,7 +1455,7 @@ static void JS_SetLocalInfoServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -1433,6 +1466,7 @@ static void JS_SetIdServerState (const v8::FunctionCallbackInfo& args ServerState::instance()->setId(id); TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1440,7 +1474,7 @@ static void JS_SetIdServerState (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_SetRoleServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -1457,6 +1491,7 @@ static void JS_SetRoleServerState (const v8::FunctionCallbackInfo& ar ServerState::instance()->setRole(r); TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1464,7 +1499,7 @@ static void JS_SetRoleServerState (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_StatusServerState (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1474,6 +1509,7 @@ static void JS_StatusServerState (const v8::FunctionCallbackInfo& arg const std::string state = ServerState::stateToString(ServerState::instance()->getState()); TRI_V8_RETURN_STD_STRING(state); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1481,7 +1517,7 @@ static void JS_StatusServerState (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_GetClusterAuthentication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1495,6 +1531,7 @@ static void JS_GetClusterAuthentication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 4 || args.Length() > 7) { @@ -1778,6 +1815,7 @@ static void JS_AsyncRequest (const v8::FunctionCallbackInfo& args) { Return_PrepareClusterCommResultForJS(args, res); delete res; + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1785,7 +1823,7 @@ static void JS_AsyncRequest (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_SyncRequest (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 4 || args.Length() > 7) { @@ -1837,6 +1875,7 @@ static void JS_SyncRequest (const v8::FunctionCallbackInfo& args) { Return_PrepareClusterCommResultForJS(args, res); delete res; + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1844,7 +1883,7 @@ static void JS_SyncRequest (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Enquire (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -1875,6 +1914,7 @@ static void JS_Enquire (const v8::FunctionCallbackInfo& args) { Return_PrepareClusterCommResultForJS(args, res); delete res; + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1882,7 +1922,7 @@ static void JS_Enquire (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Wait (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); TRI_V8_CURRENT_GLOBALS_AND_SCOPE; if (args.Length() != 1) { @@ -1956,6 +1996,7 @@ static void JS_Wait (const v8::FunctionCallbackInfo& args) { Return_PrepareClusterCommResultForJS(args, res); delete res; + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1963,7 +2004,7 @@ static void JS_Wait (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Drop (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); TRI_V8_CURRENT_GLOBALS_AND_SCOPE; if (args.Length() != 1) { @@ -2021,6 +2062,7 @@ static void JS_Drop (const v8::FunctionCallbackInfo& args) { cc->drop(myclientTransactionID, mycoordTransactionID, myoperationID, myshardID); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- diff --git a/arangod/RestServer/ArangoServer.cpp b/arangod/RestServer/ArangoServer.cpp index 6f04e35333..b20ff3073a 100644 --- a/arangod/RestServer/ArangoServer.cpp +++ b/arangod/RestServer/ArangoServer.cpp @@ -1353,19 +1353,34 @@ int ArangoServer::runScript (TRI_vocbase_t* vocbase) { } else { v8::Handle args[] = { params }; - v8::Handle result = main->Call(main, 1, args); - if (tryCatch.HasCaught()) { - if (tryCatch.CanContinue()) { - TRI_LogV8Exception(isolate, &tryCatch); + try { + v8::Handle result = main->Call(main, 1, args); + + if (tryCatch.HasCaught()) { + if (tryCatch.CanContinue()) { + TRI_LogV8Exception(isolate, &tryCatch); + } + else { + // will stop, so need for v8g->_canceled = true; + TRI_ASSERT(! ok); + } } else { - // will stop, so need for v8g->_canceled = true; - TRI_ASSERT(! ok); + ok = TRI_ObjectToDouble(result) == 0; } } - else { - ok = TRI_ObjectToDouble(result) == 0; + catch (triagens::basics::Exception const& ex) { + LOG_ERROR("caught exception %s: %s", TRI_errno_string(ex.code()), ex.what()); + ok = false; + } + catch (std::bad_alloc const&) { + LOG_ERROR("caught exception %s", TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY)); + ok = false; + } + catch (...) { + LOG_ERROR("caught unknown exception"); + ok = false; } } } diff --git a/arangod/V8Server/ApplicationV8.cpp b/arangod/V8Server/ApplicationV8.cpp index 77febda4dc..50bda024b9 100644 --- a/arangod/V8Server/ApplicationV8.cpp +++ b/arangod/V8Server/ApplicationV8.cpp @@ -220,7 +220,7 @@ void ApplicationV8::V8Context::handleGlobalContextMethods () { _globalMethods.clear(); } - for (auto type : copy) { + for (auto& type : copy) { string const& func = GlobalContextMethods::getCode(type); LOG_DEBUG("executing global context methods '%s' for context %d", func.c_str(), (int) _id); diff --git a/arangod/V8Server/V8Job.cpp b/arangod/V8Server/V8Job.cpp index 7af3f0dac1..e2eb4b4355 100644 --- a/arangod/V8Server/V8Job.cpp +++ b/arangod/V8Server/V8Job.cpp @@ -136,8 +136,8 @@ Job::status_t V8Job::work () { fArgs = v8::Undefined(isolate); } - // call the function wihtin a try/catch - { + // call the function within a try/catch + try { v8::TryCatch tryCatch; action->Call(current, 1, &fArgs); @@ -154,6 +154,15 @@ Job::status_t V8Job::work () { } } } + catch (triagens::basics::Exception const& ex) { + LOG_ERROR("caught exception in V8 job: %s %s", TRI_errno_string(ex.code()), ex.what()); + } + catch (std::bad_alloc const&) { + LOG_ERROR("caught exception in V8 job: %s", TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY)); + } + catch (...) { + LOG_ERROR("caught unknown exception in V8 job"); + } } _v8Dealer->exitContext(context); diff --git a/arangod/V8Server/V8QueueJob.cpp b/arangod/V8Server/V8QueueJob.cpp index f12f1381ff..fe16a8f94c 100644 --- a/arangod/V8Server/V8QueueJob.cpp +++ b/arangod/V8Server/V8QueueJob.cpp @@ -136,20 +136,31 @@ Job::status_t V8QueueJob::work () { } // call the function - v8::TryCatch tryCatch; - main->Call(current, 1, &fArgs); + try { + v8::TryCatch tryCatch; + main->Call(current, 1, &fArgs); - if (tryCatch.HasCaught()) { - if (tryCatch.CanContinue()) { - TRI_LogV8Exception(isolate, &tryCatch); - } - else { - TRI_GET_GLOBALS(); + if (tryCatch.HasCaught()) { + if (tryCatch.CanContinue()) { + TRI_LogV8Exception(isolate, &tryCatch); + } + else { + TRI_GET_GLOBALS(); - v8g->_canceled = true; - LOG_WARNING("caught non-catchable exception (aka termination) in V8 queue job"); + v8g->_canceled = true; + LOG_WARNING("caught non-catchable exception (aka termination) in V8 queue job"); + } } } + catch (triagens::basics::Exception const& ex) { + LOG_ERROR("caught exception in V8 queue job: %s %s", TRI_errno_string(ex.code()), ex.what()); + } + catch (std::bad_alloc const&) { + LOG_ERROR("caught exception in V8 queue job: %s", TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY)); + } + catch (...) { + LOG_ERROR("caught unknown exception in V8 queue job"); + } } _v8Dealer->exitContext(context); diff --git a/arangod/V8Server/v8-actions.cpp b/arangod/V8Server/v8-actions.cpp index 4481a08cde..0bb2bc8c92 100644 --- a/arangod/V8Server/v8-actions.cpp +++ b/arangod/V8Server/v8-actions.cpp @@ -717,8 +717,6 @@ static TRI_action_result_t ExecuteActionVocbase (TRI_vocbase_t* vocbase, TRI_action_t const* action, v8::Handle callback, HttpRequest* request) { - TRI_action_result_t result; - v8::TryCatch tryCatch; v8::HandleScope scope(isolate); @@ -758,17 +756,46 @@ static TRI_action_result_t ExecuteActionVocbase (TRI_vocbase_t* vocbase, // execute the callback v8::Handle args[2] = { req, res }; - callback->Call(callback, 2, args); + // handle C++ exceptions that happen during dynamic script execution + int errorCode; + std::string errorMessage; + + try { + callback->Call(callback, 2, args); + errorCode = TRI_ERROR_NO_ERROR; + } + catch (triagens::basics::Exception const& ex) { + errorCode = ex.code(); + errorMessage = ex.what(); + } + catch (std::bad_alloc const&) { + errorCode = TRI_ERROR_OUT_OF_MEMORY; + } + catch (...) { + errorCode = TRI_ERROR_INTERNAL; + } // invalidate request / response objects v8g->_currentRequest = v8::Undefined(isolate); v8g->_currentResponse = v8::Undefined(isolate); // convert the result + TRI_action_result_t result; result.isValid = true; - if (v8g->_canceled) { - result.isValid = false; + if (errorCode != TRI_ERROR_NO_ERROR) { + result.isValid = false; + result.canceled = false; + + HttpResponse* response = new HttpResponse(HttpResponse::SERVER_ERROR, request->compatibility()); + if (errorMessage.empty()) { + errorMessage = TRI_errno_string(errorCode); + } + response->body().appendText(errorMessage); + } + + else if (v8g->_canceled) { + result.isValid = false; result.canceled = true; } @@ -784,17 +811,15 @@ static TRI_action_result_t ExecuteActionVocbase (TRI_vocbase_t* vocbase, result.sleep = TRI_ObjectToDouble(exception->ToObject()->Get(SleepKey)); } else { - string msg = TRI_StringifyV8Exception(isolate, &tryCatch); - HttpResponse* response = new HttpResponse(HttpResponse::SERVER_ERROR, request->compatibility()); - response->body().appendText(msg); + response->body().appendText(TRI_StringifyV8Exception(isolate, &tryCatch)); result.response = response; } } else { - v8g->_canceled = true; - result.isValid = false; + v8g->_canceled = true; + result.isValid = false; result.canceled = true; } } @@ -817,7 +842,7 @@ static TRI_action_result_t ExecuteActionVocbase (TRI_vocbase_t* vocbase, //////////////////////////////////////////////////////////////////////////////// static void JS_DefineAction (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_GET_GLOBALS(); @@ -874,6 +899,7 @@ static void JS_DefineAction (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -883,7 +909,7 @@ static void JS_DefineAction (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ExecuteGlobalContextFunction (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -905,6 +931,7 @@ static void JS_ExecuteGlobalContextFunction (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_GET_GLOBALS(); @@ -923,6 +950,7 @@ static void JS_GetCurrentRequest (const v8::FunctionCallbackInfo& arg } TRI_V8_RETURN(v8g->_currentRequest); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -932,7 +960,7 @@ static void JS_GetCurrentRequest (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_RawRequestBody (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -956,6 +984,7 @@ static void JS_RawRequestBody (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -965,7 +994,7 @@ static void JS_RawRequestBody (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_RequestParts (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -1121,6 +1150,7 @@ static void JS_RequestParts (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1130,7 +1160,7 @@ static void JS_RequestParts (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_GetCurrentResponse (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_GET_GLOBALS(); @@ -1139,6 +1169,7 @@ static void JS_GetCurrentResponse (const v8::FunctionCallbackInfo& ar } TRI_V8_RETURN(v8g->_currentResponse); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1162,7 +1193,7 @@ class CallbackTest : public ClusterCommCallback { }; static void JS_ClusterTest (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_GET_GLOBALS(); @@ -1380,6 +1411,7 @@ static void JS_ClusterTest (const v8::FunctionCallbackInfo& args) { delete res; TRI_V8_RETURN(r); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1387,7 +1419,7 @@ static void JS_ClusterTest (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_SendChunk (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 2) { @@ -1406,6 +1438,7 @@ static void JS_SendChunk (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(res == TRI_ERROR_NO_ERROR ? v8::True(isolate) : v8::False(isolate)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1413,7 +1446,7 @@ static void JS_SendChunk (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_CreateSid (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 2) { @@ -1434,6 +1467,7 @@ static void JS_CreateSid (const v8::FunctionCallbackInfo& args) { VocbaseContext::createSid(v8g->_vocbase->_name, *sidStr, *username); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1441,7 +1475,7 @@ static void JS_CreateSid (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ClearSid (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -1460,6 +1494,7 @@ static void JS_ClearSid (const v8::FunctionCallbackInfo& args) { VocbaseContext::clearSid(v8g->_vocbase->_name, *sidStr); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1467,7 +1502,7 @@ static void JS_ClearSid (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_AccessSid (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -1486,6 +1521,7 @@ static void JS_AccessSid (const v8::FunctionCallbackInfo& args) { double lastAccess = VocbaseContext::accessSid(v8g->_vocbase->_name, *sidStr); TRI_V8_RETURN(v8::Number::New(isolate, lastAccess)); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- diff --git a/arangod/V8Server/v8-collection.cpp b/arangod/V8Server/v8-collection.cpp index 78092065d8..59811946c8 100644 --- a/arangod/V8Server/v8-collection.cpp +++ b/arangod/V8Server/v8-collection.cpp @@ -1530,7 +1530,9 @@ static void RemoveVocbaseCol (bool useCollection, //////////////////////////////////////////////////////////////////////////////// static void JS_DocumentVocbaseCol (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); DocumentVocbaseCol(true, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1584,7 +1586,7 @@ static void DropVocbaseColCoordinator (const v8::FunctionCallbackInfo //////////////////////////////////////////////////////////////////////////////// static void JS_DropVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -1608,6 +1610,7 @@ static void JS_DropVocbaseCol (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1640,7 +1643,9 @@ static void JS_DropVocbaseCol (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_ExistsVocbaseCol (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return ExistsVocbaseCol(true, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1783,7 +1788,7 @@ static TRI_doc_collection_info_t* GetFigures (TRI_vocbase_col_t* collection) { //////////////////////////////////////////////////////////////////////////////// static void JS_FiguresVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -1871,6 +1876,7 @@ static void JS_FiguresVocbaseCol (const v8::FunctionCallbackInfo& arg TRI_Free(TRI_UNKNOWN_MEM_ZONE, info); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1894,7 +1900,7 @@ static void JS_FiguresVocbaseCol (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_LoadVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -1930,6 +1936,7 @@ static void JS_LoadVocbaseCol (const v8::FunctionCallbackInfo& args) ReleaseCollection(collection); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1937,7 +1944,7 @@ static void JS_LoadVocbaseCol (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_NameVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -1964,10 +1971,15 @@ static void JS_NameVocbaseCol (const v8::FunctionCallbackInfo& args) TRI_Free(TRI_UNKNOWN_MEM_ZONE, name); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } +//////////////////////////////////////////////////////////////////////////////// +/// @brief return the collection's cluster plan id +//////////////////////////////////////////////////////////////////////////////// + static void JS_PlanIdVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -1981,6 +1993,7 @@ static void JS_PlanIdVocbaseCol (const v8::FunctionCallbackInfo& args } TRI_V8_RETURN(V8CollectionId(isolate, collection->_planId)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2075,7 +2088,7 @@ static void JS_PlanIdVocbaseCol (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_PropertiesVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_GET_GLOBALS(); @@ -2344,6 +2357,7 @@ static void JS_PropertiesVocbaseCol (const v8::FunctionCallbackInfo& ReleaseCollection(collection); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2407,7 +2421,9 @@ static void JS_PropertiesVocbaseCol (const v8::FunctionCallbackInfo& //////////////////////////////////////////////////////////////////////////////// static void JS_RemoveVocbaseCol (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return RemoveVocbaseCol(true, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2438,7 +2454,7 @@ static void JS_RemoveVocbaseCol (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_RenameVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1) { @@ -2488,6 +2504,7 @@ static void JS_RenameVocbaseCol (const v8::FunctionCallbackInfo& args } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2559,7 +2576,9 @@ static void JS_RenameVocbaseCol (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_ReplaceVocbaseCol (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return ReplaceVocbaseCol(true, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2623,7 +2642,7 @@ static int GetRevisionCoordinator (TRI_vocbase_col_t* collection, //////////////////////////////////////////////////////////////////////////////// static void JS_RevisionVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -2647,6 +2666,7 @@ static void JS_RevisionVocbaseCol (const v8::FunctionCallbackInfo& ar } TRI_V8_RETURN(V8RevisionId(isolate, rid)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2665,7 +2685,7 @@ static void JS_RevisionVocbaseCol (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_RotateVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (ServerState::instance()->isCoordinator()) { @@ -2694,6 +2714,7 @@ static void JS_RotateVocbaseCol (const v8::FunctionCallbackInfo& args } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2801,7 +2822,9 @@ static void JS_RotateVocbaseCol (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_UpdateVocbaseCol (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return UpdateVocbaseCol(true, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3222,7 +3245,7 @@ static void InsertEdgeColCoordinator (TRI_vocbase_col_t* collection, //////////////////////////////////////////////////////////////////////////////// static void JS_InsertVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -3249,6 +3272,7 @@ static void JS_InsertVocbaseCol (const v8::FunctionCallbackInfo& args else { InsertEdgeCol(collection, args); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3256,7 +3280,7 @@ static void JS_InsertVocbaseCol (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_StatusVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -3284,6 +3308,7 @@ static void JS_StatusVocbaseCol (const v8::FunctionCallbackInfo& args TRI_READ_UNLOCK_STATUS_VOCBASE_COL(collection); TRI_V8_RETURN(v8::Number::New(isolate, (int) status)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3291,7 +3316,7 @@ static void JS_StatusVocbaseCol (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_TruncateVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); bool const forceSync = ExtractWaitForSync(args, 1); @@ -3323,6 +3348,7 @@ static void JS_TruncateVocbaseCol (const v8::FunctionCallbackInfo& ar } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3330,7 +3356,7 @@ static void JS_TruncateVocbaseCol (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_TruncateDatafileVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -3365,6 +3391,7 @@ static void JS_TruncateDatafileVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -3406,6 +3433,7 @@ static void JS_TryRepairDatafileVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -3450,6 +3478,7 @@ static void JS_TypeVocbaseCol (const v8::FunctionCallbackInfo& args) TRI_READ_UNLOCK_STATUS_VOCBASE_COL(collection); TRI_V8_RETURN(v8::Number::New(isolate, (int) type)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3474,7 +3503,7 @@ static void JS_TypeVocbaseCol (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_UnloadVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -3499,6 +3528,7 @@ static void JS_UnloadVocbaseCol (const v8::FunctionCallbackInfo& args } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3506,7 +3536,7 @@ static void JS_UnloadVocbaseCol (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_VersionVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -3533,6 +3563,7 @@ static void JS_VersionVocbaseCol (const v8::FunctionCallbackInfo& arg } TRI_V8_RETURN(v8::Number::New(isolate, (int) info._version)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3541,7 +3572,7 @@ static void JS_VersionVocbaseCol (const v8::FunctionCallbackInfo& arg #ifdef TRI_ENABLE_MAINTAINER_MODE static void JS_CheckPointersVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -3580,11 +3611,10 @@ static void JS_CheckPointersVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_GET_GLOBALS(); @@ -3653,6 +3683,7 @@ static void JS_ChangeOperationModeVocbase (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -3754,6 +3785,7 @@ static void JS_CollectionVocbase (const v8::FunctionCallbackInfo& arg } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3775,7 +3807,7 @@ static void JS_CollectionVocbase (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_CollectionsVocbase (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -3819,6 +3851,7 @@ static void JS_CollectionsVocbase (const v8::FunctionCallbackInfo& ar } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3826,7 +3859,7 @@ static void JS_CollectionsVocbase (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_CompletionsVocbase (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -3890,6 +3923,7 @@ static void JS_CompletionsVocbase (const v8::FunctionCallbackInfo& ar result->Set(j++, TRI_V8_ASCII_STRING("_version()")); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -3967,7 +4001,9 @@ static void JS_CompletionsVocbase (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_RemoveVocbase (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return RemoveVocbaseCol(false, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -4008,7 +4044,9 @@ static void JS_RemoveVocbase (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_DocumentVocbase (const v8::FunctionCallbackInfo& args) { - return DocumentVocbaseCol(false, args); + TRI_V8_TRY_CATCH_BEGIN(isolate); + DocumentVocbaseCol(false, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -4033,7 +4071,9 @@ static void JS_DocumentVocbase (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_ExistsVocbase (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return ExistsVocbaseCol(false, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -4089,7 +4129,9 @@ static void JS_ExistsVocbase (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ReplaceVocbase (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return ReplaceVocbaseCol(false, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -4153,7 +4195,9 @@ static void JS_ReplaceVocbase (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_UpdateVocbase (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return UpdateVocbaseCol(false, args); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -4179,7 +4223,7 @@ static void JS_UpdateVocbase (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_CountVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -4228,6 +4272,7 @@ static void JS_CountVocbaseCol (const v8::FunctionCallbackInfo& args) // READ-LOCK end TRI_V8_RETURN(v8::Number::New(isolate, (double) s)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -4238,7 +4283,7 @@ static void JS_CountVocbaseCol (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_DatafilesVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -4293,6 +4338,7 @@ static void JS_DatafilesVocbaseCol (const v8::FunctionCallbackInfo& a TRI_DestroyFileStructureCollection(&structure); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -4312,7 +4358,7 @@ static void JS_DatafilesVocbaseCol (const v8::FunctionCallbackInfo& a //////////////////////////////////////////////////////////////////////////////// static void JS_DatafileScanVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -4374,6 +4420,7 @@ static void JS_DatafileScanVocbaseCol (const v8::FunctionCallbackInfo TRI_READ_UNLOCK_STATUS_VOCBASE_COL(collection); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } // ............................................................................. @@ -4444,3 +4491,4 @@ void TRI_InitV8collection (v8::Handle context, v8g->VocbaseColTempl.Reset(isolate, rt); TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("ArangoCollection"), ft->GetFunction()); } + diff --git a/arangod/V8Server/v8-dispatcher.cpp b/arangod/V8Server/v8-dispatcher.cpp index fb20c33c51..d6495e5b3f 100644 --- a/arangod/V8Server/v8-dispatcher.cpp +++ b/arangod/V8Server/v8-dispatcher.cpp @@ -108,7 +108,7 @@ static DispatcherThread* CreateV8DispatcherThread (DispatcherQueue* queue, void* //////////////////////////////////////////////////////////////////////////////// static void JS_RegisterTask (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (GlobalScheduler == nullptr || GlobalDispatcher == nullptr) { @@ -262,6 +262,7 @@ static void JS_RegisterTask (const v8::FunctionCallbackInfo& args) { v8::Handle result = TRI_ObjectJson(isolate, json.get()); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -271,7 +272,7 @@ static void JS_RegisterTask (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_UnregisterTask (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -291,6 +292,7 @@ static void JS_UnregisterTask (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -300,7 +302,7 @@ static void JS_UnregisterTask (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_GetTask (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 1) { @@ -330,6 +332,7 @@ static void JS_GetTask (const v8::FunctionCallbackInfo& args) { v8::Handle result = TRI_ObjectJson(isolate, json.get()); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -344,7 +347,7 @@ static void JS_GetTask (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_CreateNamedQueue (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (GlobalDispatcher == nullptr) { @@ -417,6 +420,7 @@ static void JS_CreateNamedQueue (const v8::FunctionCallbackInfo& args } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -426,7 +430,7 @@ static void JS_CreateNamedQueue (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_AddJob (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 2 || ! args[1]->IsObject()) { @@ -456,6 +460,7 @@ static void JS_AddJob (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- diff --git a/arangod/V8Server/v8-query.cpp b/arangod/V8Server/v8-query.cpp index c1764ff226..54e57424f0 100644 --- a/arangod/V8Server/v8-query.cpp +++ b/arangod/V8Server/v8-query.cpp @@ -920,7 +920,7 @@ static void EdgesQuery (TRI_edge_direction_e direction, //////////////////////////////////////////////////////////////////////////////// static void JS_AllQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // expecting two arguments @@ -986,6 +986,7 @@ static void JS_AllQuery (const v8::FunctionCallbackInfo& args) { result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, count)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -994,7 +995,7 @@ static void JS_AllQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_NthQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // expecting two arguments @@ -1062,6 +1063,7 @@ static void JS_NthQuery (const v8::FunctionCallbackInfo& args) { result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, count)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1070,7 +1072,7 @@ static void JS_NthQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Nth2Query (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // expecting two arguments @@ -1132,6 +1134,7 @@ static void JS_Nth2Query (const v8::FunctionCallbackInfo& args) { result->Set(TRI_V8_ASCII_STRING("count"), v8::Number::New(isolate, count)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1139,7 +1142,7 @@ static void JS_Nth2Query (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Nth3Query (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // expecting two arguments @@ -1157,6 +1160,7 @@ static void JS_Nth3Query (const v8::FunctionCallbackInfo& args) { uint64_t hash = TRI_FnvHashPointer(static_cast(key.c_str()), key.size()); TRI_V8_RETURN(v8::Number::New(isolate, static_cast(hash % numberOfPartitions))); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1165,7 +1169,7 @@ static void JS_Nth3Query (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_OffsetQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // expecting two arguments @@ -1235,6 +1239,7 @@ static void JS_OffsetQuery (const v8::FunctionCallbackInfo& args) { result->Set(TRI_V8_ASCII_STRING("skip"), v8::Number::New(isolate, internalSkip)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1254,7 +1259,7 @@ static void JS_OffsetQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_AnyQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* col; @@ -1294,6 +1299,7 @@ static void JS_AnyQuery (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(doc); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1301,7 +1307,7 @@ static void JS_AnyQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ByExampleQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // expecting example, skip, limit @@ -1352,7 +1358,8 @@ static void JS_ByExampleQuery (const v8::FunctionCallbackInfo& args) std::unique_ptr matcher; try { matcher.reset(new ExampleMatcher(isolate, example, shaper, errorMessage)); - } catch (int e) { + } + catch (int e) { if (e == TRI_RESULT_ELEMENT_NOT_FOUND) { // empty result TRI_V8_RETURN(EmptyResult(isolate)); @@ -1416,99 +1423,15 @@ static void JS_ByExampleQuery (const v8::FunctionCallbackInfo& args) } } - result->Set(TRI_V8_ASCII_STRING("total"), v8::Integer::New(isolate, (int32_t) total)); result->Set(TRI_V8_ASCII_STRING("count"), v8::Integer::New(isolate, (int32_t) count)); - if (error) { TRI_V8_THROW_EXCEPTION_MEMORY(); } TRI_V8_RETURN(result); -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief aggregate(count) value of a single attribute, experiment -//////////////////////////////////////////////////////////////////////////////// - -static void JS_AggregateCount (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope scope(isolate); - - // expecting example, skip, limit - if (args.Length() < 1) { - TRI_V8_THROW_EXCEPTION_USAGE("AGGREGATE_COUNT()"); - } - - // extract the attribute name - if (! args[0]->IsString()) { - TRI_V8_THROW_TYPE_ERROR(" must be a string"); - } - std::string attName = TRI_ObjectToString(args[0]); - - TRI_vocbase_col_t const* col; - col = TRI_UnwrapClass(args.Holder(), TRI_GetVocBaseColType()); - - if (col == nullptr) { - TRI_V8_THROW_EXCEPTION_INTERNAL("cannot extract collection"); - } - - TRI_THROW_SHARDING_COLLECTION_NOT_YET_IMPLEMENTED(col); - - SingleCollectionReadOnlyTransaction trx(new V8TransactionContext(true), col->_vocbase, col->_cid); - - int res = trx.begin(); - - if (res != TRI_ERROR_NO_ERROR) { - TRI_V8_THROW_EXCEPTION(res); - } - - TRI_document_collection_t* document = trx.documentCollection(); - TRI_shaper_t* shaper = document->getShaper(); - - // to extract sub-documents in the attribute: - TRI_shape_pid_t pid - = shaper->lookupAttributePathByName(shaper, attName.c_str()); - - // ........................................................................... - // inside a read transaction - // ........................................................................... - - CountingAggregation* agg; - - trx.lockRead(); - - // find documents by example - try { - agg = TRI_AggregateBySingleAttribute(trx.trxCollection(), pid); - } - catch (std::exception&) { - TRI_V8_THROW_EXCEPTION_MEMORY(); - } - - trx.finish(res); - - // ........................................................................... - // outside a read transaction - // ........................................................................... - - // setup result - v8::Handle result = v8::Object::New(isolate); - v8::Handle documents = v8::Array::New(isolate); - result->Set(TRI_V8_ASCII_STRING("documents"), documents); - uint32_t count = 0; - for (auto& x : *agg) { - v8::Handle w = v8::Object::New(isolate); - Json json(shaper->_memoryZone, TRI_JsonShapedJson(shaper, &x.first)); - w->Set(TRI_V8_ASCII_STRING("value"), - TRI_ObjectJson(isolate, json.json())); - w->Set(TRI_V8_ASCII_STRING("count"), - v8::Number::New(isolate, static_cast(x.second))); - documents->Set(count++, w); - } - delete agg; - TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1631,7 +1554,7 @@ static void ByExampleHashIndexQuery (SingleCollectionReadOnlyTransaction& trx, //////////////////////////////////////////////////////////////////////////////// static void JS_ByExampleHashIndex (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* col; @@ -1665,6 +1588,7 @@ static void JS_ByExampleHashIndex (const v8::FunctionCallbackInfo& ar // outside a write transaction // ............................................................................. + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1672,9 +1596,11 @@ static void JS_ByExampleHashIndex (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_ByConditionSkiplist (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); std::string const signature("BY_CONDITION_SKIPLIST(, , , , )"); return ExecuteSkiplistQuery(args, signature, QUERY_CONDITION); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1682,9 +1608,11 @@ static void JS_ByConditionSkiplist (const v8::FunctionCallbackInfo& a //////////////////////////////////////////////////////////////////////////////// static void JS_ByExampleSkiplist (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); std::string const signature("BY_EXAMPLE_SKIPLIST(, , , , )"); return ExecuteSkiplistQuery(args, signature, QUERY_EXAMPLE); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1788,7 +1716,7 @@ template static bool ChecksumCalculator (TRI_doc_mptr_t const* //////////////////////////////////////////////////////////////////////////////// static void JS_ChecksumCollection (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (ServerState::instance()->isCoordinator()) { @@ -1871,6 +1799,7 @@ static void JS_ChecksumCollection (const v8::FunctionCallbackInfo& ar result->Set(TRI_V8_ASCII_STRING("revision"), TRI_V8_STD_STRING(rid)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1907,7 +1836,9 @@ static void JS_ChecksumCollection (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_EdgesQuery (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return EdgesQuery(TRI_EDGE_ANY, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1943,7 +1874,9 @@ static void JS_EdgesQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_InEdgesQuery (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return EdgesQuery(TRI_EDGE_IN, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1951,7 +1884,7 @@ static void JS_InEdgesQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_FirstQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 1) { @@ -2025,6 +1958,7 @@ static void JS_FirstQuery (const v8::FunctionCallbackInfo& args) { TRI_V8_RETURN(result); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2149,7 +2083,7 @@ static void FulltextQuery (SingleCollectionReadOnlyTransaction& trx, //////////////////////////////////////////////////////////////////////////////// static void JS_FulltextQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* col; @@ -2182,6 +2116,8 @@ static void JS_FulltextQuery (const v8::FunctionCallbackInfo& args) { // ............................................................................. // outside a write transaction // ............................................................................. + + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2189,7 +2125,7 @@ static void JS_FulltextQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_LastQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 1) { @@ -2265,6 +2201,7 @@ static void JS_LastQuery (const v8::FunctionCallbackInfo& args) { TRI_V8_RETURN(result); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2327,7 +2264,7 @@ static void NearQuery (SingleCollectionReadOnlyTransaction& trx, //////////////////////////////////////////////////////////////////////////////// static void JS_NearQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* col; @@ -2360,6 +2297,8 @@ static void JS_NearQuery (const v8::FunctionCallbackInfo& args) { // ............................................................................. // outside a write transaction // ............................................................................. + + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2395,7 +2334,9 @@ static void JS_NearQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_OutEdgesQuery (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); return EdgesQuery(TRI_EDGE_OUT, args); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2458,7 +2399,7 @@ static void WithinQuery (SingleCollectionReadOnlyTransaction& trx, //////////////////////////////////////////////////////////////////////////////// static void JS_WithinQuery (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* col; @@ -2491,6 +2432,7 @@ static void JS_WithinQuery (const v8::FunctionCallbackInfo& args) { // ............................................................................. // outside a read transaction // ............................................................................. + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2521,7 +2463,7 @@ static void JS_WithinQuery (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_LookupByKeys (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* col = TRI_UnwrapClass(args.Holder(), TRI_GetVocBaseColType()); @@ -2535,45 +2477,38 @@ static void JS_LookupByKeys (const v8::FunctionCallbackInfo& args) { TRI_V8_THROW_EXCEPTION_USAGE("documents()"); } - try { - triagens::basics::Json bindVars(triagens::basics::Json::Object, 2); - bindVars("@collection", triagens::basics::Json(std::string(col->_name))); - bindVars("keys", triagens::basics::Json(TRI_UNKNOWN_MEM_ZONE, TRI_ObjectToJson(isolate, args[0]))); + triagens::basics::Json bindVars(triagens::basics::Json::Object, 2); + bindVars("@collection", triagens::basics::Json(std::string(col->_name))); + bindVars("keys", triagens::basics::Json(TRI_UNKNOWN_MEM_ZONE, TRI_ObjectToJson(isolate, args[0]))); - std::string const aql("FOR doc IN @@collection FILTER doc._key IN @keys RETURN doc"); + std::string const aql("FOR doc IN @@collection FILTER doc._key IN @keys RETURN doc"); - TRI_GET_GLOBALS(); - triagens::aql::Query query(v8g->_applicationV8, - true, - col->_vocbase, - aql.c_str(), - aql.size(), - bindVars.steal(), - nullptr, - triagens::aql::PART_MAIN); - - auto queryResult = query.executeV8(isolate, static_cast(v8g->_queryRegistry)); + TRI_GET_GLOBALS(); + triagens::aql::Query query(v8g->_applicationV8, + true, + col->_vocbase, + aql.c_str(), + aql.size(), + bindVars.steal(), + nullptr, + triagens::aql::PART_MAIN); - if (queryResult.code != TRI_ERROR_NO_ERROR) { - if (queryResult.code == TRI_ERROR_REQUEST_CANCELED || - queryResult.code == TRI_ERROR_QUERY_KILLED) { - THROW_ARANGO_EXCEPTION(TRI_ERROR_REQUEST_CANCELED); - } + auto queryResult = query.executeV8(isolate, static_cast(v8g->_queryRegistry)); - THROW_ARANGO_EXCEPTION_MESSAGE(queryResult.code, queryResult.details); + if (queryResult.code != TRI_ERROR_NO_ERROR) { + if (queryResult.code == TRI_ERROR_REQUEST_CANCELED || + queryResult.code == TRI_ERROR_QUERY_KILLED) { + THROW_ARANGO_EXCEPTION(TRI_ERROR_REQUEST_CANCELED); } - v8::Handle result = v8::Object::New(isolate); - result->Set(TRI_V8_ASCII_STRING("documents"), queryResult.result); + THROW_ARANGO_EXCEPTION_MESSAGE(queryResult.code, queryResult.details); + } - TRI_V8_RETURN(result); - } - catch (triagens::basics::Exception const& ex) { - TRI_V8_THROW_EXCEPTION_MESSAGE(ex.code(), ex.what()); - } - catch (...) { - TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); - } + v8::Handle result = v8::Object::New(isolate); + result->Set(TRI_V8_ASCII_STRING("documents"), queryResult.result); + + TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2608,7 +2543,7 @@ static void JS_LookupByKeys (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_RemoveByKeys (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_col_t const* col = TRI_UnwrapClass(args.Holder(), TRI_GetVocBaseColType()); @@ -2622,61 +2557,54 @@ static void JS_RemoveByKeys (const v8::FunctionCallbackInfo& args) { TRI_V8_THROW_EXCEPTION_USAGE("removeByKeys()"); } - try { - triagens::basics::Json bindVars(triagens::basics::Json::Object, 2); - bindVars("@collection", triagens::basics::Json(std::string(col->_name))); - bindVars("keys", triagens::basics::Json(TRI_UNKNOWN_MEM_ZONE, TRI_ObjectToJson(isolate, args[0]))); + triagens::basics::Json bindVars(triagens::basics::Json::Object, 2); + bindVars("@collection", triagens::basics::Json(std::string(col->_name))); + bindVars("keys", triagens::basics::Json(TRI_UNKNOWN_MEM_ZONE, TRI_ObjectToJson(isolate, args[0]))); - std::string const aql("FOR key IN @keys REMOVE key IN @@collection OPTIONS { ignoreErrors: true }"); - - TRI_GET_GLOBALS(); - triagens::aql::Query query(v8g->_applicationV8, - true, - col->_vocbase, - aql.c_str(), - aql.size(), - bindVars.steal(), - nullptr, - triagens::aql::PART_MAIN); - - auto queryResult = query.executeV8(isolate, static_cast(v8g->_queryRegistry)); + std::string const aql("FOR key IN @keys REMOVE key IN @@collection OPTIONS { ignoreErrors: true }"); + + TRI_GET_GLOBALS(); + triagens::aql::Query query(v8g->_applicationV8, + true, + col->_vocbase, + aql.c_str(), + aql.size(), + bindVars.steal(), + nullptr, + triagens::aql::PART_MAIN); - if (queryResult.code != TRI_ERROR_NO_ERROR) { - if (queryResult.code == TRI_ERROR_REQUEST_CANCELED || - queryResult.code == TRI_ERROR_QUERY_KILLED) { - THROW_ARANGO_EXCEPTION(TRI_ERROR_REQUEST_CANCELED); - } + auto queryResult = query.executeV8(isolate, static_cast(v8g->_queryRegistry)); - THROW_ARANGO_EXCEPTION_MESSAGE(queryResult.code, queryResult.details); + if (queryResult.code != TRI_ERROR_NO_ERROR) { + if (queryResult.code == TRI_ERROR_REQUEST_CANCELED || + queryResult.code == TRI_ERROR_QUERY_KILLED) { + THROW_ARANGO_EXCEPTION(TRI_ERROR_REQUEST_CANCELED); } + + THROW_ARANGO_EXCEPTION_MESSAGE(queryResult.code, queryResult.details); + } + + size_t ignored = 0; + size_t removed = 0; - size_t ignored = 0; - size_t removed = 0; + if (queryResult.stats != nullptr) { + auto found = TRI_LookupObjectJson(queryResult.stats, "writesIgnored"); + if (TRI_IsNumberJson(found)) { + ignored = static_cast(found->_value._number); + } - if (queryResult.stats != nullptr) { - auto found = TRI_LookupObjectJson(queryResult.stats, "writesIgnored"); - if (TRI_IsNumberJson(found)) { - ignored = static_cast(found->_value._number); - } - - found = TRI_LookupObjectJson(queryResult.stats, "writesExecuted"); - if (TRI_IsNumberJson(found)) { - removed = static_cast(found->_value._number); - } + found = TRI_LookupObjectJson(queryResult.stats, "writesExecuted"); + if (TRI_IsNumberJson(found)) { + removed = static_cast(found->_value._number); } - - v8::Handle result = v8::Object::New(isolate); - result->Set(TRI_V8_ASCII_STRING("removed"), v8::Number::New(isolate, static_cast(removed))); - result->Set(TRI_V8_ASCII_STRING("ignored"), v8::Number::New(isolate, static_cast(ignored))); - - TRI_V8_RETURN(result); - } - catch (triagens::basics::Exception const& ex) { - TRI_V8_THROW_EXCEPTION_MESSAGE(ex.code(), ex.what()); - } - catch (...) { - TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); } + + v8::Handle result = v8::Object::New(isolate); + result->Set(TRI_V8_ASCII_STRING("removed"), v8::Number::New(isolate, static_cast(removed))); + result->Set(TRI_V8_ASCII_STRING("ignored"), v8::Number::New(isolate, static_cast(ignored))); + + TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -2723,7 +2651,6 @@ void TRI_InitV8Queries (v8::Isolate* isolate, TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("removeByKeys"), JS_RemoveByKeys, true); // internal methods. not intended to be used by end-users - TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("AGGREGATE_COUNT"), JS_AggregateCount, true); TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("NTH"), JS_NthQuery, true); TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("NTH2"), JS_Nth2Query, true); TRI_AddMethodVocbase(isolate, VocbaseColTempl, TRI_V8_ASCII_STRING("NTH3"), JS_Nth3Query, true); diff --git a/arangod/V8Server/v8-replication.cpp b/arangod/V8Server/v8-replication.cpp index c294888ad6..5098426c1c 100644 --- a/arangod/V8Server/v8-replication.cpp +++ b/arangod/V8Server/v8-replication.cpp @@ -31,6 +31,7 @@ #include "v8-vocbaseprivate.h" #include "Replication/InitialSyncer.h" #include "V8/v8-conv.h" +#include "V8/v8-globals.h" #include "V8/v8-utils.h" #include "Wal/LogfileManager.h" #include "VocBase/replication-dump.h" @@ -49,7 +50,7 @@ using namespace triagens::rest; //////////////////////////////////////////////////////////////////////////////// static void JS_StateLoggerReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); triagens::wal::LogfileManagerState s = triagens::wal::LogfileManager::instance()->state(); @@ -72,6 +73,7 @@ static void JS_StateLoggerReplication (const v8::FunctionCallbackInfo result->Set(TRI_V8_ASCII_STRING("clients"), clients); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -80,7 +82,7 @@ static void JS_StateLoggerReplication (const v8::FunctionCallbackInfo #ifdef TRI_ENABLE_MAINTAINER_MODE static void JS_LastLoggerReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -113,6 +115,7 @@ static void JS_LastLoggerReplication (const v8::FunctionCallbackInfo& TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } #endif @@ -121,7 +124,7 @@ static void JS_LastLoggerReplication (const v8::FunctionCallbackInfo& //////////////////////////////////////////////////////////////////////////////// static void JS_SynchroniseReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1 || ! args[0]->IsObject()) { @@ -251,6 +254,7 @@ static void JS_SynchroniseReplication (const v8::FunctionCallbackInfo } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -258,11 +262,12 @@ static void JS_SynchroniseReplication (const v8::FunctionCallbackInfo //////////////////////////////////////////////////////////////////////////////// static void JS_ServerIdReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); const string serverId = StringUtils::itoa(TRI_GetIdServer()); TRI_V8_RETURN_STD_STRING(serverId); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -270,7 +275,7 @@ static void JS_ServerIdReplication (const v8::FunctionCallbackInfo& a //////////////////////////////////////////////////////////////////////////////// static void JS_ConfigureApplierReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -476,6 +481,7 @@ static void JS_ConfigureApplierReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -517,6 +523,7 @@ static void JS_StartApplierReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -548,6 +555,7 @@ static void JS_ShutdownApplierReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -582,6 +590,7 @@ static void JS_StateApplierReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -613,6 +622,7 @@ static void JS_ForgetApplierReplication (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 1 || ! args[0]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEYSPACE_CREATE(, , )"); } @@ -914,6 +913,7 @@ static void JS_KeyspaceCreate (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -921,7 +921,7 @@ static void JS_KeyspaceCreate (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_KeyspaceDrop (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1 || ! args[0]->IsString()) { @@ -952,6 +952,7 @@ static void JS_KeyspaceDrop (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -959,10 +960,9 @@ static void JS_KeyspaceDrop (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyspaceCount (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 1 || ! args[0]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEYSPACE_COUNT(, )"); } @@ -997,6 +997,7 @@ static void JS_KeyspaceCount (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(v8::Number::New(isolate, static_cast(count))); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1004,10 +1005,9 @@ static void JS_KeyspaceCount (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyspaceExists (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() != 1 || ! args[0]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEYSPACE_EXISTS()"); } @@ -1028,9 +1028,8 @@ static void JS_KeyspaceExists (const v8::FunctionCallbackInfo& args) if (hash != nullptr) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1038,10 +1037,9 @@ static void JS_KeyspaceExists (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_KeyspaceKeys (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 1 || ! args[0]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEYSPACE_KEYS(, )"); } @@ -1070,6 +1068,7 @@ static void JS_KeyspaceKeys (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(hash->keyspaceKeys(isolate)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1077,10 +1076,9 @@ static void JS_KeyspaceKeys (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyspaceGet (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 1 || ! args[0]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEYSPACE_GET(, )"); } @@ -1109,18 +1107,17 @@ static void JS_KeyspaceGet (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(hash->keyspaceGet(isolate)); + TRI_V8_TRY_CATCH_END } - //////////////////////////////////////////////////////////////////////////////// /// @brief removes all keys from the keyspace //////////////////////////////////////////////////////////////////////////////// static void JS_KeyspaceRemove (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 1 || ! args[0]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEYSPACE_REMOVE(, )"); } @@ -1149,18 +1146,17 @@ static void JS_KeyspaceRemove (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN(hash->keyspaceRemove(isolate)); + TRI_V8_TRY_CATCH_END } - //////////////////////////////////////////////////////////////////////////////// /// @brief returns the value for a key in the keyspace //////////////////////////////////////////////////////////////////////////////// static void JS_KeyGet (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_GET(, )"); } @@ -1190,6 +1186,7 @@ static void JS_KeyGet (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1197,10 +1194,9 @@ static void JS_KeyGet (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeySet (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 3 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_SET(, , , )"); } @@ -1237,9 +1233,8 @@ static void JS_KeySet (const v8::FunctionCallbackInfo& args) { if (result) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1247,10 +1242,9 @@ static void JS_KeySet (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeySetCas (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 4 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_SET_CAS(, , , )"); } @@ -1292,9 +1286,8 @@ static void JS_KeySetCas (const v8::FunctionCallbackInfo& args) { if (match) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1302,10 +1295,9 @@ static void JS_KeySetCas (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyRemove (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_REMOVE(, )"); } @@ -1337,9 +1329,8 @@ static void JS_KeyRemove (const v8::FunctionCallbackInfo& args) { if (result) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1347,10 +1338,9 @@ static void JS_KeyRemove (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyExists (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_EXISTS(, )"); } @@ -1382,9 +1372,8 @@ static void JS_KeyExists (const v8::FunctionCallbackInfo& args) { if (result) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1392,10 +1381,9 @@ static void JS_KeyExists (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyIncr (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_INCR(, , )"); } @@ -1439,6 +1427,7 @@ static void JS_KeyIncr (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(v8::Number::New(isolate, result)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1446,10 +1435,9 @@ static void JS_KeyIncr (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyUpdate (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 3 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_UPDATE(, , , )"); } @@ -1479,6 +1467,7 @@ static void JS_KeyUpdate (const v8::FunctionCallbackInfo& args) { } hash->keyMerge(args, key, args[2], nullMeansRemove); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1486,10 +1475,9 @@ static void JS_KeyUpdate (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyKeys (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_KEYS(, )"); } @@ -1514,6 +1502,7 @@ static void JS_KeyKeys (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(hash->keyKeys(isolate, key)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1521,10 +1510,9 @@ static void JS_KeyKeys (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyValues (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_VALUES(, )"); } @@ -1549,6 +1537,7 @@ static void JS_KeyValues (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(hash->keyValues(isolate, key)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1556,10 +1545,9 @@ static void JS_KeyValues (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyPush (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 3 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_PUSH(, , )"); } @@ -1590,6 +1578,7 @@ static void JS_KeyPush (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1597,10 +1586,9 @@ static void JS_KeyPush (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyPop (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_POP(, )"); } @@ -1625,6 +1613,7 @@ static void JS_KeyPop (const v8::FunctionCallbackInfo& args) { } hash->keyPop(args, key); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1632,10 +1621,9 @@ static void JS_KeyPop (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyTransfer (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 3 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_TRANSFER(, , )"); } @@ -1661,6 +1649,7 @@ static void JS_KeyTransfer (const v8::FunctionCallbackInfo& args) { } hash->keyTransfer(args, keyFrom, keyTo); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1668,10 +1657,9 @@ static void JS_KeyTransfer (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyGetAt (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 3 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_GET_AT(, , )"); } @@ -1697,6 +1685,7 @@ static void JS_KeyGetAt (const v8::FunctionCallbackInfo& args) { } hash->keyGetAt(args, key, offset); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1704,10 +1693,9 @@ static void JS_KeyGetAt (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeySetAt (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 4 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_SET_AT(, , , )"); } @@ -1738,6 +1726,7 @@ static void JS_KeySetAt (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1745,10 +1734,9 @@ static void JS_KeySetAt (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyType (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_TYPE(, )"); } @@ -1778,6 +1766,7 @@ static void JS_KeyType (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_STRING(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1785,10 +1774,9 @@ static void JS_KeyType (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_KeyCount (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2 || ! args[0]->IsString() || ! args[1]->IsString()) { TRI_V8_THROW_EXCEPTION_USAGE("KEY_COUNT(, )"); } @@ -1823,6 +1811,7 @@ static void JS_KeyCount (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 9ea11e9e31..9f8afea9d4 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -31,10 +31,11 @@ #include "Aql/Query.h" #include "Aql/QueryList.h" #include "Aql/QueryRegistry.h" -#include "Basics/Utf8Helper.h" #include "Basics/conversions.h" #include "Basics/json-utilities.h" #include "Basics/MutexLocker.h" +#include "Basics/ScopeGuard.h" +#include "Basics/Utf8Helper.h" #include "Cluster/AgencyComm.h" #include "Cluster/ClusterComm.h" #include "Cluster/ClusterInfo.h" @@ -157,7 +158,7 @@ static v8::Handle WrapClass (v8::Isolate *isolate, //////////////////////////////////////////////////////////////////////////////// static void JS_Transaction (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1 || ! args[0]->IsObject()) { @@ -356,7 +357,7 @@ static void JS_Transaction (const v8::FunctionCallbackInfo& args) { } v8::Handle result; - { + try { v8::TryCatch tryCatch; v8::Handle arguments = params; result = action->Call(current, 1, &arguments); @@ -374,6 +375,18 @@ static void JS_Transaction (const v8::FunctionCallbackInfo& args) { } } } + catch (triagens::basics::Exception const& ex) { + TRI_V8_THROW_EXCEPTION_MESSAGE(ex.code(), ex.what()); + } + catch (std::bad_alloc const& ex) { + TRI_V8_THROW_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY); + } + catch (std::exception const& ex) { + TRI_V8_THROW_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, ex.what()); + } + catch (...) { + TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); + } res = trx.commit(); @@ -382,6 +395,7 @@ static void JS_Transaction (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -444,7 +458,7 @@ static void JS_Transaction (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_PropertiesWal (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 1 || (args.Length() == 1 && ! args[0]->IsObject())) { @@ -497,6 +511,7 @@ static void JS_PropertiesWal (const v8::FunctionCallbackInfo& args) { result->Set(TRI_V8_ASCII_STRING("throttleWhenPending"), v8::Number::New(isolate, (double) l->throttleWhenPending())); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -529,7 +544,7 @@ static void JS_PropertiesWal (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_FlushWal (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); bool waitForSync = false; @@ -564,14 +579,15 @@ static void JS_FlushWal (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief normalize UTF 16 strings //////////////////////////////////////////////////////////////////////////////// -static void JS_normalize_string (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); +static void JS_NormalizeString (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -579,6 +595,7 @@ static void JS_normalize_string (const v8::FunctionCallbackInfo& args } TRI_normalize_V8_Obj(args, args[0]); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -586,7 +603,7 @@ static void JS_normalize_string (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_EnableNativeBacktraces (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -596,6 +613,7 @@ static void JS_EnableNativeBacktraces (const v8::FunctionCallbackInfo triagens::basics::Exception::SetVerbose(TRI_ObjectToBoolean(args[0])); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } extern triagens::V8LineEditor* theConsole; @@ -605,7 +623,7 @@ extern triagens::V8LineEditor* theConsole; //////////////////////////////////////////////////////////////////////////////// static void JS_Debug (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::Local name(TRI_V8_ASCII_STRING("debug loop")); v8::Local debug(TRI_V8_ASCII_STRING("debug")); @@ -651,14 +669,15 @@ static void JS_Debug (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief compare two UTF 16 strings //////////////////////////////////////////////////////////////////////////////// -static void JS_compare_string (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); +static void JS_CompareString (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 2) { @@ -676,14 +695,15 @@ static void JS_compare_string (const v8::FunctionCallbackInfo& args) int result = Utf8Helper::DefaultUtf8Helper.compareUtf16(*left, left.length(), *right, right.length()); TRI_V8_RETURN(v8::Integer::New(isolate, result)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief get list of timezones //////////////////////////////////////////////////////////////////////////////// -static void JS_getIcuTimezones (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); +static void JS_GetIcuTimezones (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -708,14 +728,15 @@ static void JS_getIcuTimezones (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief get list of locales //////////////////////////////////////////////////////////////////////////////// -static void JS_getIcuLocales (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); +static void JS_GetIcuLocales (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -737,14 +758,15 @@ static void JS_getIcuLocales (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief format datetime //////////////////////////////////////////////////////////////////////////////// -static void JS_formatDatetime (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); +static void JS_FormatDatetime (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 2) { @@ -796,14 +818,15 @@ static void JS_formatDatetime (const v8::FunctionCallbackInfo& args) delete tz; TRI_V8_RETURN_STD_STRING(resultString); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief parse datetime //////////////////////////////////////////////////////////////////////////////// -static void JS_parseDatetime (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); +static void JS_ParseDatetime (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 2) { @@ -854,6 +877,7 @@ static void JS_parseDatetime (const v8::FunctionCallbackInfo& args) { delete tz; TRI_V8_RETURN(v8::Number::New(isolate, udate / 1000)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -888,12 +912,12 @@ static bool ReloadAuthCoordinator (TRI_vocbase_t* vocbase) { //////////////////////////////////////////////////////////////////////////////// static void JS_ReloadAuth (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); - if (vocbase == 0) { + if (vocbase == nullptr) { TRI_V8_THROW_EXCEPTION(TRI_ERROR_ARANGO_DATABASE_NOT_FOUND); } @@ -911,12 +935,10 @@ static void JS_ReloadAuth (const v8::FunctionCallbackInfo& args) { if (result) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } - // ----------------------------------------------------------------------------- // --SECTION-- AQL // ----------------------------------------------------------------------------- @@ -926,7 +948,7 @@ static void JS_ReloadAuth (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ParseAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -986,6 +1008,7 @@ static void JS_ParseAql (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -994,7 +1017,7 @@ static void JS_ParseAql (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_WarningAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 2) { @@ -1020,6 +1043,7 @@ static void JS_WarningAql (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1027,7 +1051,7 @@ static void JS_WarningAql (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ExplainAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -1116,6 +1140,7 @@ static void JS_ExplainAql (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1123,7 +1148,7 @@ static void JS_ExplainAql (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ExecuteAqlJson (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -1189,6 +1214,7 @@ static void JS_ExecuteAqlJson (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1196,7 +1222,8 @@ static void JS_ExecuteAqlJson (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_ExecuteAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); + v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -1287,6 +1314,7 @@ static void JS_ExecuteAql (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1294,7 +1322,7 @@ static void JS_ExecuteAql (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_QueriesPropertiesAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -1346,6 +1374,7 @@ static void JS_QueriesPropertiesAql (const v8::FunctionCallbackInfo& result->Set(TRI_V8_ASCII_STRING("maxQueryStringLength"), v8::Number::New(isolate, static_cast(queryList->maxQueryStringLength()))); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1353,7 +1382,7 @@ static void JS_QueriesPropertiesAql (const v8::FunctionCallbackInfo& //////////////////////////////////////////////////////////////////////////////// static void JS_QueriesCurrentAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -1395,6 +1424,7 @@ static void JS_QueriesCurrentAql (const v8::FunctionCallbackInfo& arg catch (...) { TRI_V8_THROW_EXCEPTION_MEMORY(); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1402,7 +1432,7 @@ static void JS_QueriesCurrentAql (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_QueriesSlowAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -1447,6 +1477,7 @@ static void JS_QueriesSlowAql (const v8::FunctionCallbackInfo& args) catch (...) { TRI_V8_THROW_EXCEPTION_MEMORY(); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1454,7 +1485,7 @@ static void JS_QueriesSlowAql (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_QueriesKillAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -1479,6 +1510,7 @@ static void JS_QueriesKillAql (const v8::FunctionCallbackInfo& args) } TRI_V8_THROW_EXCEPTION(res); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1486,14 +1518,16 @@ static void JS_QueriesKillAql (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_QueryIsKilledAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_GET_GLOBALS(); if (v8g->_query != nullptr && static_cast(v8g->_query)->killed()) { TRI_V8_RETURN_TRUE(); } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1632,40 +1666,31 @@ static ExplicitTransaction* BeginTransaction (TRI_vocbase_t* vocbase, bool waitForSync = false; // Start Transaction to collect all parts of the path - ExplicitTransaction* trx = new ExplicitTransaction( + std::unique_ptr trx(new ExplicitTransaction( vocbase, readCollections, writeCollections, lockTimeout, waitForSync, embed - ); + )); int res = trx->begin(); if (res != TRI_ERROR_NO_ERROR) { trx->finish(res); - delete trx; throw res; } - try { - // Get all ditches at once - for (auto const& it : readCollections) { - AddDitch(trx, it, ditches); - } - for (auto const& it : writeCollections) { - AddDitch(trx, it, ditches); - } - } - catch (int&) { - // Could not get a ditch - // Abort the collection and free the pointers - trx->abort(); - delete trx; - throw; + // Get all ditches at once + for (auto const& it : readCollections) { + AddDitch(trx.get(), it, ditches); } - return trx; + for (auto const& it : writeCollections) { + AddDitch(trx.get(), it, ditches); + } + + return trx.release(); } //////////////////////////////////////////////////////////////////////////////// @@ -1692,16 +1717,16 @@ static v8::Handle PathIdsToV8 (v8::Isolate* isolate, ExtractCidsFromPath(vocbase, p, readCollections); vector writeCollections; unordered_map ditches; - ExplicitTransaction* trx = BeginTransaction(vocbase, readCollections, - writeCollections, resolver, ditches); + + std::unique_ptr trx(BeginTransaction(vocbase, readCollections, + writeCollections, resolver, ditches)); for (uint32_t j = 0; j < vn; ++j) { - vertices->Set(j, VertexIdToData(isolate, resolver, trx, ditches, p.vertices[j])); + vertices->Set(j, VertexIdToData(isolate, resolver, trx.get(), ditches, p.vertices[j])); } for (uint32_t j = 0; j < en; ++j) { - edges->Set(j, EdgeIdToData(isolate, resolver, trx, ditches, p.edges[j])); + edges->Set(j, EdgeIdToData(isolate, resolver, trx.get(), ditches, p.edges[j])); } - trx->finish(0); - delete trx; + trx->finish(TRI_ERROR_NO_ERROR); } else { for (uint32_t j = 0; j < vn; ++j) { @@ -1821,7 +1846,7 @@ static VertexId IdStringToVertexId (CollectionNameResolver const* resolver, throw TRI_ERROR_ARANGO_INVALID_KEY_GENERATOR; } - string collectionName = vertex.substr(0, split); + string const collectionName = vertex.substr(0, split); auto coli = resolver->getCollectionStruct(collectionName); if (coli == nullptr) { @@ -1836,7 +1861,7 @@ static VertexId IdStringToVertexId (CollectionNameResolver const* resolver, //////////////////////////////////////////////////////////////////////////////// static void JS_QueryShortestPath (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 4 || args.Length() > 5) { @@ -1924,18 +1949,18 @@ static void JS_QueryShortestPath (const v8::FunctionCallbackInfo& arg } // Parse filterEdges + // note: only works with edge examples and not with user-defined AQL functions v8::Local keyFilterEdges = TRI_V8_ASCII_STRING("filterEdges"); if (options->Has(keyFilterEdges)) { opts.useEdgeFilter = true; - // TODO: User defined AQL function !! edgeExample = v8::Handle::Cast(options->Get(keyFilterEdges)); } // Parse vertexFilter + // note: only works with vertex examples and not with user-defined AQL functions v8::Local keyFilterVertices = TRI_V8_ASCII_STRING("filterVertices"); if (options->Has(keyFilterVertices)) { opts.useVertexFilter = true; - // TODO: User defined AQL function !! vertexExample = v8::Handle::Cast(options->Get(keyFilterVertices)); } } @@ -1957,25 +1982,21 @@ static void JS_QueryShortestPath (const v8::FunctionCallbackInfo& arg // Start the transaction and order ditches unordered_map ditches; - ExplicitTransaction* trx = nullptr; - try { - trx = BeginTransaction(vocbase, readCollections, writeCollections, resolver, ditches); - } - catch (int e) { - // Nothing to clean up. Throw the error to V8 - TRI_V8_THROW_EXCEPTION(e); - } + std::unique_ptr trx(BeginTransaction(vocbase, readCollections, writeCollections, resolver, ditches)); vector edgeCollectionInfos; vector vertexCollectionInfos; - - auto cleanup = [&] () -> void { - for (auto& p : edgeCollectionInfos) { - delete p; - } - for (auto& p : vertexCollectionInfos) { - delete p; + + triagens::basics::ScopeGuard guard{ + []() -> void { }, + [&edgeCollectionInfos, &vertexCollectionInfos]() -> void { + for (auto& p : edgeCollectionInfos) { + delete p; + } + for (auto& p : vertexCollectionInfos) { + delete p; + } } }; @@ -2022,7 +2043,7 @@ static void JS_QueryShortestPath (const v8::FunctionCallbackInfo& arg catch (int e) { // ELEMENT not found is expected, if there is no shape of this type in this collection if (e != TRI_RESULT_ELEMENT_NOT_FOUND) { - // TODO Max fragen was mit Fehlern passieren muss + TRI_V8_THROW_EXCEPTION(e); } } } @@ -2032,13 +2053,12 @@ static void JS_QueryShortestPath (const v8::FunctionCallbackInfo& arg string errorMessage; for (auto const& it: vertexCollectionInfos) { try { - opts.addVertexFilter(isolate, vertexExample, trx, it->getCollection(), it->getShaper(), it->getCid(), errorMessage); + opts.addVertexFilter(isolate, vertexExample, trx.get(), it->getCollection(), it->getShaper(), it->getCid(), errorMessage); } catch (int e) { - cout << "ARG!!!" << endl; // ELEMENT not found is expected, if there is no shape of this type in this collection if (e != TRI_RESULT_ELEMENT_NOT_FOUND) { - // TODO Max fragen was mit Fehlern passieren muss + TRI_V8_THROW_EXCEPTION(e); } } } @@ -2051,8 +2071,6 @@ static void JS_QueryShortestPath (const v8::FunctionCallbackInfo& arg catch (int e) { // Id string might have illegal collection name trx->finish(e); - cleanup(); - delete trx; TRI_V8_THROW_EXCEPTION(e); } @@ -2067,8 +2085,6 @@ static void JS_QueryShortestPath (const v8::FunctionCallbackInfo& arg } catch (int e) { trx->finish(e); - cleanup(); - delete trx; TRI_V8_THROW_EXCEPTION(e); } @@ -2076,19 +2092,20 @@ static void JS_QueryShortestPath (const v8::FunctionCallbackInfo& arg if (path.get() == nullptr) { v8::EscapableHandleScope scope(isolate); trx->finish(res); - cleanup(); - delete trx; TRI_V8_RETURN(scope.Escape(v8::Null(isolate))); } + trx->finish(res); - cleanup(); - delete trx; + // must finish "old" transaction first before starting a new in PathIdsToV8 + delete trx.release(); + // Potential inconsistency here. Graph is outside a transaction in this very second. // Adding additional locks on vertex collections at this point to the transaction // would cause dead-locks. // Will be fixed automatically with new MVCC version. auto result = PathIdsToV8(isolate, vocbase, resolver, *path, ditches, includeData); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2123,7 +2140,7 @@ static v8::Handle VertexIdsToV8 (v8::Isolate* isolate, //////////////////////////////////////////////////////////////////////////////// static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 3 || args.Length() > 4) { @@ -2215,7 +2232,7 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) v8::Local keyFilterVertices = TRI_V8_ASCII_STRING("filterVertices"); if (options->Has(keyFilterVertices)) { opts.useVertexFilter = true; - // TODO: User defined AQL function !! + // note: only works with vertex examples and not with user-defined AQL functions vertexExample = v8::Handle::Cast(options->Get(keyFilterVertices)); } @@ -2237,7 +2254,6 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) V8ResolverGuard resolverGuard(vocbase); - ExplicitTransaction* trx = nullptr; int res = TRI_ERROR_NO_ERROR; CollectionNameResolver const* resolver = resolverGuard.getResolver(); @@ -2250,16 +2266,23 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) unordered_map ditches; // Start the transaction - try { - trx = BeginTransaction(vocbase, readCollections, writeCollections, - resolver, ditches); - } - catch (int e) { - // Nothing to clean up. Throw the error to V8 - TRI_V8_THROW_EXCEPTION(e); - } - + std::unique_ptr trx(BeginTransaction(vocbase, readCollections, writeCollections, resolver, ditches)); + vector edgeCollectionInfos; + vector vertexCollectionInfos; + + triagens::basics::ScopeGuard guard{ + []() -> void { }, + [&edgeCollectionInfos, &vertexCollectionInfos]() -> void { + for (auto& p : edgeCollectionInfos) { + delete p; + } + for (auto& p : vertexCollectionInfos) { + delete p; + } + } + }; + for (auto const& it : edgeCollectionNames) { auto cid = resolver->getCollectionId(it); auto colObj = ditches.find(cid)->second.col->_collection->_collection; @@ -2270,8 +2293,7 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) )); } - vector vertexCollectionInfos; - for(auto it : vertexCollectionNames) { + for (auto it : vertexCollectionNames) { auto cid = resolver->getCollectionId(it); auto colObj = ditches.find(cid)->second.col; vertexCollectionInfos.emplace_back(new VertexCollectionInfo( @@ -2281,14 +2303,6 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) // Explicitly allow all collections. opts.addCollectionRestriction(cid); } - auto cleanup = [&] () -> void { - for (auto& p : edgeCollectionInfos) { - delete p; - } - for (auto& p : vertexCollectionInfos) { - delete p; - } - }; unordered_set distinctNeighbors; vector neighbors; @@ -2302,7 +2316,7 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) catch (int e) { // ELEMENT not found is expected, if there is no shape of this type in this collection if (e != TRI_RESULT_ELEMENT_NOT_FOUND) { - // TODO Max fragen was mit Fehlern passieren muss + TRI_V8_THROW_EXCEPTION(e); } } } @@ -2312,12 +2326,12 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) string errorMessage; for (auto const& it: vertexCollectionInfos) { try { - opts.addVertexFilter(isolate, vertexExample, trx, it->getCollection(), it->getShaper(), it->getCid(), errorMessage); + opts.addVertexFilter(isolate, vertexExample, trx.get(), it->getCollection(), it->getShaper(), it->getCid(), errorMessage); } catch (int e) { // ELEMENT not found is expected, if there is no shape of this type in this collection if (e != TRI_RESULT_ELEMENT_NOT_FOUND) { - // TODO Max fragen was mit Fehlern passieren muss + TRI_V8_THROW_EXCEPTION(e); } } } @@ -2329,9 +2343,7 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) } catch (int e) { // Id string might have illegal collection name - cleanup(); trx->finish(e); - delete trx; TRI_V8_THROW_EXCEPTION(e); } try { @@ -2343,19 +2355,17 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) ); } catch (int e) { - cleanup(); trx->finish(e); - delete trx; TRI_V8_THROW_EXCEPTION(e); } } - auto result = VertexIdsToV8(isolate, trx, resolver, neighbors, ditches, includeData); + auto result = VertexIdsToV8(isolate, trx.get(), resolver, neighbors, ditches, includeData); - cleanup(); trx->finish(res); - delete trx; + TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2363,7 +2373,7 @@ static void JS_QueryNeighbors (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_QuerySleepAql (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -2393,6 +2403,7 @@ static void JS_QuerySleepAql (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -3308,7 +3319,7 @@ static void JS_DropDatabase (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ConfigureEndpoint (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1 || args.Length() > 2) { @@ -3372,6 +3383,7 @@ static void JS_ConfigureEndpoint (const v8::FunctionCallbackInfo& arg } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3381,7 +3393,7 @@ static void JS_ConfigureEndpoint (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_RemoveEndpoint (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1 || args.Length() > 2) { @@ -3414,6 +3426,7 @@ static void JS_RemoveEndpoint (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3423,7 +3436,7 @@ static void JS_RemoveEndpoint (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_ListEndpoints (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -3470,6 +3483,7 @@ static void JS_ListEndpoints (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -3691,12 +3705,12 @@ void TRI_InitV8VocBridge (v8::Isolate* isolate, TRI_InitV8Replication(isolate, context, server, vocbase, loader, threadNumber, v8g); - TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("COMPARE_STRING"), JS_compare_string); - TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("NORMALIZE_STRING"), JS_normalize_string); - TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("TIMEZONES"), JS_getIcuTimezones); - TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("LOCALES"), JS_getIcuLocales); - TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FORMAT_DATETIME"), JS_formatDatetime); - TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("PARSE_DATETIME"), JS_parseDatetime); + TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("COMPARE_STRING"), JS_CompareString); + TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("NORMALIZE_STRING"), JS_NormalizeString); + TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("TIMEZONES"), JS_GetIcuTimezones); + TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("LOCALES"), JS_GetIcuLocales); + TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("FORMAT_DATETIME"), JS_FormatDatetime); + TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("PARSE_DATETIME"), JS_ParseDatetime); TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("CONFIGURE_ENDPOINT"), JS_ConfigureEndpoint, true); TRI_AddGlobalFunctionVocbase(isolate, context, TRI_V8_ASCII_STRING("REMOVE_ENDPOINT"), JS_RemoveEndpoint, true); diff --git a/arangod/V8Server/v8-voccursor.cpp b/arangod/V8Server/v8-voccursor.cpp index 8a22349a38..5162d1633f 100644 --- a/arangod/V8Server/v8-voccursor.cpp +++ b/arangod/V8Server/v8-voccursor.cpp @@ -49,7 +49,7 @@ using namespace triagens::rest; //////////////////////////////////////////////////////////////////////////////// static void JS_CreateCursor (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -110,6 +110,7 @@ static void JS_CreateCursor (const v8::FunctionCallbackInfo& args) { catch (...) { TRI_V8_THROW_EXCEPTION_MEMORY(); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -117,7 +118,7 @@ static void JS_CreateCursor (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_JsonCursor (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_vocbase_t* vocbase = GetContextVocBase(isolate); @@ -197,6 +198,7 @@ static void JS_JsonCursor (const v8::FunctionCallbackInfo& args) { cursors->release(cursor); TRI_V8_THROW_EXCEPTION_MEMORY(); } + TRI_V8_TRY_CATCH_END } // ............................................................................. diff --git a/arangod/V8Server/v8-vocindex.cpp b/arangod/V8Server/v8-vocindex.cpp index 5e2e33111b..558773772c 100644 --- a/arangod/V8Server/v8-vocindex.cpp +++ b/arangod/V8Server/v8-vocindex.cpp @@ -1146,12 +1146,13 @@ static void CreateCollectionCoordinator (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); PREVENT_EMBEDDED_TRANSACTION(); EnsureIndex(args, true, "ensureIndex"); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1159,10 +1160,11 @@ static void JS_EnsureIndexVocbaseCol (const v8::FunctionCallbackInfo& //////////////////////////////////////////////////////////////////////////////// static void JS_LookupIndexVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); EnsureIndex(args, false, "lookupIndex"); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief drops an index, coordinator case @@ -1215,9 +1217,7 @@ static void DropIndexCoordinator (const v8::FunctionCallbackInfo& arg if (res == TRI_ERROR_NO_ERROR) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); } //////////////////////////////////////////////////////////////////////////////// @@ -1262,10 +1262,9 @@ static void DropIndexCoordinator (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_DropIndexVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - PREVENT_EMBEDDED_TRANSACTION(); TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); @@ -1323,6 +1322,7 @@ static void JS_DropIndexVocbaseCol (const v8::FunctionCallbackInfo& a } TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1405,10 +1405,9 @@ static void GetIndexesCoordinator (const v8::FunctionCallbackInfo& ar //////////////////////////////////////////////////////////////////////////////// static void JS_GetIndexesVocbaseCol (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - TRI_vocbase_col_t* collection = TRI_UnwrapClass(args.Holder(), WRP_VOCBASE_COL_TYPE); if (collection == nullptr) { @@ -1456,6 +1455,7 @@ static void JS_GetIndexesVocbaseCol (const v8::FunctionCallbackInfo& TRI_FreeVectorPointer(TRI_UNKNOWN_MEM_ZONE, indexes); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1527,7 +1527,6 @@ static void CreateVocBase (const v8::FunctionCallbackInfo& args, v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope scope(isolate); - TRI_vocbase_t* vocbase = GetContextVocBase(isolate); if (vocbase == nullptr) { @@ -1819,7 +1818,9 @@ static void CreateVocBase (const v8::FunctionCallbackInfo& args, //////////////////////////////////////////////////////////////////////////////// static void JS_CreateVocbase (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); CreateVocBase(args, TRI_COL_TYPE_DOCUMENT); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1833,7 +1834,9 @@ static void JS_CreateVocbase (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_CreateDocumentCollectionVocbase (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); CreateVocBase(args, TRI_COL_TYPE_DOCUMENT); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1860,25 +1863,25 @@ static void JS_CreateDocumentCollectionVocbase (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); CreateVocBase(args, TRI_COL_TYPE_EDGE); + TRI_V8_TRY_CATCH_END } void TRI_InitV8indexArangoDB (v8::Isolate* isolate, - v8::Handle rt){ + v8::Handle rt) { TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("_create"), JS_CreateVocbase, true); TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("_createEdgeCollection"), JS_CreateEdgeCollectionVocbase); TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("_createDocumentCollection"), JS_CreateDocumentCollectionVocbase); - } void TRI_InitV8indexCollection (v8::Isolate* isolate, - v8::Handle rt){ + v8::Handle rt) { TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("dropIndex"), JS_DropIndexVocbaseCol); TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("ensureIndex"), JS_EnsureIndexVocbaseCol); TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("lookupIndex"), JS_LookupIndexVocbaseCol); TRI_AddMethodVocbase(isolate, rt, TRI_V8_ASCII_STRING("getIndexes"), JS_GetIndexesVocbaseCol); - } diff --git a/arangod/V8Server/v8-wrapshapedjson.cpp b/arangod/V8Server/v8-wrapshapedjson.cpp index 05bdae48c5..23a84ca8ad 100644 --- a/arangod/V8Server/v8-wrapshapedjson.cpp +++ b/arangod/V8Server/v8-wrapshapedjson.cpp @@ -517,91 +517,96 @@ static void CopyAttributes (v8::Isolate* isolate, static void MapGetNamedShapedJson (v8::Local name, const v8::PropertyCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope scope(isolate); + try { + v8::HandleScope scope(isolate); - // sanity check - v8::Handle self = args.Holder(); + // sanity check + v8::Handle self = args.Holder(); - if (self->InternalFieldCount() <= SLOT_DITCH) { - // we better not throw here... otherwise this will cause a segfault - TRI_V8_RETURN(v8::Handle()); - } - - // get shaped json - void* marker = TRI_UnwrapClass(self, WRP_SHAPED_JSON_TYPE); - - if (marker == nullptr) { - TRI_V8_RETURN(v8::Handle()); - } - - // convert the JavaScript string to a string - // we take the fast path here and don't normalize the string - v8::String::Utf8Value const str(name); - string const key(*str, (size_t) str.length()); - - if (key.empty()) { - TRI_V8_RETURN(v8::Handle()); - } - - if (key[0] == '_') { - char buffer[TRI_VOC_KEY_MAX_LENGTH + 1]; - - if (key == TRI_VOC_ATTRIBUTE_KEY) { - char const* docKey = TRI_EXTRACT_MARKER_KEY(static_cast(marker)); - TRI_ASSERT(docKey != nullptr); - size_t keyLength = strlen(docKey); - memcpy(buffer, docKey, keyLength); - TRI_V8_RETURN_PAIR_STRING(buffer, (int) keyLength); - } - else if (key == TRI_VOC_ATTRIBUTE_REV) { - TRI_voc_rid_t rid = TRI_EXTRACT_MARKER_RID(static_cast(marker)); - TRI_ASSERT(rid > 0); - size_t len = TRI_StringUInt64InPlace((uint64_t) rid, (char*) &buffer); - TRI_V8_RETURN_PAIR_STRING((char const*) buffer, (int) len); - } - - if (key == TRI_VOC_ATTRIBUTE_ID || - key == TRI_VOC_ATTRIBUTE_FROM || - key == TRI_VOC_ATTRIBUTE_TO) { - // strip reserved attributes + if (self->InternalFieldCount() <= SLOT_DITCH) { + // we better not throw here... otherwise this will cause a segfault TRI_V8_RETURN(v8::Handle()); } - } - // TODO: check whether accessing an attribute with a dot is actually possible, - // e.g. doc.a.b vs. doc["a.b"] - if (strchr(key.c_str(), '.') != nullptr) { + // get shaped json + void* marker = TRI_UnwrapClass(self, WRP_SHAPED_JSON_TYPE); + + if (marker == nullptr) { + TRI_V8_RETURN(v8::Handle()); + } + + // convert the JavaScript string to a string + // we take the fast path here and don't normalize the string + v8::String::Utf8Value const str(name); + string const key(*str, (size_t) str.length()); + + if (key.empty()) { + TRI_V8_RETURN(v8::Handle()); + } + + if (key[0] == '_') { + char buffer[TRI_VOC_KEY_MAX_LENGTH + 1]; + + if (key == TRI_VOC_ATTRIBUTE_KEY) { + char const* docKey = TRI_EXTRACT_MARKER_KEY(static_cast(marker)); + TRI_ASSERT(docKey != nullptr); + size_t keyLength = strlen(docKey); + memcpy(buffer, docKey, keyLength); + TRI_V8_RETURN_PAIR_STRING(buffer, (int) keyLength); + } + else if (key == TRI_VOC_ATTRIBUTE_REV) { + TRI_voc_rid_t rid = TRI_EXTRACT_MARKER_RID(static_cast(marker)); + TRI_ASSERT(rid > 0); + size_t len = TRI_StringUInt64InPlace((uint64_t) rid, (char*) &buffer); + TRI_V8_RETURN_PAIR_STRING((char const*) buffer, (int) len); + } + + if (key == TRI_VOC_ATTRIBUTE_ID || + key == TRI_VOC_ATTRIBUTE_FROM || + key == TRI_VOC_ATTRIBUTE_TO) { + // strip reserved attributes + TRI_V8_RETURN(v8::Handle()); + } + } + + // TODO: check whether accessing an attribute with a dot is actually possible, + // e.g. doc.a.b vs. doc["a.b"] + if (strchr(key.c_str(), '.') != nullptr) { + TRI_V8_RETURN(v8::Handle()); + } + + // get the underlying collection + auto ditch = static_cast(v8::Handle::Cast(self->GetInternalField(SLOT_DITCH))->Value()); + TRI_ASSERT(ditch != nullptr); + + TRI_document_collection_t* collection = ditch->collection(); + + // get shape accessor + TRI_shaper_t* shaper = collection->getShaper(); // PROTECTED by trx here + TRI_shape_pid_t pid = shaper->lookupAttributePathByName(shaper, key.c_str()); + + if (pid == 0) { + TRI_V8_RETURN(v8::Handle()); + } + + TRI_shaped_json_t document; + TRI_EXTRACT_SHAPED_JSON_MARKER(document, marker); + + TRI_shaped_json_t json; + TRI_shape_t const* shape; + + bool ok = TRI_ExtractShapedJsonVocShaper(shaper, &document, 0, pid, &json, &shape); + + if (ok && shape != nullptr) { + TRI_V8_RETURN(TRI_JsonShapeData(isolate, shaper, shape, json._data.data, json._data.length)); + } + + // we must not throw a v8 exception here because this will cause follow up errors TRI_V8_RETURN(v8::Handle()); } - - // get the underlying collection - auto ditch = static_cast(v8::Handle::Cast(self->GetInternalField(SLOT_DITCH))->Value()); - TRI_ASSERT(ditch != nullptr); - - TRI_document_collection_t* collection = ditch->collection(); - - // get shape accessor - TRI_shaper_t* shaper = collection->getShaper(); // PROTECTED by trx here - TRI_shape_pid_t pid = shaper->lookupAttributePathByName(shaper, key.c_str()); - - if (pid == 0) { + catch (...) { TRI_V8_RETURN(v8::Handle()); } - - TRI_shaped_json_t document; - TRI_EXTRACT_SHAPED_JSON_MARKER(document, marker); - - TRI_shaped_json_t json; - TRI_shape_t const* shape; - - bool ok = TRI_ExtractShapedJsonVocShaper(shaper, &document, 0, pid, &json, &shape); - - if (ok && shape != nullptr) { - TRI_V8_RETURN(TRI_JsonShapeData(isolate, shaper, shape, json._data.data, json._data.length)); - } - - // we must not throw a v8 exception here because this will cause follow up errors - TRI_V8_RETURN(v8::Handle()); } //////////////////////////////////////////////////////////////////////////////// @@ -614,38 +619,43 @@ static void MapSetNamedShapedJson (v8::Local name, v8::Local value, const v8::PropertyCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope scope(isolate); + try { + v8::HandleScope scope(isolate); - // sanity check - v8::Handle self = args.Holder(); + // sanity check + v8::Handle self = args.Holder(); - if (self->InternalFieldCount() <= SLOT_DITCH) { - // we better not throw here... otherwise this will cause a segfault - TRI_V8_RETURN(v8::Handle()); - } + if (self->InternalFieldCount() <= SLOT_DITCH) { + // we better not throw here... otherwise this will cause a segfault + TRI_V8_RETURN(v8::Handle()); + } - // get shaped json - void* marker = TRI_UnwrapClass(self, WRP_SHAPED_JSON_TYPE); + // get shaped json + void* marker = TRI_UnwrapClass(self, WRP_SHAPED_JSON_TYPE); - if (marker == nullptr) { - return; - } + if (marker == nullptr) { + return; + } - if (self->HasRealNamedProperty(name)) { - // object already has the property. use the regular property setter + if (self->HasRealNamedProperty(name)) { + // object already has the property. use the regular property setter + self->ForceSet(name, value); + TRI_V8_RETURN_TRUE(); + } + + // copy all attributes from the shaped json into the object + CopyAttributes(isolate, self, marker); + + // remove pointer to marker, so the object becomes stand-alone + self->SetInternalField(SLOT_CLASS, v8::External::New(isolate, nullptr)); + + // and now use the regular property setter self->ForceSet(name, value); TRI_V8_RETURN_TRUE(); } - - // copy all attributes from the shaped json into the object - CopyAttributes(isolate, self, marker); - - // remove pointer to marker, so the object becomes stand-alone - self->SetInternalField(SLOT_CLASS, v8::External::New(isolate, nullptr)); - - // and now use the regular property setter - self->ForceSet(name, value); - TRI_V8_RETURN_TRUE(); + catch (...) { + TRI_V8_RETURN(v8::Handle()); + } } //////////////////////////////////////////////////////////////////////////////// @@ -657,32 +667,37 @@ static void MapSetNamedShapedJson (v8::Local name, static void MapDeleteNamedShapedJson (v8::Local name, const v8::PropertyCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope scope(isolate); - - // sanity check - v8::Handle self = args.Holder(); + try { + v8::HandleScope scope(isolate); + + // sanity check + v8::Handle self = args.Holder(); - if (self->InternalFieldCount() <= SLOT_DITCH) { - // we better not throw here... otherwise this will cause a segfault - return; - } + if (self->InternalFieldCount() <= SLOT_DITCH) { + // we better not throw here... otherwise this will cause a segfault + return; + } - // get shaped json - void* marker = TRI_UnwrapClass(self, WRP_SHAPED_JSON_TYPE); + // get shaped json + void* marker = TRI_UnwrapClass(self, WRP_SHAPED_JSON_TYPE); + + if (marker == nullptr) { + self->ForceDelete(name); + TRI_V8_RETURN_TRUE(); + } + + // copy all attributes from the shaped json into the object + CopyAttributes(isolate, self, marker); + + // remove pointer to marker, so the object becomes stand-alone + self->SetInternalField(SLOT_CLASS, v8::External::New(isolate, nullptr)); - if (marker == nullptr) { self->ForceDelete(name); TRI_V8_RETURN_TRUE(); } - - // copy all attributes from the shaped json into the object - CopyAttributes(isolate, self, marker); - - // remove pointer to marker, so the object becomes stand-alone - self->SetInternalField(SLOT_CLASS, v8::External::New(isolate, nullptr)); - - self->ForceDelete(name); - TRI_V8_RETURN_TRUE(); + catch (...) { + return; + } } //////////////////////////////////////////////////////////////////////////////// @@ -692,70 +707,75 @@ static void MapDeleteNamedShapedJson (v8::Local name, static void PropertyQueryShapedJson (v8::Local name, const v8::PropertyCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); - v8::HandleScope scope(isolate); + try { + v8::HandleScope scope(isolate); - v8::Handle self = args.Holder(); + v8::Handle self = args.Holder(); - // sanity check - if (self->InternalFieldCount() <= SLOT_DITCH) { - TRI_V8_RETURN(v8::Handle()); - } - - // get shaped json - void* marker = TRI_UnwrapClass(self, WRP_SHAPED_JSON_TYPE); - - if (marker == nullptr) { - TRI_V8_RETURN(v8::Handle()); - } - - // convert the JavaScript string to a string - string const&& key = TRI_ObjectToString(name); - - if (key.empty()) { - TRI_V8_RETURN(v8::Handle()); - } - - if (key[0] == '_') { - if (key == TRI_VOC_ATTRIBUTE_KEY || - key == TRI_VOC_ATTRIBUTE_REV || - key == TRI_VOC_ATTRIBUTE_ID || - key == TRI_VOC_ATTRIBUTE_FROM || - key == TRI_VOC_ATTRIBUTE_TO) { - TRI_V8_RETURN(v8::Handle(v8::Integer::New(isolate, v8::None))); + // sanity check + if (self->InternalFieldCount() <= SLOT_DITCH) { + TRI_V8_RETURN(v8::Handle()); } - } - // get underlying collection - auto ditch = static_cast(v8::Handle::Cast(self->GetInternalField(SLOT_DITCH))->Value()); - TRI_document_collection_t* collection = ditch->collection(); + // get shaped json + void* marker = TRI_UnwrapClass(self, WRP_SHAPED_JSON_TYPE); - // get shape accessor - TRI_shaper_t* shaper = collection->getShaper(); // PROTECTED by BARRIER, checked by RUNTIME - TRI_shape_pid_t pid = shaper->lookupAttributePathByName(shaper, key.c_str()); + if (marker == nullptr) { + TRI_V8_RETURN(v8::Handle()); + } - if (pid == 0) { - TRI_V8_RETURN(v8::Handle()); - } + // convert the JavaScript string to a string + string const&& key = TRI_ObjectToString(name); - TRI_shape_sid_t sid; - TRI_EXTRACT_SHAPE_IDENTIFIER_MARKER(sid, marker); + if (key.empty()) { + TRI_V8_RETURN(v8::Handle()); + } - if (sid == TRI_SHAPE_ILLEGAL) { - // invalid shape + if (key[0] == '_') { + if (key == TRI_VOC_ATTRIBUTE_KEY || + key == TRI_VOC_ATTRIBUTE_REV || + key == TRI_VOC_ATTRIBUTE_ID || + key == TRI_VOC_ATTRIBUTE_FROM || + key == TRI_VOC_ATTRIBUTE_TO) { + TRI_V8_RETURN(v8::Handle(v8::Integer::New(isolate, v8::None))); + } + } + + // get underlying collection + auto ditch = static_cast(v8::Handle::Cast(self->GetInternalField(SLOT_DITCH))->Value()); + TRI_document_collection_t* collection = ditch->collection(); + + // get shape accessor + TRI_shaper_t* shaper = collection->getShaper(); // PROTECTED by BARRIER, checked by RUNTIME + TRI_shape_pid_t pid = shaper->lookupAttributePathByName(shaper, key.c_str()); + + if (pid == 0) { + TRI_V8_RETURN(v8::Handle()); + } + + TRI_shape_sid_t sid; + TRI_EXTRACT_SHAPE_IDENTIFIER_MARKER(sid, marker); + + if (sid == TRI_SHAPE_ILLEGAL) { + // invalid shape #ifdef TRI_ENABLE_MAINTAINER_MODE - LOG_WARNING("invalid shape id '%llu' found for key '%s'", (unsigned long long) sid, key.c_str()); + LOG_WARNING("invalid shape id '%llu' found for key '%s'", (unsigned long long) sid, key.c_str()); #endif + TRI_V8_RETURN(v8::Handle()); + } + + TRI_shape_access_t const* acc = TRI_FindAccessorVocShaper(shaper, sid, pid); + + // key not found + if (acc == nullptr || acc->_resultSid == TRI_SHAPE_ILLEGAL) { + TRI_V8_RETURN(v8::Handle()); + } + + TRI_V8_RETURN(v8::Handle(v8::Integer::New(isolate, v8::None))); + } + catch (...) { TRI_V8_RETURN(v8::Handle()); } - - TRI_shape_access_t const* acc = TRI_FindAccessorVocShaper(shaper, sid, pid); - - // key not found - if (acc == nullptr || acc->_resultSid == TRI_SHAPE_ILLEGAL) { - TRI_V8_RETURN(v8::Handle()); - } - - TRI_V8_RETURN(v8::Handle(v8::Integer::New(isolate, v8::None))); } //////////////////////////////////////////////////////////////////////////////// @@ -839,9 +859,9 @@ void TRI_InitV8ShapedJson (v8::Isolate *isolate, // accessor for indexed properties (e.g. doc[1]) rt->SetIndexedPropertyHandler(MapGetIndexedShapedJson, // IndexedPropertyGetter, MapSetIndexedShapedJson, // IndexedPropertySetter, - 0, // IndexedPropertyQuery, + nullptr, // IndexedPropertyQuery, MapDeleteIndexedShapedJson, // IndexedPropertyDeleter, - 0 // IndexedPropertyEnumerator, + nullptr // IndexedPropertyEnumerator, // Handle data = Handle()); ); diff --git a/arangod/VocBase/document-collection.h b/arangod/VocBase/document-collection.h index 1491bc34b5..944b2f0ea8 100644 --- a/arangod/VocBase/document-collection.h +++ b/arangod/VocBase/document-collection.h @@ -258,7 +258,7 @@ struct TRI_doc_mptr_copy_t : public TRI_doc_mptr_t { TRI_doc_mptr_copy_t (TRI_doc_mptr_copy_t&& that) { copy(that); } - + TRI_doc_mptr_copy_t&& operator= (TRI_doc_mptr_copy_t&& that) { copy(that); return std::move(*this); diff --git a/arangosh/V8Client/arangosh.cpp b/arangosh/V8Client/arangosh.cpp index 044f072030..f50795421d 100644 --- a/arangosh/V8Client/arangosh.cpp +++ b/arangosh/V8Client/arangosh.cpp @@ -210,7 +210,7 @@ static bool VoiceMode = false; //////////////////////////////////////////////////////////////////////////////// static void JS_PagerOutput (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); for (int i = 0; i < args.Length(); i++) { @@ -223,6 +223,7 @@ static void JS_PagerOutput (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -230,7 +231,7 @@ static void JS_PagerOutput (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_StartOutputPager (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (BaseClient.usePager()) { @@ -242,6 +243,7 @@ static void JS_StartOutputPager (const v8::FunctionCallbackInfo& args } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -249,7 +251,7 @@ static void JS_StartOutputPager (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_StopOutputPager (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (BaseClient.usePager()) { @@ -262,6 +264,7 @@ static void JS_StopOutputPager (const v8::FunctionCallbackInfo& args) BaseClient.setUsePager(false); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -283,10 +286,9 @@ static void JS_StopOutputPager (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_ImportCsvFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2) { TRI_V8_THROW_EXCEPTION_USAGE("importCsvFile(, [, ])"); } @@ -351,6 +353,7 @@ static void JS_ImportCsvFile (const v8::FunctionCallbackInfo& args) { } TRI_V8_THROW_EXCEPTION_MESSAGE(TRI_ERROR_FAILED, ih.getErrorMessage().c_str()); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -363,10 +366,9 @@ static void JS_ImportCsvFile (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ImportJsonFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() < 2) { TRI_V8_THROW_EXCEPTION_USAGE("importJsonFile(, )"); } @@ -401,13 +403,15 @@ static void JS_ImportJsonFile (const v8::FunctionCallbackInfo& args) } TRI_V8_THROW_EXCEPTION_MESSAGE(TRI_ERROR_FAILED, ih.getErrorMessage().c_str()); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief normalizes UTF 16 strings //////////////////////////////////////////////////////////////////////////////// -static void JS_normalize_string (const v8::FunctionCallbackInfo& args) { +static void JS_NormalizeString (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope scope(isolate); @@ -417,17 +421,17 @@ static void JS_normalize_string (const v8::FunctionCallbackInfo& args } TRI_normalize_V8_Obj(args, args[0]); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// /// @brief compare two UTF 16 strings //////////////////////////////////////////////////////////////////////////////// -static void JS_compare_string (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); +static void JS_CompareString (const v8::FunctionCallbackInfo& args) { + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); - if (args.Length() != 2) { TRI_V8_THROW_EXCEPTION_USAGE("COMPARE_STRING(, )"); } @@ -438,6 +442,7 @@ static void JS_compare_string (const v8::FunctionCallbackInfo& args) int result = Utf8Helper::DefaultUtf8Helper.compareUtf16(*left, left.length(), *right, right.length()); TRI_V8_RETURN(v8::Integer::New(isolate, result)); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -2217,8 +2222,8 @@ static void InitCallbacks (v8::Isolate *isolate, TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("SYS_STOP_PAGER"), v8::FunctionTemplate::New(isolate, JS_StopOutputPager)->GetFunction()); TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("SYS_IMPORT_CSV_FILE"), v8::FunctionTemplate::New(isolate, JS_ImportCsvFile)->GetFunction()); TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("SYS_IMPORT_JSON_FILE"), v8::FunctionTemplate::New(isolate, JS_ImportJsonFile)->GetFunction()); - TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("NORMALIZE_STRING"), v8::FunctionTemplate::New(isolate, JS_normalize_string)->GetFunction()); - TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("COMPARE_STRING"), v8::FunctionTemplate::New(isolate, JS_compare_string)->GetFunction()); + TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("NORMALIZE_STRING"), v8::FunctionTemplate::New(isolate, JS_NormalizeString)->GetFunction()); + TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("COMPARE_STRING"), v8::FunctionTemplate::New(isolate, JS_CompareString)->GetFunction()); TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("ARANGO_QUIET"), v8::Boolean::New(isolate, BaseClient.quiet())); TRI_AddGlobalVariableVocbase(isolate, context, TRI_V8_ASCII_STRING("VALGRIND"), v8::Boolean::New(isolate, (RUNNING_ON_VALGRIND > 0))); @@ -2330,7 +2335,7 @@ static int Run (v8::Isolate* isolate, eRunMode runMode, bool promptError) { cerr << "caught unknown exception" << endl; ok = false; } - return (ok)? EXIT_SUCCESS : EXIT_FAILURE; + return (ok) ? EXIT_SUCCESS : EXIT_FAILURE; } class BufferAllocator : public v8::ArrayBuffer::Allocator { @@ -2483,7 +2488,17 @@ int main (int argc, char* args[]) { if (ret == EXIT_SUCCESS) { BaseClient.openLog(); - ret = Run(isolate, runMode, promptError); + try { + ret = Run(isolate, runMode, promptError); + } + catch (std::bad_alloc const&) { + LOG_ERROR("caught exception %s", TRI_errno_string(TRI_ERROR_OUT_OF_MEMORY)); + ret = EXIT_FAILURE; + } + catch (...) { + LOG_ERROR("caught unknown exception"); + ret = EXIT_FAILURE; + } } isolate->LowMemoryNotification(); diff --git a/js/server/tests/aql-general-graph.js b/js/server/tests/aql-general-graph.js index 962b8d789e..fe72dd7665 100644 --- a/js/server/tests/aql-general-graph.js +++ b/js/server/tests/aql-general-graph.js @@ -2716,6 +2716,7 @@ function ahuacatlQueryMultiCollectionMadnessTestSuite() { //////////////////////////////////////////////////////////////////////////////// /// @brief executes the test suite //////////////////////////////////////////////////////////////////////////////// + jsunity.run(ahuacatlQueryGeneralCommonTestSuite); jsunity.run(ahuacatlQueryGeneralCyclesSuite); jsunity.run(ahuacatlQueryGeneralTraversalTestSuite); diff --git a/lib/Basics/StringBuffer.h b/lib/Basics/StringBuffer.h index 9767f38028..ad69a7a65f 100644 --- a/lib/Basics/StringBuffer.h +++ b/lib/Basics/StringBuffer.h @@ -524,6 +524,15 @@ namespace triagens { return *this; } +//////////////////////////////////////////////////////////////////////////////// +/// @brief appends string +//////////////////////////////////////////////////////////////////////////////// + + StringBuffer& appendText (std::string&& str) { + TRI_AppendString2StringBuffer(&_buffer, str.c_str(), str.length()); + return *this; + } + //////////////////////////////////////////////////////////////////////////////// /// @brief appends a string buffer //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/V8/V8LineEditor.cpp b/lib/V8/V8LineEditor.cpp index b1c8069a1f..742f2d4b91 100644 --- a/lib/V8/V8LineEditor.cpp +++ b/lib/V8/V8LineEditor.cpp @@ -255,10 +255,16 @@ void V8Completer::getAlternatives (char const * text, if (funcVal->IsFunction()) { v8::Handle func = v8::Handle::Cast(funcVal); v8::Handle args; - v8::Handle cpls = func->Call(current, 0, &args); - if (cpls->IsArray()) { - properties = v8::Handle::Cast(cpls); + try { + v8::Handle cpls = func->Call(current, 0, &args); + + if (cpls->IsArray()) { + properties = v8::Handle::Cast(cpls); + } + } + catch (...) { + // silently ignore errors here } } } diff --git a/lib/V8/v8-globals.h b/lib/V8/v8-globals.h index 8c2d593e0a..6ebed84baa 100644 --- a/lib/V8/v8-globals.h +++ b/lib/V8/v8-globals.h @@ -58,6 +58,30 @@ static const uint32_t V8DataSlot = 0; #define ISOLATE v8::Isolate* isolate = v8::Isolate::GetCurrent() +//////////////////////////////////////////////////////////////////////////////// +/// @brief macro to initiate a try-catch sequence for V8 callbacks +//////////////////////////////////////////////////////////////////////////////// + +#define TRI_V8_TRY_CATCH_BEGIN(isolateVar) \ + auto isolateVar = args.GetIsolate(); \ + try { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief macro to terminate a try-catch sequence for V8 callbacks +//////////////////////////////////////////////////////////////////////////////// + +#define TRI_V8_TRY_CATCH_END \ + } \ + catch (triagens::basics::Exception const& ex) { \ + TRI_V8_THROW_EXCEPTION_MESSAGE(ex.code(), ex.what()); \ + } \ + catch (std::exception const& ex) { \ + TRI_V8_THROW_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, ex.what()); \ + } \ + catch (...) { \ + TRI_V8_THROW_EXCEPTION(TRI_ERROR_INTERNAL); \ + } + //////////////////////////////////////////////////////////////////////////////// /// @brief shortcut for creating a v8 symbol for the specified string /// implicites isolate available. diff --git a/lib/V8/v8-shell.cpp b/lib/V8/v8-shell.cpp index 29f5937800..cebcd70435 100644 --- a/lib/V8/v8-shell.cpp +++ b/lib/V8/v8-shell.cpp @@ -31,6 +31,7 @@ #include "Basics/conversions.h" #include "Basics/csv.h" +#include "Basics/Exceptions.h" #include "Basics/logging.h" #include "Basics/shell-colors.h" #include "Basics/string-buffer.h" @@ -120,7 +121,7 @@ static void ProcessCsvEnd (TRI_csv_parser_t* parser, const char* field, size_t, //////////////////////////////////////////////////////////////////////////////// static void JS_ProcessCsvFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 2) { @@ -216,6 +217,7 @@ static void JS_ProcessCsvFile (const v8::FunctionCallbackInfo& args) TRI_CLOSE(fd); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -237,7 +239,7 @@ static void JS_ProcessCsvFile (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_ProcessJsonFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 2) { @@ -308,6 +310,7 @@ static void JS_ProcessJsonFile (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- diff --git a/lib/V8/v8-utils.cpp b/lib/V8/v8-utils.cpp index 3c791dfb51..e68676c3de 100644 --- a/lib/V8/v8-utils.cpp +++ b/lib/V8/v8-utils.cpp @@ -337,7 +337,7 @@ static void FillDistribution (v8::Isolate* isolate, //////////////////////////////////////////////////////////////////////////////// static void JS_Options (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -356,6 +356,7 @@ static void JS_Options (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(v8::Object::New(isolate)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -367,7 +368,7 @@ static void JS_Options (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Base64Decode(const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -385,6 +386,7 @@ static void JS_Base64Decode(const v8::FunctionCallbackInfo& args) { } TRI_ASSERT(false); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -396,7 +398,7 @@ static void JS_Base64Decode(const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Base64Encode (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -414,6 +416,7 @@ static void JS_Base64Encode (const v8::FunctionCallbackInfo& args) { } TRI_ASSERT(false); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -427,7 +430,7 @@ static void JS_Base64Encode (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Parse (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() < 1) { @@ -469,9 +472,8 @@ static void JS_Parse (const v8::FunctionCallbackInfo& args) { if (script.IsEmpty()) { TRI_V8_RETURN_FALSE(); } - else { - TRI_V8_RETURN_TRUE(); - } + TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -485,7 +487,7 @@ static void JS_Parse (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ParseFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); // extract arguments @@ -520,9 +522,8 @@ static void JS_ParseFile (const v8::FunctionCallbackInfo& args) { if (script.IsEmpty()) { TRI_V8_RETURN(result); } - else { - TRI_V8_RETURN_TRUE(); - } + TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -586,7 +587,7 @@ static std::string GetEndpointFromUrl (std::string const& url) { //////////////////////////////////////////////////////////////////////////////// static void JS_Download (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); std::string const signature = "download(, , , )"; @@ -734,7 +735,7 @@ static void JS_Download (const v8::FunctionCallbackInfo& args) { maxRedirects = (int) TRI_ObjectToInt64(options->Get(TRI_V8_ASCII_STRING("maxRedirects"))); } - if (body.size() > 0 && + if (! body.empty() && (method == HttpRequest::HTTP_REQUEST_GET || method == HttpRequest::HTTP_REQUEST_HEAD)) { TRI_V8_THROW_EXCEPTION_MESSAGE(TRI_ERROR_BAD_PARAMETER, "should not provide a body value for this request method"); @@ -952,6 +953,7 @@ static void JS_Download (const v8::FunctionCallbackInfo& args) { } TRI_V8_THROW_EXCEPTION_INTERNAL("too many redirects"); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -968,7 +970,7 @@ static void JS_Download (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Execute (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1096,9 +1098,8 @@ static void JS_Execute (const v8::FunctionCallbackInfo& args) { if (useSandbox) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN(result); - } + TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1106,7 +1107,7 @@ static void JS_Execute (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_RegisterExecuteFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_GET_GLOBALS(); @@ -1121,6 +1122,7 @@ static void JS_RegisterExecuteFile (const v8::FunctionCallbackInfo& a v8g->ExecuteFileCallback.Reset(isolate, func); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1134,7 +1136,7 @@ static void JS_RegisterExecuteFile (const v8::FunctionCallbackInfo& a //////////////////////////////////////////////////////////////////////////////// static void JS_Exists (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1154,6 +1156,7 @@ static void JS_Exists (const v8::FunctionCallbackInfo& args) { else { TRI_V8_RETURN_FALSE(); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1166,7 +1169,7 @@ static void JS_Exists (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ChMod (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1208,6 +1211,7 @@ static void JS_ChMod (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_TRUE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1220,7 +1224,7 @@ static void JS_ChMod (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_SizeFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1245,6 +1249,7 @@ static void JS_SizeFile (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(v8::Number::New(isolate, (double) size)); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1252,13 +1257,14 @@ static void JS_SizeFile (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Getline (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); string line; getline(cin, line); TRI_V8_RETURN_STD_STRING(line); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1272,7 +1278,7 @@ static void JS_Getline (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_GetTempPath (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -1289,6 +1295,7 @@ static void JS_GetTempPath (const v8::FunctionCallbackInfo& args) { TRI_Free(TRI_CORE_MEM_ZONE, path); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1305,7 +1312,7 @@ static void JS_GetTempPath (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_GetTempFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() > 2) { @@ -1337,6 +1344,7 @@ static void JS_GetTempFile (const v8::FunctionCallbackInfo& args) { // return result TRI_V8_RETURN_STD_STRING(tempfile); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1349,7 +1357,7 @@ static void JS_GetTempFile (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_IsDirectory (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1370,6 +1378,7 @@ static void JS_IsDirectory (const v8::FunctionCallbackInfo& args) { else { TRI_V8_RETURN_FALSE(); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1382,7 +1391,7 @@ static void JS_IsDirectory (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_IsFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1403,6 +1412,7 @@ static void JS_IsFile (const v8::FunctionCallbackInfo& args) { else { TRI_V8_RETURN_FALSE(); } + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1416,7 +1426,7 @@ static void JS_IsFile (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_MakeAbsolute(const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1449,6 +1459,7 @@ static void JS_MakeAbsolute(const v8::FunctionCallbackInfo& args) { // return result TRI_V8_RETURN(res); + TRI_V8_TRY_CATCH_END } @@ -1467,7 +1478,7 @@ static void JS_MakeAbsolute(const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_List (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1496,6 +1507,7 @@ static void JS_List (const v8::FunctionCallbackInfo& args) { // return result TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1512,7 +1524,7 @@ static void JS_List (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ListTree (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1541,6 +1553,7 @@ static void JS_ListTree (const v8::FunctionCallbackInfo& args) { // return result TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1553,7 +1566,7 @@ static void JS_ListTree (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_MakeDirectory (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // 2nd argument (permissions) are ignored for now @@ -1577,6 +1590,7 @@ static void JS_MakeDirectory (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1589,7 +1603,7 @@ static void JS_MakeDirectory (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_MakeDirectoryRecursive (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // 2nd argument (permissions) are ignored for now @@ -1613,9 +1627,9 @@ static void JS_MakeDirectoryRecursive (const v8::FunctionCallbackInfo } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } - //////////////////////////////////////////////////////////////////////////////// /// @brief unzips a file /// @startDocuBlock JS_Unzip @@ -1630,7 +1644,7 @@ static void JS_MakeDirectoryRecursive (const v8::FunctionCallbackInfo //////////////////////////////////////////////////////////////////////////////// static void JS_UnzipFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1665,6 +1679,7 @@ static void JS_UnzipFile (const v8::FunctionCallbackInfo& args) { } TRI_V8_THROW_EXCEPTION_MESSAGE(res, errMsg); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1684,7 +1699,7 @@ static void JS_UnzipFile (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ZipFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1738,6 +1753,7 @@ static void JS_ZipFile (const v8::FunctionCallbackInfo& args) { } TRI_V8_THROW_EXCEPTION(res); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1749,7 +1765,7 @@ static void JS_ZipFile (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Load (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1820,6 +1836,7 @@ static void JS_Load (const v8::FunctionCallbackInfo& args) { TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, content); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1840,7 +1857,7 @@ static void JS_Load (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Log (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 2) { @@ -1882,6 +1899,7 @@ static void JS_Log (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1908,7 +1926,7 @@ static void JS_Log (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_LogLevel (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (1 <= args.Length()) { @@ -1918,6 +1936,7 @@ static void JS_LogLevel (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_STRING(TRI_LogLevelLogging()); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1929,7 +1948,7 @@ static void JS_LogLevel (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Md5 (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -1960,6 +1979,7 @@ static void JS_Md5 (const v8::FunctionCallbackInfo& args) { v8::Handle hashStr = TRI_V8_PAIR_STRING(hex, 32); TRI_V8_RETURN(hashStr); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1971,7 +1991,7 @@ static void JS_Md5 (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_RandomNumbers (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1 || ! args[0]->IsNumber()) { @@ -1986,6 +2006,7 @@ static void JS_RandomNumbers (const v8::FunctionCallbackInfo& args) { string&& str = JSNumGenerator.random(length); TRI_V8_RETURN_STD_STRING(str); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -1997,7 +2018,7 @@ static void JS_RandomNumbers (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_RandomAlphaNum (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1 || ! args[0]->IsNumber()) { @@ -2011,6 +2032,7 @@ static void JS_RandomAlphaNum (const v8::FunctionCallbackInfo& args) string&& str = JSAlphaNumGenerator.random(length); TRI_V8_RETURN_STD_STRING(str); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2022,7 +2044,7 @@ static void JS_RandomAlphaNum (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_RandomSalt (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -2031,6 +2053,7 @@ static void JS_RandomSalt (const v8::FunctionCallbackInfo& args) { string str = JSSaltGenerator.random(8); TRI_V8_RETURN_STD_STRING(str); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2042,7 +2065,7 @@ static void JS_RandomSalt (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_CreateNonce (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() != 0) { @@ -2052,6 +2075,7 @@ static void JS_CreateNonce (const v8::FunctionCallbackInfo& args) { string str = Nonce::createNonce(); TRI_V8_RETURN_STD_STRING(str); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2063,7 +2087,7 @@ static void JS_CreateNonce (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_MarkNonce (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1 || ! args[0]->IsString()) { @@ -2085,9 +2109,8 @@ static void JS_MarkNonce (const v8::FunctionCallbackInfo& args) { if (Nonce::checkAndMark(raw)) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2101,7 +2124,7 @@ static void JS_MarkNonce (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_MTime (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract two arguments @@ -2119,9 +2142,9 @@ static void JS_MTime (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN(v8::Number::New(isolate, static_cast(mtime))); + TRI_V8_TRY_CATCH_END } - //////////////////////////////////////////////////////////////////////////////// /// @brief renames a file /// @startDocuBlock JS_MoveFile @@ -2135,7 +2158,7 @@ static void JS_MTime (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_MoveFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract two arguments @@ -2177,6 +2200,7 @@ static void JS_MoveFile (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2193,7 +2217,7 @@ static void JS_MoveFile (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_CopyRecursive (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract two arguments @@ -2246,6 +2270,7 @@ static void JS_CopyRecursive (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2260,7 +2285,7 @@ static void JS_CopyRecursive (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_CopyFile (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract two arguments @@ -2302,10 +2327,9 @@ static void JS_CopyFile (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } - - //////////////////////////////////////////////////////////////////////////////// /// @brief outputs the arguments /// @@ -2317,7 +2341,7 @@ static void JS_CopyFile (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Output (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); for (int i = 0; i < args.Length(); i++) { @@ -2350,6 +2374,7 @@ static void JS_Output (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2390,7 +2415,7 @@ static void JS_Output (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ProcessStatistics (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); v8::Handle result = v8::Object::New(isolate); @@ -2413,6 +2438,7 @@ static void JS_ProcessStatistics (const v8::FunctionCallbackInfo& arg result->Set(TRI_V8_ASCII_STRING("virtualSize"), v8::Number::New(isolate, (double) info._virtualSize)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2424,7 +2450,7 @@ static void JS_ProcessStatistics (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_Rand (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); // check arguments @@ -2454,6 +2480,7 @@ static void JS_Rand (const v8::FunctionCallbackInfo& args) { // we failed to produce a valid random number TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2467,7 +2494,7 @@ static void JS_Rand (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Read (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -2495,9 +2522,9 @@ static void JS_Read (const v8::FunctionCallbackInfo& args) { TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, content); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } - //////////////////////////////////////////////////////////////////////////////// /// @brief reads in a file /// @startDocuBlock JS_ReadBuffer @@ -2508,7 +2535,7 @@ static void JS_Read (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_ReadBuffer (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -2533,6 +2560,7 @@ static void JS_ReadBuffer (const v8::FunctionCallbackInfo& args) { TRI_FreeString(TRI_UNKNOWN_MEM_ZONE, content); TRI_V8_RETURN(buffer->_handle); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2546,7 +2574,7 @@ static void JS_ReadBuffer (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Read64 (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -2570,6 +2598,7 @@ static void JS_Read64 (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_STD_STRING(base64); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2583,7 +2612,7 @@ static void JS_Read64 (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Save (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); if (args.Length() != 2) { @@ -2634,6 +2663,7 @@ static void JS_Save (const v8::FunctionCallbackInfo& args) { } TRI_V8_THROW_EXCEPTION_SYS("cannot write file"); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2648,7 +2678,7 @@ static void JS_Save (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Remove (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract the arguments @@ -2669,6 +2699,7 @@ static void JS_Remove (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2683,7 +2714,7 @@ static void JS_Remove (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_RemoveDirectory (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract the arguments @@ -2709,6 +2740,7 @@ static void JS_RemoveDirectory (const v8::FunctionCallbackInfo& args) } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2722,7 +2754,7 @@ static void JS_RemoveDirectory (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_RemoveRecursiveDirectory (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract the arguments @@ -2782,6 +2814,7 @@ static void JS_RemoveRecursiveDirectory (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); TRI_server_statistics_t info = TRI_GetServerStatistics(); @@ -2806,6 +2839,7 @@ static void JS_ServerStatistics (const v8::FunctionCallbackInfo& args result->Set(TRI_V8_ASCII_STRING("physicalMemory"), v8::Number::New(isolate, (double) TRI_PhysicalMemory)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2817,7 +2851,7 @@ static void JS_ServerStatistics (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_SPrintF (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); size_t len = args.Length(); @@ -2924,6 +2958,7 @@ static void JS_SPrintF (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_STD_STRING(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2935,7 +2970,7 @@ static void JS_SPrintF (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Sha512 (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); // extract arguments @@ -2965,6 +3000,7 @@ static void JS_Sha512 (const v8::FunctionCallbackInfo& args) { delete[] hex; TRI_V8_RETURN(hashStr); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -2976,7 +3012,7 @@ static void JS_Sha512 (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Sha384 (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); // extract arguments @@ -3006,6 +3042,7 @@ static void JS_Sha384 (const v8::FunctionCallbackInfo& args) { delete[] hex; TRI_V8_RETURN(hashStr); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3017,7 +3054,7 @@ static void JS_Sha384 (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Sha256 (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); // extract arguments @@ -3047,6 +3084,7 @@ static void JS_Sha256 (const v8::FunctionCallbackInfo& args) { delete[] hex; TRI_V8_RETURN(hashStr); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3058,7 +3096,7 @@ static void JS_Sha256 (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Sha224 (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); // extract arguments @@ -3088,6 +3126,7 @@ static void JS_Sha224 (const v8::FunctionCallbackInfo& args) { delete[] hex; TRI_V8_RETURN(hashStr); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3099,7 +3138,7 @@ static void JS_Sha224 (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Sha1 (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); // extract arguments @@ -3129,6 +3168,7 @@ static void JS_Sha1 (const v8::FunctionCallbackInfo& args) { delete[] hex; TRI_V8_RETURN(hashStr); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3140,7 +3180,7 @@ static void JS_Sha1 (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Sleep (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -3157,6 +3197,7 @@ static void JS_Sleep (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3170,10 +3211,11 @@ static void JS_Sleep (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Time (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); TRI_V8_RETURN(v8::Number::New(isolate, TRI_microtime())); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3186,7 +3228,7 @@ static void JS_Time (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_Wait (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -3212,6 +3254,7 @@ static void JS_Wait (const v8::FunctionCallbackInfo& args) { } TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3223,9 +3266,8 @@ static void JS_Wait (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// #ifdef TRI_ENABLE_FAILURE_TESTS - static void JS_DebugSegfault (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -3240,8 +3282,8 @@ static void JS_DebugSegfault (const v8::FunctionCallbackInfo& args) { // we may get here if we are in non-maintainer mode TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } - #endif //////////////////////////////////////////////////////////////////////////////// @@ -3253,9 +3295,8 @@ static void JS_DebugSegfault (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// #ifdef TRI_ENABLE_FAILURE_TESTS - static void JS_DebugSetFailAt (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -3268,8 +3309,8 @@ static void JS_DebugSetFailAt (const v8::FunctionCallbackInfo& args) TRI_AddFailurePointDebugging(point.c_str()); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } - #endif //////////////////////////////////////////////////////////////////////////////// @@ -3281,9 +3322,8 @@ static void JS_DebugSetFailAt (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// #ifdef TRI_ENABLE_FAILURE_TESTS - static void JS_DebugRemoveFailAt (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -3296,8 +3336,8 @@ static void JS_DebugRemoveFailAt (const v8::FunctionCallbackInfo& arg TRI_RemoveFailurePointDebugging(point.c_str()); TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } - #endif //////////////////////////////////////////////////////////////////////////////// @@ -3309,7 +3349,7 @@ static void JS_DebugRemoveFailAt (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_DebugClearFailAt (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -3323,6 +3363,7 @@ static void JS_DebugClearFailAt (const v8::FunctionCallbackInfo& args #endif TRI_V8_RETURN_UNDEFINED(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3334,7 +3375,7 @@ static void JS_DebugClearFailAt (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_DebugCanUseFailAt (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -3345,9 +3386,8 @@ static void JS_DebugCanUseFailAt (const v8::FunctionCallbackInfo& arg if (TRI_CanUseFailurePointsDebugging()) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3355,7 +3395,7 @@ static void JS_DebugCanUseFailAt (const v8::FunctionCallbackInfo& arg //////////////////////////////////////////////////////////////////////////////// static void JS_ClientStatistics (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); v8::Handle result = v8::Object::New(isolate); @@ -3388,6 +3428,7 @@ static void JS_ClientStatistics (const v8::FunctionCallbackInfo& args FillDistribution(isolate, result, TRI_V8_ASCII_STRING("bytesReceived"), bytesReceived); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3399,7 +3440,7 @@ static void JS_ClientStatistics (const v8::FunctionCallbackInfo& args //////////////////////////////////////////////////////////////////////////////// static void JS_PBKDF2 (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate) v8::HandleScope scope(isolate); // extract arguments @@ -3414,6 +3455,7 @@ static void JS_PBKDF2 (const v8::FunctionCallbackInfo& args) { string result = SslInterface::sslPBKDF2(salt.c_str(), salt.size(), password.c_str(), password.size(), iterations, keyLength); TRI_V8_RETURN_STD_STRING(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3425,7 +3467,7 @@ static void JS_PBKDF2 (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_HMAC (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract arguments @@ -3466,6 +3508,7 @@ static void JS_HMAC (const v8::FunctionCallbackInfo& args) { string result = SslInterface::sslHMAC(key.c_str(), key.size(), message.c_str(), message.size(), al); TRI_V8_RETURN_STD_STRING(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3473,7 +3516,7 @@ static void JS_HMAC (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_HttpStatistics (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); v8::Handle result = v8::Object::New(isolate); @@ -3499,6 +3542,7 @@ static void JS_HttpStatistics (const v8::FunctionCallbackInfo& args) result->Set(TRI_V8_ASCII_STRING("requestsOther"), v8::Number::New(isolate, (double) methodRequests[(int) HttpRequest::HTTP_REQUEST_ILLEGAL]._count)); TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3506,7 +3550,7 @@ static void JS_HttpStatistics (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_ExecuteExternal (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract the arguments @@ -3606,6 +3650,7 @@ static void JS_ExecuteExternal (const v8::FunctionCallbackInfo& args) } #endif TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3613,7 +3658,7 @@ static void JS_ExecuteExternal (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_StatusExternal (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); v8::Handle pidname = TRI_V8_ASCII_STRING("pid"); @@ -3673,15 +3718,15 @@ static void JS_StatusExternal (const v8::FunctionCallbackInfo& args) } // return the result TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } - //////////////////////////////////////////////////////////////////////////////// /// @brief executes a external program //////////////////////////////////////////////////////////////////////////////// static void JS_ExecuteAndWaitExternal (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract the arguments @@ -3815,6 +3860,7 @@ static void JS_ExecuteAndWaitExternal (const v8::FunctionCallbackInfo } // return the result TRI_V8_RETURN(result); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3822,7 +3868,7 @@ static void JS_ExecuteAndWaitExternal (const v8::FunctionCallbackInfo //////////////////////////////////////////////////////////////////////////////// static void JS_KillExternal (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); v8::Handle pidname = TRI_V8_ASCII_STRING("pid"); @@ -3850,9 +3896,8 @@ static void JS_KillExternal (const v8::FunctionCallbackInfo& args) { if (TRI_KillExternalProcess(pid)) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3860,7 +3905,7 @@ static void JS_KillExternal (const v8::FunctionCallbackInfo& args) { //////////////////////////////////////////////////////////////////////////////// static void JS_TestPort (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); // extract the arguments @@ -3887,9 +3932,8 @@ static void JS_TestPort (const v8::FunctionCallbackInfo& args) { if (available) { TRI_V8_RETURN_TRUE(); } - else { - TRI_V8_RETURN_FALSE(); - } + TRI_V8_RETURN_FALSE(); + TRI_V8_TRY_CATCH_END } //////////////////////////////////////////////////////////////////////////////// @@ -3975,7 +4019,7 @@ static void JS_SleepAndRequeue (const v8::FunctionCallbackInfo& args) //////////////////////////////////////////////////////////////////////////////// static void JS_IsIP (const v8::FunctionCallbackInfo& args) { - v8::Isolate* isolate = args.GetIsolate(); + TRI_V8_TRY_CATCH_BEGIN(isolate); v8::HandleScope scope(isolate); if (args.Length() != 1) { @@ -3984,15 +4028,16 @@ static void JS_IsIP (const v8::FunctionCallbackInfo& args) { TRI_Utf8ValueNFC address(TRI_UNKNOWN_MEM_ZONE, args[0]); - if (TRI_InetPton4(*address, NULL) == TRI_ERROR_NO_ERROR) { + if (TRI_InetPton4(*address, nullptr) == TRI_ERROR_NO_ERROR) { TRI_V8_RETURN(v8::Number::New(isolate, 4)); } - else if (TRI_InetPton6(*address, NULL) == 0) { + else if (TRI_InetPton6(*address, nullptr) == 0) { TRI_V8_RETURN(v8::Number::New(isolate, 6)); } else { TRI_V8_RETURN(v8::Number::New(isolate, 0)); } + TRI_V8_TRY_CATCH_END } // ----------------------------------------------------------------------------- @@ -4297,7 +4342,7 @@ void TRI_CreateErrorObject (v8::Isolate *isolate, size_t str_len = str.length(); if (str_len > 0) { UErrorCode errorCode = U_ZERO_ERROR; - const Normalizer2* normalizer = Normalizer2::getInstance(NULL, "nfc", UNORM2_COMPOSE ,errorCode); + const Normalizer2* normalizer = Normalizer2::getInstance(nullptr, "nfc", UNORM2_COMPOSE ,errorCode); if (U_FAILURE(errorCode)) { TRI_V8_RETURN(TRI_V8_PAIR_STRING((char*)*str, (int) str_len));