From 424ab3e759a26a50ab76d1310a8162a7f548032b Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 7 Mar 2013 01:30:34 +0100 Subject: [PATCH] removed redundant function --- arangod/V8Server/v8-query.cpp | 12 +++-- arangod/V8Server/v8-vocbase.cpp | 16 +++--- lib/V8/v8-conv.cpp | 89 ++++----------------------------- lib/V8/v8-conv.h | 6 --- 4 files changed, 25 insertions(+), 98 deletions(-) diff --git a/arangod/V8Server/v8-query.cpp b/arangod/V8Server/v8-query.cpp index b96b5460ed..a7479372e7 100644 --- a/arangod/V8Server/v8-query.cpp +++ b/arangod/V8Server/v8-query.cpp @@ -300,9 +300,9 @@ static TRI_index_operator_t* SetupConditionsSkiplist (TRI_index_t* idx, goto MEM_ERROR; } - TRI_json_t* json = TRI_JsonObject(value); + TRI_json_t* json = TRI_ObjectToJson(value); - if (!json) { + if (! json) { goto MEM_ERROR; } @@ -480,7 +480,9 @@ static TRI_json_t* SetupBitarrayAttributeValuesHelper (TRI_index_t* idx, v8::Han // .................................................................... v8::Handle value = attributeValues->Get(key); - json = TRI_JsonObject(value); + json = TRI_ObjectToJson(value); + + // TODO: check return value! // .................................................................... @@ -828,9 +830,9 @@ static TRI_index_operator_t* SetupExampleSkiplist (TRI_index_t* idx, v8::Handle value = example->Get(key); - TRI_json_t* json = TRI_JsonObject(value); + TRI_json_t* json = TRI_ObjectToJson(value); - if (!json) { + if (json == 0) { TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, parameters); return 0; diff --git a/arangod/V8Server/v8-vocbase.cpp b/arangod/V8Server/v8-vocbase.cpp index 0338782f52..aec694f22c 100644 --- a/arangod/V8Server/v8-vocbase.cpp +++ b/arangod/V8Server/v8-vocbase.cpp @@ -1202,7 +1202,7 @@ static v8::Handle UpdateVocbaseCol (const bool useCollection, assert(key); - TRI_json_t* json = TRI_JsonObject(argv[1]); + TRI_json_t* json = TRI_ObjectToJson(argv[1]); if (! holder.registerJson(TRI_UNKNOWN_MEM_ZONE, json)) { return scope.Close(v8::ThrowException(TRI_CreateErrorObject(TRI_errno(), " is no valid JSON"))); } @@ -1391,7 +1391,7 @@ static v8::Handle CreateVocBase (v8::Arguments const& argv, TRI_col_t // get optional options TRI_json_t* options = 0; if (p->Has(v8g->CreateOptionsKey)) { - options = TRI_JsonObject(p->Get(v8g->CreateOptionsKey)); + options = TRI_ObjectToJson(p->Get(v8g->CreateOptionsKey)); } TRI_InitCollectionInfo(vocbase, ¶meter, name.c_str(), collectionType, effectiveSize, options); @@ -1679,7 +1679,7 @@ static v8::Handle ExecuteQueryCursorAhuacatl (TRI_vocbase_t* const vo } // return the result as a cursor object - TRI_json_t* json = TRI_JsonObject(result); + TRI_json_t* json = TRI_ObjectToJson(result); if (! json) { v8::Handle errorObject = TRI_CreateErrorObject(TRI_ERROR_OUT_OF_MEMORY); @@ -1996,7 +1996,7 @@ static v8::Handle JS_CreateCursor (v8::Arguments const& argv) { // extract objects v8::Handle array = v8::Handle::Cast(argv[0]); - TRI_json_t* json = TRI_JsonObject(array); + TRI_json_t* json = TRI_ObjectToJson(array); if (json == 0) { return scope.Close(v8::ThrowException( @@ -2599,7 +2599,7 @@ static v8::Handle JS_RunAhuacatl (v8::Arguments const& argv) { TRI_json_t* parameters = 0; if (argc > 1) { - parameters = TRI_JsonObject(argv[1]); + parameters = TRI_ObjectToJson(argv[1]); holder.registerJson(TRI_UNKNOWN_MEM_ZONE, parameters); } @@ -2663,7 +2663,7 @@ static v8::Handle JS_ExplainAhuacatl (v8::Arguments const& argv) { TRI_json_t* parameters = 0; if (argc > 1) { - parameters = TRI_JsonObject(argv[1]); + parameters = TRI_ObjectToJson(argv[1]); holder.registerJson(TRI_UNKNOWN_MEM_ZONE, parameters); } @@ -3796,14 +3796,14 @@ static v8::Handle EnsureBitarray (v8::Arguments const& argv, bool sup // Attempt to convert the V8 javascript function argument into a TRI_json_t // ......................................................................... - TRI_json_t* value = TRI_JsonObject(argument); + TRI_json_t* value = TRI_ObjectToJson(argument); // ......................................................................... // If the conversion from V8 value into a TRI_json_t fails, exit // ......................................................................... - if (value == NULL) { + if (value == 0) { errorString = "invalid parameter -- expected an array (list)"; errorCode = TRI_ERROR_ILLEGAL_OPTION; ok = false; diff --git a/lib/V8/v8-conv.cpp b/lib/V8/v8-conv.cpp index ab33d7f99b..1e827adb02 100644 --- a/lib/V8/v8-conv.cpp +++ b/lib/V8/v8-conv.cpp @@ -1238,7 +1238,7 @@ static v8::Handle ObjectJsonString (TRI_json_t const* json) { static v8::Handle ObjectJsonArray (TRI_json_t const* json) { v8::Handle object = v8::Object::New(); - size_t n = json->_value._objects._length; + const size_t n = json->_value._objects._length; for (size_t i = 0; i < n; i += 2) { TRI_json_t* key = (TRI_json_t*) TRI_AtVector(&json->_value._objects, i); @@ -1250,7 +1250,7 @@ static v8::Handle ObjectJsonArray (TRI_json_t const* json) { TRI_json_t* j = (TRI_json_t*) TRI_AtVector(&json->_value._objects, i + 1); v8::Handle val = TRI_ObjectJson(j); - object->Set(v8::String::New(key->_value._string.data), val); + object->Set(v8::String::New(key->_value._string.data, key->_value._string.length - 1), val); } return object; @@ -1263,7 +1263,7 @@ static v8::Handle ObjectJsonArray (TRI_json_t const* json) { static v8::Handle ObjectJsonList (TRI_json_t const* json) { v8::Handle object = v8::Array::New(); - size_t n = json->_value._objects._length; + const size_t n = json->_value._objects._length; for (size_t i = 0; i < n; ++i) { TRI_json_t* j = (TRI_json_t*) TRI_AtVector(&json->_value._objects, i); @@ -1344,74 +1344,6 @@ v8::Handle TRI_ObjectJson (TRI_json_t const* json) { return scope.Close(v8::Undefined()); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief convert V8 object to TRI_json_t -//////////////////////////////////////////////////////////////////////////////// - -TRI_json_t* TRI_JsonObject (v8::Handle parameter) { - if (parameter->IsBoolean()) { - v8::Handle booleanParameter = parameter->ToBoolean(); - return TRI_CreateBooleanJson(TRI_UNKNOWN_MEM_ZONE, booleanParameter->Value()); - } - - if (parameter->IsNull()) { - return TRI_CreateNullJson(TRI_UNKNOWN_MEM_ZONE); - } - - if (parameter->IsNumber()) { - v8::Handle numberParameter = parameter->ToNumber(); - return TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, numberParameter->Value()); - } - - if (parameter->IsString()) { - v8::Handle stringParameter= parameter->ToString(); - TRI_Utf8ValueNFC str(TRI_UNKNOWN_MEM_ZONE, stringParameter); - return TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, *str, str.length()); - } - - if (parameter->IsArray()) { - v8::Handle arrayParameter = v8::Handle::Cast(parameter); - const uint32_t n = arrayParameter->Length(); - - TRI_json_t* listJson = TRI_CreateList2Json(TRI_UNKNOWN_MEM_ZONE, (const size_t) n); - if (listJson != 0) { - for (uint32_t j = 0; j < n; ++j) { - v8::Handle item = arrayParameter->Get(j); - TRI_json_t* result = TRI_JsonObject(item); - - if (result != 0) { - TRI_PushBack3ListJson(TRI_UNKNOWN_MEM_ZONE, listJson, result); - } - } - } - - return listJson; - } - - if (parameter->IsObject()) { - v8::Handle arrayParameter = v8::Handle::Cast(parameter); - v8::Handle names = arrayParameter->GetOwnPropertyNames(); - const uint32_t n = names->Length(); - - TRI_json_t* arrayJson = TRI_CreateArray2Json(TRI_UNKNOWN_MEM_ZONE, (const size_t) n); - if (arrayJson != 0) { - for (uint32_t j = 0; j < n; ++j) { - v8::Handle key = names->Get(j); - v8::Handle item = arrayParameter->Get(key); - TRI_json_t* result = TRI_JsonObject(item); - - if (result != 0) { - TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, arrayJson, TRI_ObjectToString(key).c_str(), result); - } - } - } - - return arrayJson; - } - - return 0; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief converts a TRI_shaped_json_t into a V8 object //////////////////////////////////////////////////////////////////////////////// @@ -1480,13 +1412,13 @@ TRI_json_t* TRI_ObjectToJson (v8::Handle parameter) { const uint32_t n = arrayParameter->Length(); TRI_json_t* listJson = TRI_CreateList2Json(TRI_UNKNOWN_MEM_ZONE, (const size_t) n); - if (listJson) { - for (uint32_t j = 0; j < arrayParameter->Length(); ++j) { + if (listJson != 0) { + for (uint32_t j = 0; j < n; ++j) { v8::Handle item = arrayParameter->Get(j); TRI_json_t* result = TRI_ObjectToJson(item); - if (result) { - TRI_PushBack2ListJson(listJson, result); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, result); + + if (result != 0) { + TRI_PushBack3ListJson(TRI_UNKNOWN_MEM_ZONE, listJson, result); } } } @@ -1506,15 +1438,14 @@ TRI_json_t* TRI_ObjectToJson (v8::Handle parameter) { TRI_json_t* result = TRI_ObjectToJson(item); if (result != 0) { - TRI_Insert2ArrayJson(TRI_UNKNOWN_MEM_ZONE, arrayJson, TRI_ObjectToString(key).c_str(), result); - TRI_Free(TRI_UNKNOWN_MEM_ZONE, result); + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, arrayJson, TRI_ObjectToString(key).c_str(), result); } } } return arrayJson; } - return NULL; + return 0; } //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/V8/v8-conv.h b/lib/V8/v8-conv.h index 3df2400e8e..1790baa666 100644 --- a/lib/V8/v8-conv.h +++ b/lib/V8/v8-conv.h @@ -58,12 +58,6 @@ v8::Handle TRI_ArrayAssociativePointer (const TRI_associative_pointer v8::Handle TRI_ObjectJson (TRI_json_t const*); -//////////////////////////////////////////////////////////////////////////////// -/// @brief convert V8 object to TRI_json_t -//////////////////////////////////////////////////////////////////////////////// - -TRI_json_t* TRI_JsonObject (v8::Handle parameter); - //////////////////////////////////////////////////////////////////////////////// /// @brief converts a TRI_shaped_json_t into a V8 object ////////////////////////////////////////////////////////////////////////////////