#include <vector>
#include <sstream>
+#include <hash_set>
#include <locale.h>
-#include <stdio.h>
+
using namespace node;
using namespace v8;
+#ifdef __GNUC__
+using namespace __gnu_cxx;
+#endif
+
static const int CMD_RET_ERROR = 1;
#define DEFINE_INT64_CONSTANT(target, constant) \
return sobj->ToNumber()->NumberValue();
}
- typedef struct {
- Handle<Object> traversed;
- } TBSONCTX;
+ struct V8ObjHash {
+
+ size_t operator()(const Handle<Object>& obj) const {
+ return (size_t) obj->GetIdentityHash();
+ }
+ };
+
+ struct V8ObjEq {
+
+ bool operator()(const Handle<Object>& o1, const Handle<Object>& o2) const {
+ return (o1 == o2);
+ }
+ };
+
+ typedef hash_set<Handle<Object>, V8ObjHash, V8ObjEq> V8ObjSet;
+
+ struct TBSONCTX {
+ V8ObjSet tset; //traversed objects set
+ };
static Handle<Object> toV8Object(bson_iterator *it, bson_type obt = BSON_OBJECT);
static Handle<Value> toV8Value(bson_iterator *it);
static void toBSON0(Handle<Object> obj, bson *bs, TBSONCTX *ctx) {
HandleScope scope;
assert(ctx && obj->IsObject());
- if (ctx->traversed->Get(obj)->IsObject()) {
+ V8ObjSet::iterator it = ctx->tset.find(obj);
+ if (it != ctx->tset.end()) {
bs->err = BSON_ERROR_ANY;
bs->errstr = strdup("Circular object reference");
return;
}
- ctx->traversed->Set(obj, obj);
+ ctx->tset.insert(obj);
Local<Array> pnames = obj->GetOwnPropertyNames();
for (uint32_t i = 0; i < pnames->Length(); ++i) {
Local<Value> pn = pnames->Get(i);
static void toBSON(Handle<Object> obj, bson *bs) {
HandleScope scope;
TBSONCTX ctx;
- ctx.traversed = Object::New();
toBSON0(obj, bs, &ctx);
}
));
}
bson *bs = bson_create();
- bson_init(bs);
+ bson_init_as_query(bs);
toBSON(Local<Object>::Cast(qv), bs);
bson_finish(bs);
if (bs->err) {
});
};
+/*
module.exports.testQuery1 = function(test) {
test.ok(jb);
});
};
+*/
+
module.exports.testQuery2 = function(test) {
- test.done();
+ test.ok(jb);
+ test.ok(jb.isOpen());
+ jb.query("parrots",
+ {name : /(grenny|bounty)/ig},
+ {$orderby : {name : 1}},
+ function(err, cursor, count) {
+ test.ifError(err);
+ console.log("count=" + count);
+ test.done();
+ });
+
};
module.exports.testClose = function(test) {