mirror of https://gitee.com/bigwinds/arangodb
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:
parent
5c28a00b24
commit
0b99acc04d
|
@ -337,7 +337,7 @@ void RocksDBTransactionCollection::commitCounts(uint64_t trxId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_initialNumberDocuments = _numInserts - _numRemoves;
|
_initialNumberDocuments += _numInserts - _numRemoves;
|
||||||
_operationSize = 0;
|
_operationSize = 0;
|
||||||
_numInserts = 0;
|
_numInserts = 0;
|
||||||
_numUpdates = 0;
|
_numUpdates = 0;
|
||||||
|
|
|
@ -145,7 +145,9 @@ Result executeTransactionJS(
|
||||||
// parse all other options. `allowImplicitCollections` will
|
// parse all other options. `allowImplicitCollections` will
|
||||||
// be overwritten later if is contained in `object`
|
// be overwritten later if is contained in `object`
|
||||||
VPackBuilder builder;
|
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()) {
|
if (!builder.isClosed()) {
|
||||||
builder.close();
|
builder.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,8 +283,11 @@ static inline void AddValue(BuilderContext& context,
|
||||||
template <bool performAllChecks, bool inObject>
|
template <bool performAllChecks, bool inObject>
|
||||||
static int V8ToVPack(BuilderContext& context,
|
static int V8ToVPack(BuilderContext& context,
|
||||||
v8::Handle<v8::Value> const parameter,
|
v8::Handle<v8::Value> const parameter,
|
||||||
arangodb::StringRef const& attributeName) {
|
arangodb::StringRef const& attributeName,
|
||||||
if (parameter->IsNull() || parameter->IsUndefined()) {
|
bool convertFunctionsToNull) {
|
||||||
|
if (parameter->IsNull() ||
|
||||||
|
parameter->IsUndefined() ||
|
||||||
|
(convertFunctionsToNull && parameter->IsFunction())) {
|
||||||
AddValue<VPackValue, inObject>(context, attributeName,
|
AddValue<VPackValue, inObject>(context, attributeName,
|
||||||
VPackValue(VPackValueType::Null));
|
VPackValue(VPackValueType::Null));
|
||||||
return TRI_ERROR_NO_ERROR;
|
return TRI_ERROR_NO_ERROR;
|
||||||
|
@ -347,7 +350,7 @@ static int V8ToVPack(BuilderContext& context,
|
||||||
}
|
}
|
||||||
|
|
||||||
int res = V8ToVPack<performAllChecks, false>(context, value,
|
int res = V8ToVPack<performAllChecks, false>(context, value,
|
||||||
arangodb::StringRef());
|
arangodb::StringRef(), convertFunctionsToNull);
|
||||||
|
|
||||||
--context.level;
|
--context.level;
|
||||||
|
|
||||||
|
@ -417,7 +420,7 @@ static int V8ToVPack(BuilderContext& context,
|
||||||
|
|
||||||
if (!converted.IsEmpty()) {
|
if (!converted.IsEmpty()) {
|
||||||
// return whatever toJSON returned
|
// 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>(
|
int res = V8ToVPack<performAllChecks, true>(
|
||||||
context, value, arangodb::StringRef(*str, str.length()));
|
context, value, arangodb::StringRef(*str, str.length()), convertFunctionsToNull);
|
||||||
|
|
||||||
--context.level;
|
--context.level;
|
||||||
|
|
||||||
|
@ -475,13 +478,14 @@ static int V8ToVPack(BuilderContext& context,
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int TRI_V8ToVPack(v8::Isolate* isolate, VPackBuilder& builder,
|
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);
|
v8::HandleScope scope(isolate);
|
||||||
BuilderContext context(isolate, builder, keepTopLevelOpen);
|
BuilderContext context(isolate, builder, keepTopLevelOpen);
|
||||||
TRI_GET_GLOBALS();
|
TRI_GET_GLOBALS();
|
||||||
TRI_GET_GLOBAL_STRING(ToJsonKey);
|
TRI_GET_GLOBAL_STRING(ToJsonKey);
|
||||||
context.toJsonKey = 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) {
|
v8::Handle<v8::Value> const value) {
|
||||||
// a HandleScope must have been created by the caller already
|
// a HandleScope must have been created by the caller already
|
||||||
BuilderContext context(isolate, builder, false);
|
BuilderContext context(isolate, builder, false);
|
||||||
return V8ToVPack<false, false>(context, value, arangodb::StringRef());
|
return V8ToVPack<false, false>(context, value, arangodb::StringRef(), false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,8 @@ v8::Handle<v8::Value> TRI_VPackToV8(
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int TRI_V8ToVPack(v8::Isolate* isolate, arangodb::velocypack::Builder& builder,
|
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
|
/// @brief convert a V8 value to VPack value, simplified version
|
||||||
|
|
Loading…
Reference in New Issue