1
0
Fork 0

removed unused file

This commit is contained in:
Jan Steemann 2014-12-16 17:30:48 +01:00
parent 8515b8643e
commit 50e08ab099
6 changed files with 0 additions and 499 deletions

View File

@ -196,7 +196,6 @@ add_library(
STATIC
V8/JSLoader.cpp
V8/V8LineEditor.cpp
V8/V8StringConverter.cpp
V8/v8-buffer.cpp
V8/v8-conv.cpp
V8/v8-globals.cpp

View File

@ -179,7 +179,6 @@ lib_libarango_fe_a_SOURCES = \
lib_libarango_v8_a_SOURCES = \
lib/V8/JSLoader.cpp \
lib/V8/V8LineEditor.cpp \
lib/V8/V8StringConverter.cpp \
lib/V8/v8-buffer.cpp \
lib/V8/v8-conv.cpp \
lib/V8/v8-globals.cpp \

View File

@ -1,175 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief V8 string converter
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "V8StringConverter.h"
#include "unicode/normalizer2.h"
using namespace triagens::utils;
// -----------------------------------------------------------------------------
// --SECTION-- constructors / destructors
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief create the converter
////////////////////////////////////////////////////////////////////////////////
V8StringConverter::V8StringConverter (TRI_memory_zone_t* zone)
: _str(nullptr),
_temp(nullptr),
_length(0),
_strCapacity(0),
_tempCapacity(0),
_memoryZone(zone) {
UErrorCode status = U_ZERO_ERROR;
_normalizer = unorm2_getInstance(nullptr, "nfc", UNORM2_COMPOSE, &status);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the converter
////////////////////////////////////////////////////////////////////////////////
V8StringConverter::~V8StringConverter () {
if (_temp != nullptr) {
TRI_Free(_memoryZone, _temp);
}
if (_str != nullptr) {
TRI_Free(_memoryZone, _str);
}
}
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief assign a V8 string to the converter and convert it
////////////////////////////////////////////////////////////////////////////////
bool V8StringConverter::assign (v8::Handle<v8::Value> const obj) {
v8::String::Value str(obj);
size_t const length = (size_t) str.length();
if (length == 0) {
// empty string. no need for unicode conversion
reserveBuffer(_str, _strCapacity, 1);
if (_str != nullptr) {
_str[0] = '\0';
}
_length = 0;
}
else {
char buffer[64];
UChar* dest;
if (length + 1 < sizeof(buffer) / sizeof(UChar)) {
// use a static buffer if string is small enough
dest = (UChar*) &buffer[0];
}
else {
// use dynamic memory
if (! reserveBuffer(_temp, _tempCapacity, (length + 1) * sizeof(UChar))) {
return false;
}
dest = (UChar*) _temp;
}
// do unicode normalization
UErrorCode status = U_ZERO_ERROR;
int32_t utf16Length = unorm2_normalize(_normalizer, (UChar*) *str, (int32_t) length, dest, (int32_t) length + 1, &status);
if (status != U_ZERO_ERROR) {
_length = 0;
return false;
}
// calculate UTF-8 length
int32_t utf8Length;
status = U_ZERO_ERROR;
u_strToUTF8(nullptr, 0, &utf8Length, dest, (int32_t) utf16Length, &status);
if (status != U_BUFFER_OVERFLOW_ERROR) {
_length = 0;
return false;
}
// allocate big enough target buffer
reserveBuffer(_str, _strCapacity, utf8Length + 1);
if (_str == nullptr) {
_length = 0;
return false;
}
// convert from UTF-16 to UTF-8
status = U_ZERO_ERROR;
u_strToUTF8(_str, utf8Length + 1, nullptr, dest, (int32_t) utf16Length, &status);
_length = utf8Length;
}
return true;
}
// -----------------------------------------------------------------------------
// --SECTION-- private functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief reserve a buffer for operations
////////////////////////////////////////////////////////////////////////////////
bool V8StringConverter::reserveBuffer (char*& what,
size_t& oldSize,
size_t length) {
if (length < 64) {
// minimum buffer size
length = 64;
}
if (oldSize < length) {
char* ptr = static_cast<char*>(TRI_Reallocate(_memoryZone, what, length));
if (ptr == nullptr) {
return false;
}
what = ptr;
oldSize = length;
}
return true;
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -1,168 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief V8 string converter
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2011-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef ARANGODB_V8_V8_STRING_CONVERTER_H
#define ARANGODB_V8_V8_STRING_CONVERTER_H 1
#include "Basics/Common.h"
#include <v8.h>
struct UNormalizer2;
namespace triagens {
namespace utils {
class V8StringConverter {
// -----------------------------------------------------------------------------
// --SECTION-- constructors / destructors
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief create the converter
////////////////////////////////////////////////////////////////////////////////
V8StringConverter (TRI_memory_zone_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the converter
////////////////////////////////////////////////////////////////////////////////
~V8StringConverter ();
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
public:
////////////////////////////////////////////////////////////////////////////////
/// @brief assign a V8 string to the converter and convert it
////////////////////////////////////////////////////////////////////////////////
bool assign (v8::Handle<v8::Value> const);
////////////////////////////////////////////////////////////////////////////////
/// @brief steal the string
////////////////////////////////////////////////////////////////////////////////
inline char* steal () {
char* tmp = _str;
_str = nullptr;
_strCapacity = 0;
return tmp;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get the length of the converted string
////////////////////////////////////////////////////////////////////////////////
inline size_t length () const {
return _length;
}
// -----------------------------------------------------------------------------
// --SECTION-- private functions
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief reserve a buffer for operations
////////////////////////////////////////////////////////////////////////////////
bool reserveBuffer (char*&,
size_t&,
size_t);
// -----------------------------------------------------------------------------
// --SECTION-- private variables
// -----------------------------------------------------------------------------
private:
////////////////////////////////////////////////////////////////////////////////
/// @brief buffer for the converted string
////////////////////////////////////////////////////////////////////////////////
char* _str;
////////////////////////////////////////////////////////////////////////////////
/// @brief temporary buffer for Unicode conversion
////////////////////////////////////////////////////////////////////////////////
char* _temp;
////////////////////////////////////////////////////////////////////////////////
/// @brief length of _str
////////////////////////////////////////////////////////////////////////////////
size_t _length;
////////////////////////////////////////////////////////////////////////////////
/// @brief size of _str buffer (allocated size)
////////////////////////////////////////////////////////////////////////////////
size_t _strCapacity;
////////////////////////////////////////////////////////////////////////////////
/// @brief size of _temp buffer (allocated size)
////////////////////////////////////////////////////////////////////////////////
size_t _tempCapacity;
////////////////////////////////////////////////////////////////////////////////
/// @brief memory zone
////////////////////////////////////////////////////////////////////////////////
TRI_memory_zone_t* _memoryZone;
////////////////////////////////////////////////////////////////////////////////
/// @brief UTF-8 normalizer instance
////////////////////////////////////////////////////////////////////////////////
UNormalizer2 const* _normalizer;
};
}
}
#endif
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @page\\|// --SECTION--\\|/// @\\}"
// End:

View File

@ -36,7 +36,6 @@
#include "Basics/tri-strings.h"
#include "ShapedJson/shaped-json.h"
#include "V8/V8StringConverter.h"
#include "V8/v8-json.h"
#include "V8/v8-utils.h"
@ -1737,124 +1736,6 @@ int TRI_FillShapedJsonV8Object (v8::Isolate* isolate,
return TRI_ERROR_NO_ERROR;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief convert a V8 value to a json_t value,
////////////////////////////////////////////////////////////////////////////////
static bool ShapedJsonToJson (v8::Isolate *isolate,
TRI_json_t* dst,
triagens::utils::V8StringConverter& converter,
v8::Handle<v8::Value> const parameter) {
v8::HandleScope scope(isolate);
if (parameter->IsBoolean()) {
v8::Handle<v8::Boolean> booleanParameter = parameter->ToBoolean();
TRI_InitBooleanJson(dst, booleanParameter->Value());
return true;
}
if (parameter->IsBooleanObject()) {
v8::Handle<v8::BooleanObject> bo = v8::Handle<v8::BooleanObject>::Cast(parameter);
TRI_InitBooleanJson(dst, bo->BooleanValue());
return true;
}
if (parameter->IsNull()) {
TRI_InitNullJson(dst);
return true;
}
if (parameter->IsNumber()) {
v8::Handle<v8::Number> numberParameter = parameter->ToNumber();
TRI_InitNumberJson(dst, numberParameter->Value());
return true;
}
if (parameter->IsNumberObject()) {
v8::Handle<v8::NumberObject> no = v8::Handle<v8::NumberObject>::Cast(parameter);
TRI_InitNumberJson(dst, no->NumberValue());
return true;
}
if (parameter->IsString() || parameter->IsStringObject()) {
v8::Handle<v8::String> stringParameter = parameter->ToString();
if (converter.assign(stringParameter)) {
TRI_InitString2Json(dst, converter.steal(), converter.length());
// this passes ownership for the utf8 string to the JSON object
// so the converter dtor won't free the string now
return true;
}
// failed
TRI_InitNullJson(dst);
return false;
}
if (parameter->IsArray()) {
v8::Handle<v8::Array> arrayParameter = v8::Handle<v8::Array>::Cast(parameter);
uint32_t const n = arrayParameter->Length();
TRI_InitList2Json(TRI_UNKNOWN_MEM_ZONE, dst, static_cast<size_t const>(n));
if (n > 0) {
if (dst->_value._objects._capacity < n) {
// initialisation failed
return false;
}
TRI_json_t listElement;
for (uint32_t j = 0; j < n; ++j) {
if (! ShapedJsonToJson(isolate,
&listElement,
converter,
arrayParameter->Get(j))) {
return false;
}
TRI_PushBack2ListJson(dst, &listElement);
}
}
return true;
}
if (parameter->IsObject()) {
v8::Handle<v8::Array> arrayParameter = v8::Handle<v8::Array>::Cast(parameter);
v8::Handle<v8::Array> names = arrayParameter->GetOwnPropertyNames();
uint32_t const n = names->Length();
if (n > 0) {
TRI_InitArray2Json(TRI_UNKNOWN_MEM_ZONE, dst, static_cast<size_t const>(n));
if (dst->_value._objects._capacity < n * 2) {
// initialisation failed
return false;
}
TRI_json_t keyElement;
TRI_json_t valueElement;
for (uint32_t j = 0; j < n; ++j) {
v8::Handle<v8::Value> key = names->Get(j);
if (! ShapedJsonToJson(isolate,
&valueElement,
converter,
arrayParameter->Get(key))) {
return false;
}
if (converter.assign(key)) {
// move the string pointer into the JSON object
TRI_InitString2Json(&keyElement, converter.steal(), converter.length());
TRI_PushBackVector(&dst->_value._objects, &keyElement);
TRI_PushBackVector(&dst->_value._objects, &valueElement);
// this passes ownership for the utf8 string to the JSON object
}
}
}
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief convert a V8 value to a TRI_json_t value
////////////////////////////////////////////////////////////////////////////////
@ -2031,32 +1912,6 @@ TRI_json_t* TRI_ObjectToJson (v8::Isolate* isolate,
return ObjectToJson(isolate, parameter, seenHashes, seenObjects);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief convert a V8 object to a json_t value
/// this function makes some assumption about the v8 object to achieve
/// substantial speedups (in comparison to TRI_ObjectToJson)
/// use for ShapedJson v8 objects only or for lists of ShapedJson v8 objects!
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_ShapedJsonToJson (v8::Isolate *isolate, v8::Handle<v8::Value> const parameter) {
triagens::utils::V8StringConverter converter(TRI_UNKNOWN_MEM_ZONE);
TRI_json_t* result = TRI_CreateNullJson(TRI_UNKNOWN_MEM_ZONE);
if (result == nullptr) {
// OOM
return nullptr;
}
if (! ShapedJsonToJson(isolate, result, converter, parameter)) {
// something went wrong during JSON buildup
TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, result);
return nullptr;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief converts a V8 object to a string
////////////////////////////////////////////////////////////////////////////////

View File

@ -120,15 +120,6 @@ int TRI_FillShapedJsonV8Object (v8::Isolate* isolate,
TRI_json_t* TRI_ObjectToJson (v8::Isolate* isolate,
v8::Handle<v8::Value> const);
////////////////////////////////////////////////////////////////////////////////
/// @brief convert a V8 object to a json_t value
/// this function makes some assumption about the v8 object to achieve
/// substantial speedups (in comparison to TRI_ObjectToJson)
/// use for ShapedJson v8 objects only or for lists of ShapedJson v8 objects!
////////////////////////////////////////////////////////////////////////////////
TRI_json_t* TRI_ShapedJsonToJson (v8::Isolate *isolate, v8::Handle<v8::Value> const);
////////////////////////////////////////////////////////////////////////////////
/// @brief converts an V8 object to a string
////////////////////////////////////////////////////////////////////////////////