1
0
Fork 0

properly convert the JS object to VPack for transactions (#4640)

previously this did not work when the "action" attribute was a JavaScript function
This commit is contained in:
Jan 2018-02-21 12:10:19 +01:00 committed by GitHub
parent 5c28a00b24
commit 0b99acc04d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 11 deletions

View File

@ -337,7 +337,7 @@ void RocksDBTransactionCollection::commitCounts(uint64_t trxId,
}
}
_initialNumberDocuments = _numInserts - _numRemoves;
_initialNumberDocuments += _numInserts - _numRemoves;
_operationSize = 0;
_numInserts = 0;
_numUpdates = 0;

View File

@ -145,7 +145,9 @@ Result executeTransactionJS(
// parse all other options. `allowImplicitCollections` will
// be overwritten later if is contained in `object`
VPackBuilder builder;
TRI_V8ToVPack(isolate, builder, object, false);
// we must use "convertFunctionsToNull" here, because "action" is most
// likey a JavaScript function
TRI_V8ToVPack(isolate, builder, object, false, /*convertFunctionsToNull*/ true);
if (!builder.isClosed()) {
builder.close();
}

View File

@ -283,8 +283,11 @@ static inline void AddValue(BuilderContext& context,
template <bool performAllChecks, bool inObject>
static int V8ToVPack(BuilderContext& context,
v8::Handle<v8::Value> const parameter,
arangodb::StringRef const& attributeName) {
if (parameter->IsNull() || parameter->IsUndefined()) {
arangodb::StringRef const& attributeName,
bool convertFunctionsToNull) {
if (parameter->IsNull() ||
parameter->IsUndefined() ||
(convertFunctionsToNull && parameter->IsFunction())) {
AddValue<VPackValue, inObject>(context, attributeName,
VPackValue(VPackValueType::Null));
return TRI_ERROR_NO_ERROR;
@ -347,7 +350,7 @@ static int V8ToVPack(BuilderContext& context,
}
int res = V8ToVPack<performAllChecks, false>(context, value,
arangodb::StringRef());
arangodb::StringRef(), convertFunctionsToNull);
--context.level;
@ -417,7 +420,7 @@ static int V8ToVPack(BuilderContext& context,
if (!converted.IsEmpty()) {
// return whatever toJSON returned
return V8ToVPack<performAllChecks, inObject>(context, converted, attributeName);
return V8ToVPack<performAllChecks, inObject>(context, converted, attributeName, convertFunctionsToNull);
}
}
@ -452,7 +455,7 @@ static int V8ToVPack(BuilderContext& context,
}
int res = V8ToVPack<performAllChecks, true>(
context, value, arangodb::StringRef(*str, str.length()));
context, value, arangodb::StringRef(*str, str.length()), convertFunctionsToNull);
--context.level;
@ -475,13 +478,14 @@ static int V8ToVPack(BuilderContext& context,
////////////////////////////////////////////////////////////////////////////////
int TRI_V8ToVPack(v8::Isolate* isolate, VPackBuilder& builder,
v8::Handle<v8::Value> const value, bool keepTopLevelOpen) {
v8::Handle<v8::Value> const value, bool keepTopLevelOpen,
bool convertFunctionsToNull) {
v8::HandleScope scope(isolate);
BuilderContext context(isolate, builder, keepTopLevelOpen);
TRI_GET_GLOBALS();
TRI_GET_GLOBAL_STRING(ToJsonKey);
context.toJsonKey = ToJsonKey;
return V8ToVPack<true, false>(context, value, arangodb::StringRef());
return V8ToVPack<true, false>(context, value, arangodb::StringRef(), convertFunctionsToNull);
}
////////////////////////////////////////////////////////////////////////////////
@ -495,5 +499,5 @@ int TRI_V8ToVPackSimple(v8::Isolate* isolate,
v8::Handle<v8::Value> const value) {
// a HandleScope must have been created by the caller already
BuilderContext context(isolate, builder, false);
return V8ToVPack<false, false>(context, value, arangodb::StringRef());
return V8ToVPack<false, false>(context, value, arangodb::StringRef(), false);
}

View File

@ -46,7 +46,8 @@ v8::Handle<v8::Value> TRI_VPackToV8(
////////////////////////////////////////////////////////////////////////////////
int TRI_V8ToVPack(v8::Isolate* isolate, arangodb::velocypack::Builder& builder,
v8::Handle<v8::Value> const value, bool keepTopLevelOpen);
v8::Handle<v8::Value> const value, bool keepTopLevelOpen,
bool convertFunctionsToNull = false);
////////////////////////////////////////////////////////////////////////////////
/// @brief convert a V8 value to VPack value, simplified version