1
0
Fork 0

do not segfault on cancellation

This commit is contained in:
Jan Steemann 2014-04-25 12:45:31 +02:00
parent dcf0f8fbb8
commit 18302b3ab4
8 changed files with 33 additions and 20 deletions

View File

@ -689,13 +689,14 @@ static TRI_aql_node_t* OptimiseFcall (TRI_aql_context_t* const context,
// all arguments are constants
// create the function code
code = FcallCode(function->_internalName, args);
if (! code) {
if (code == NULL) {
TRI_SetErrorContextAql(__FILE__, __LINE__, context, TRI_ERROR_OUT_OF_MEMORY, NULL);
return node;
}
// execute the function code
execContext = TRI_CreateExecutionContext(code->_buffer);
execContext = TRI_CreateExecutionContext(TRI_BeginStringBuffer(code), TRI_LengthStringBuffer(code));
TRI_FreeStringBuffer(TRI_UNKNOWN_MEM_ZONE, code);
if (execContext == NULL) {
@ -717,6 +718,7 @@ static TRI_aql_node_t* OptimiseFcall (TRI_aql_context_t* const context,
TRI_FreeExecutionContext(execContext);
if (res != TRI_ERROR_NO_ERROR) {
TRI_SetErrorContextAql(__FILE__, __LINE__, context, res, NULL);
return node;
}
@ -1216,7 +1218,7 @@ static TRI_aql_node_t* OptimiseBinaryRelationalOperation (TRI_aql_context_t* con
}
// execute the function code
execContext = TRI_CreateExecutionContext(code->_buffer);
execContext = TRI_CreateExecutionContext(TRI_BeginStringBuffer(code), TRI_LengthStringBuffer(code));
TRI_FreeStringBuffer(TRI_UNKNOWN_MEM_ZONE, code);
if (execContext == NULL) {

View File

@ -529,7 +529,7 @@ static v8::Handle<v8::Object> RequestCppToV8 ( TRI_v8_global_t const* v8g,
////////////////////////////////////////////////////////////////////////////////
static HttpResponse* ResponseV8ToCpp (TRI_v8_global_t const* v8g,
v8::Handle<v8::Object> res,
v8::Handle<v8::Object> const& res,
uint32_t compatibility) {
HttpResponse::HttpResponseCode code = HttpResponse::OK;

View File

@ -3406,18 +3406,14 @@ static v8::Handle<v8::Object> CreateErrorObjectAhuacatl (TRI_aql_error_t* error)
char* message = TRI_GetErrorMessageAql(error);
if (message) {
if (message != 0) {
std::string str(message);
TRI_Free(TRI_UNKNOWN_MEM_ZONE, message);
return scope.Close(TRI_CreateErrorObject(error->_file,
error->_line,
TRI_GetErrorCodeAql(error), str));
return scope.Close(TRI_CreateErrorObject(error->_file, error->_line, TRI_GetErrorCodeAql(error), str));
}
return scope.Close(TRI_CreateErrorObject(error->_file,
error->_line,
TRI_ERROR_OUT_OF_MEMORY));
return scope.Close(TRI_CreateErrorObject(error->_file, error->_line, TRI_ERROR_OUT_OF_MEMORY));
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -1836,6 +1836,10 @@ function resultException (req, res, err, headers, verbose) {
case arangodb.ERROR_USER_NOT_FOUND:
code = exports.HTTP_NOT_FOUND;
break;
case arangodb.ERROR_REQUEST_TIMEOUT:
code = exports.HTTP_REQUEST_TIMEOUT;
break;
case arangodb.ERROR_ARANGO_DUPLICATE_NAME:
case arangodb.ERROR_ARANGO_DUPLICATE_IDENTIFIER:
@ -2123,6 +2127,7 @@ exports.HTTP_PAYMENT = 402;
exports.HTTP_FORBIDDEN = 403;
exports.HTTP_NOT_FOUND = 404;
exports.HTTP_METHOD_NOT_ALLOWED = 405;
exports.HTTP_REQUEST_TIMEOUT = 408;
exports.HTTP_CONFLICT = 409;
exports.HTTP_PRECONDITION_FAILED = 412;
exports.HTTP_ENTITY_TOO_LARGE = 413;

View File

@ -72,12 +72,14 @@ int TRI_GetErrorExecutionContext (TRI_js_exec_context_t const context) {
/// @brief creates a new execution context
////////////////////////////////////////////////////////////////////////////////
TRI_js_exec_context_t TRI_CreateExecutionContext (char const* script) {
TRI_js_exec_context_t TRI_CreateExecutionContext (char const* script,
size_t length) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
js_exec_context_t* ctx = new js_exec_context_t;
ctx->_error = TRI_ERROR_NO_ERROR;
// execute script inside the context
v8::Handle<v8::Script> compiled = v8::Script::Compile(v8::String::New(script),
v8::Handle<v8::Script> compiled = v8::Script::Compile(v8::String::New(script, (int) length),
v8::String::New("--script--"));
// compilation failed, return

View File

@ -64,7 +64,7 @@ int TRI_GetErrorExecutionContext (TRI_js_exec_context_t const);
/// @brief creates a new execution context
////////////////////////////////////////////////////////////////////////////////
TRI_js_exec_context_t TRI_CreateExecutionContext (const char* script);
TRI_js_exec_context_t TRI_CreateExecutionContext (const char*, size_t);
////////////////////////////////////////////////////////////////////////////////
/// @brief frees an new execution context

View File

@ -125,13 +125,21 @@ static v8::Handle<v8::Object> CreateErrorObject (int errorNumber,
if (errorNumber == TRI_ERROR_OUT_OF_MEMORY) {
LOG_ERROR("encountered out-of-memory error in %s at line %d", file, line);
}
v8::Handle<v8::String> errorMessage = v8::String::New(message.c_str(), (int) message.size());
if (errorMessage.IsEmpty()) {
return scope.Close(v8::Object::New());
}
v8::Handle<v8::Object> errorObject = v8::Exception::Error(errorMessage)->ToObject();
v8::Handle<v8::Value> err = v8::Exception::Error(errorMessage);
if (err.IsEmpty()) {
return scope.Close(v8::Object::New());
}
v8::Handle<v8::Object> errorObject = err->ToObject();
if (errorObject.IsEmpty()) {
return scope.Close(v8::Object::New());
}
@ -3048,8 +3056,8 @@ bool TRI_ParseJavaScriptFile (char const* filename) {
////////////////////////////////////////////////////////////////////////////////
v8::Handle<v8::Value> TRI_ExecuteJavaScriptString (v8::Handle<v8::Context> context,
v8::Handle<v8::String> source,
v8::Handle<v8::Value> name,
v8::Handle<v8::String> const& source,
v8::Handle<v8::Value> const& name,
bool printResult) {
v8::HandleScope scope;

View File

@ -153,8 +153,8 @@ bool TRI_ParseJavaScriptFile (char const*);
////////////////////////////////////////////////////////////////////////////////
v8::Handle<v8::Value> TRI_ExecuteJavaScriptString (v8::Handle<v8::Context> context,
v8::Handle<v8::String> source,
v8::Handle<v8::Value> name,
v8::Handle<v8::String> const& source,
v8::Handle<v8::Value> const& name,
bool printResult);
////////////////////////////////////////////////////////////////////////////////