mirror of https://gitee.com/bigwinds/arangodb
toV8
This commit is contained in:
parent
b08b052fd4
commit
2f7b7ad1f1
|
@ -33,6 +33,7 @@
|
||||||
#include "VocBase/document-collection.h"
|
#include "VocBase/document-collection.h"
|
||||||
#include "Aql/AstNode.h"
|
#include "Aql/AstNode.h"
|
||||||
#include "Aql/Variable.h"
|
#include "Aql/Variable.h"
|
||||||
|
#include "V8/v8-conv.h"
|
||||||
|
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
namespace aql {
|
namespace aql {
|
||||||
|
@ -83,6 +84,26 @@ namespace triagens {
|
||||||
|
|
||||||
AqlValue* clone () const;
|
AqlValue* clone () const;
|
||||||
|
|
||||||
|
v8::Handle<v8::Value> toV8 () const {
|
||||||
|
switch (_type) {
|
||||||
|
case JSON: {
|
||||||
|
return TRI_ObjectJson(_json->json());
|
||||||
|
}
|
||||||
|
case DOCVEC: {
|
||||||
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
case RANGE: {
|
||||||
|
v8::Handle<v8::Array> values = v8::Array::New();
|
||||||
|
// TODO: fill range
|
||||||
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string toString () {
|
std::string toString () {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case JSON: {
|
case JSON: {
|
||||||
|
|
|
@ -31,6 +31,10 @@
|
||||||
#define ARANGODB_AQL_V8_EXPRESSION_H 1
|
#define ARANGODB_AQL_V8_EXPRESSION_H 1
|
||||||
|
|
||||||
#include "Basics/Common.h"
|
#include "Basics/Common.h"
|
||||||
|
#include "Basics/JsonHelper.h"
|
||||||
|
#include "BasicsC/json.h"
|
||||||
|
#include "Aql/Types.h"
|
||||||
|
#include "V8/v8-conv.h"
|
||||||
#include <v8.h>
|
#include <v8.h>
|
||||||
|
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
|
@ -65,11 +69,29 @@ namespace triagens {
|
||||||
/// @brief execute the expression
|
/// @brief execute the expression
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
v8::Handle<v8::Value> execute (v8::Handle<v8::Value> argv) {
|
AqlValue* execute (AqlValue const** argv,
|
||||||
v8::HandleScope scope;
|
std::vector<Variable*> vars,
|
||||||
|
std::vector<RegisterId> regs) {
|
||||||
|
// TODO: decide whether a separate handle scope is needed
|
||||||
|
|
||||||
v8::Handle<v8::Value> args[] = { argv };
|
v8::Handle<v8::Object> values = v8::Object::New();
|
||||||
return scope.Close(func->Call(func, 1, args));
|
for (size_t i = 0; i < vars.size(); ++i) {
|
||||||
|
auto varname = vars[i]->name;
|
||||||
|
auto reg = regs[i];
|
||||||
|
|
||||||
|
values->Set(v8::String::New(varname.c_str(), (int) varname.size()), argv[reg]->toV8());
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::Handle<v8::Value> args[] = { values };
|
||||||
|
v8::Handle<v8::Value> result = func->Call(func, 1, args);
|
||||||
|
|
||||||
|
TRI_json_t* json = TRI_ObjectToJson(result);
|
||||||
|
|
||||||
|
if (json == nullptr) {
|
||||||
|
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AqlValue(new triagens::basics::Json(TRI_UNKNOWN_MEM_ZONE, json));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue