8000 properly convert the JS object to VPack for transactions (#4640) · ashang/arangodb@0b99acc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b99acc

Browse files
authored
properly convert the JS object to VPack for transactions (arangodb#4640)
previously this did not work when the "action" attribute was a JavaScript function
1 parent 5c28a00 commit 0b99acc

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

arangod/RocksDBEngine/RocksDBTransactionCollection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ void RocksDBTransactionCollection::commitCounts(uint64_t trxId,
337337
}
338338
}
339339

340-
_initialNumberDocuments = _numInserts - _numRemoves;
340+
_initialNumberDocuments += _numInserts - _numRemoves;
341341
_operationSize = 0;
342342
_numInserts = 0;
343343
_numUpdates = 0;

arangod/VocBase/Methods/Transactions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ Result executeTransactionJS(
145145
// parse all other options. `allowImplicitCollections` will
146146
// be overwritten later if is contained in `object`
147147
VPackBuilder builder;
148-
TRI_V8ToVPack(isolate, builder, object, false);
148+
// we must use "convertFunctionsToNull" here, because "action" is most
149+
// likey a JavaScript function
150+
TRI_V8ToVPack(isolate, builder, object, false, /*convertFunctionsToNull*/ true);
149151
if (!builder.isClosed()) {
150152
builder.close();
151153
}

lib/V8/v8-vpack.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,11 @@ static inline void AddValue(BuilderContext& context,
283283
template <bool performAllChecks, bool inObject>
284284
static int V8ToVPack(BuilderContext& context,
285285
v8::Handle<v8::Value> const parameter,
286-
arangodb::StringRef const& attributeName) {
287-
if (parameter->IsNull() || parameter->IsUndefined()) {
286+
arangodb::StringRef const& attributeName,
287+
bool convertFunctionsToNull) {
288+
if (parameter->IsNull() ||
289+
parameter->IsUndefined() ||
290+
(convertFunctionsToNull && parameter->IsFunction())) {
288291
AddValue<VPackValue, inObject>(context, attributeName,
289292
VPackValue(VPackValueType::Null));
290293
return TRI_ERROR_NO_ERROR;
@@ -347,7 +350,7 @@ static int V8ToVPack(BuilderContext& context,
347350
}
348351

349352
int res = V8ToVPack<performAllChecks, false>(context, value,
350-
arangodb::StringRef());
353+
arangodb::StringRef(), convertFunctionsToNull);
351354

352355
--context.level;
353356

@@ -417,7 +420,7 @@ static int V8ToVPack(BuilderContext& context,
417420

418421
if (!converted.IsEmpty()) {
419422
// return whatever toJSON returned
420-
return V8ToVPack<performAllChecks, inObject>(context, converted, attributeName);
423+
return V8ToVPack<performAllChecks, inObject>(context, converted, attributeName, convertFunctionsToNull);
421424
}
422425
}
423426

@@ -452,7 +455,7 @@ static int V8ToVPack(BuilderContext& context,
452455
}
453456

454457
int res = V8ToVPack<performAllChecks, true>(
455-
context, value, arangodb::StringRef(*str, str.length()));
458+
context, value, arangodb::StringRef(*str, str.length()), convertFunctionsToNull);
456459

457460
--context.level;
458461

@@ -475,13 +478,14 @@ static int V8ToVPack(BuilderContext& context,
475478
////////////////////////////////////////////////////////////////////////////////
476479

477480
int TRI_V8ToVPack(v8::Isolate* isolate, VPackBuilder& builder,
478-
v8::Handle<v8::Value> const value, bool keepTopLevelOpen) {
481+
v8::Handle<v8::Value> const value, bool keepTopLevelOpen,
482+
bool convertFunctionsToNull) {
479483
v8::HandleScope scope(isolate);
480484
BuilderContext context(isolate, builder, keepTopLevelOpen);
481485
TRI_GET_GLOBALS();
482486
TRI_GET_GLOBAL_STRING(ToJsonKey);
483487
context.toJsonKey = ToJsonKey;
484-
return V8ToVPack<true, false>(context, value, arangodb::StringRef());
488+
return V8ToVPack<true, false>(context, value, arangodb::StringRef(), convertFunctionsToNull);
485489
}
486490

487491
////////////////////////////////////////////////////////////////////////////////
@@ -495,5 +499,5 @@ int TRI_V8ToVPackSimple(v8::Isolate* isolate,
495499
v8::Handle<v8::Value> const value) {
496500
// a HandleScope must have been created by the caller already
497501
BuilderContext context(isolate, builder, false);
498-
return V8ToVPack<false, false>(context, value, arangodb::StringRef());
502+
return V8ToVPack<false, false>(context, value, arangodb::StringRef(), false);
499503
}

lib/V8/v8-vpack.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ v8::Handle<v8::Value> TRI_VPackToV8(
4646
////////////////////////////////////////////////////////////////////////////////
4747

4848
int TRI_V8ToVPack(v8::Isolate* isolate, arangodb::velocypack::Builder& builder,
49-
v8::Handle<v8::Value> const value, bool keepTopLevelOpen);
49+
v8::Handle<v8::Value> const value, bool keepTopLevelOpen,
50+
bool convertFunctionsToNull = false);
5051

5152
////////////////////////////////////////////////////////////////////////////////
5253
/// @brief convert a V8 value to VPack value, simplified version

0 commit comments

Comments
 (0)
0