[Pkg-javascript-commits] [node-leveldown] 205/492: explicit namespaces, tighter line wrapping
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:59 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.
commit 70c14349f435e5a7eb88a09f206150749c92e79d
Author: Rod Vagg <rod at vagg.org>
Date: Sat Feb 16 00:18:10 2013 +1100
explicit namespaces, tighter line wrapping
---
src/async.cc | 30 ++++----
src/async.h | 12 ++--
src/batch.cc | 8 ++-
src/batch.h | 34 +++++----
src/database.cc | 186 +++++++++++++++++++++++++++++---------------------
src/database.h | 38 +++++++----
src/database_async.cc | 98 +++++++++++++-------------
src/database_async.h | 84 +++++++++++------------
src/iterator.cc | 38 ++++++++---
src/iterator.h | 1 -
src/iterator_async.cc | 39 ++++++-----
src/iterator_async.h | 18 ++---
src/levelup.cc | 15 +---
src/levelup.h | 47 ++++++++-----
14 files changed, 370 insertions(+), 278 deletions(-)
diff --git a/src/async.cc b/src/async.cc
index 20353ab..00d15eb 100644
--- a/src/async.cc
+++ b/src/async.cc
@@ -10,14 +10,11 @@
#include "async.h"
#include "batch.h"
-using namespace std;
-using namespace v8;
-using namespace node;
-using namespace leveldb;
+namespace levelup {
/** ASYNC BASE **/
-AsyncWorker::AsyncWorker (Database* database, Persistent<Function> callback)
+AsyncWorker::AsyncWorker (Database* database, v8::Persistent<v8::Function> callback)
: database(database), callback(callback) {
request.data = this;
};
@@ -25,7 +22,7 @@ AsyncWorker::AsyncWorker (Database* database, Persistent<Function> callback)
AsyncWorker::~AsyncWorker () {}
void AsyncWorker::WorkComplete () {
- HandleScope scope;
+ v8::HandleScope scope;
if (status.ok())
HandleOKCallback();
else
@@ -34,15 +31,17 @@ void AsyncWorker::WorkComplete () {
}
void AsyncWorker::HandleOKCallback () {
- Local<Value> argv[0];
- RunCallback(callback, argv, 0);
+ v8::Local<v8::Value> argv[0];
+ RUN_CALLBACK(callback, argv, 0);
}
void AsyncWorker::HandleErrorCallback () {
- Local<Value> argv[] = {
- Local<Value>::New(Exception::Error(String::New(status.ToString().c_str())))
+ v8::Local<v8::Value> argv[] = {
+ v8::Local<v8::Value>::New(
+ v8::Exception::Error(v8::String::New(status.ToString().c_str()))
+ )
};
- RunCallback(callback, argv, 1);
+ RUN_CALLBACK(callback, argv, 1);
}
void AsyncExecute (uv_work_t* req) {
@@ -56,5 +55,12 @@ void AsyncExecuteComplete (uv_work_t* req) {
}
void AsyncQueueWorker (AsyncWorker* worker) {
- uv_queue_work(uv_default_loop(), &worker->request, AsyncExecute, (uv_after_work_cb)AsyncExecuteComplete);
+ uv_queue_work(
+ uv_default_loop()
+ , &worker->request
+ , AsyncExecute
+ , (uv_after_work_cb)AsyncExecuteComplete
+ );
}
+
+} // namespace levelup
diff --git a/src/async.h b/src/async.h
index 5379b6d..ddb7416 100644
--- a/src/async.h
+++ b/src/async.h
@@ -8,15 +8,13 @@
#include <node.h>
-using namespace std;
-using namespace v8;
-using namespace leveldb;
+namespace levelup {
/* abstract */ class AsyncWorker {
public:
AsyncWorker (
Database* database
- , Persistent<Function> callback
+ , v8::Persistent<v8::Function> callback
);
virtual ~AsyncWorker ();
@@ -26,8 +24,8 @@ public:
protected:
Database* database;
- Persistent<Function> callback;
- Status status;
+ v8::Persistent<v8::Function> callback;
+ leveldb::Status status;
virtual void HandleOKCallback ();
virtual void HandleErrorCallback ();
};
@@ -36,4 +34,6 @@ void AsyncExecute (uv_work_t* req);
void AsyncExecuteComplete (uv_work_t* req);
void AsyncQueueWorker (AsyncWorker* worker);
+} // namespace LevelUP
+
#endif
diff --git a/src/batch.cc b/src/batch.cc
index bb6cb5e..8a17b2a 100644
--- a/src/batch.cc
+++ b/src/batch.cc
@@ -7,7 +7,7 @@
#include "batch.h"
-using namespace std;
+namespace levelup {
BatchOp::~BatchOp () {}
@@ -15,7 +15,7 @@ BatchDelete::~BatchDelete () {
keyPtr.Dispose();
}
-void BatchDelete::Execute (WriteBatch* batch) {
+void BatchDelete::Execute (leveldb::WriteBatch* batch) {
batch->Delete(key);
}
@@ -24,6 +24,8 @@ BatchWrite::~BatchWrite () {
valuePtr.Dispose();
}
-void BatchWrite::Execute (WriteBatch* batch) {
+void BatchWrite::Execute (leveldb::WriteBatch* batch) {
batch->Put(key, value);
}
+
+} // namespace LevelUP
diff --git a/src/batch.h b/src/batch.h
index 3bcc749..ca408d8 100644
--- a/src/batch.h
+++ b/src/batch.h
@@ -10,49 +10,53 @@
#include "database.h"
+namespace levelup {
+
class BatchOp {
public:
BatchOp () {};
virtual ~BatchOp ();
- virtual void Execute (WriteBatch* batch) =0;
+ virtual void Execute (leveldb::WriteBatch* batch) =0;
};
class BatchDelete : public BatchOp {
public:
BatchDelete (
- Slice key
- , Persistent<Value> keyPtr
+ leveldb::Slice key
+ , v8::Persistent<v8::Value> keyPtr
) : key(key)
, keyPtr(keyPtr)
{};
~BatchDelete ();
- void Execute (WriteBatch* batch);
+ void Execute (leveldb::WriteBatch* batch);
private:
- Slice key;
- Persistent<Value> keyPtr;
+ leveldb::Slice key;
+ v8::Persistent<v8::Value> keyPtr;
};
class BatchWrite : public BatchOp {
public:
BatchWrite (
- Slice key
- , Slice value
- , Persistent<Value> keyPtr
- , Persistent<Value> valuePtr
+ leveldb::Slice key
+ , leveldb::Slice value
+ , v8::Persistent<v8::Value> keyPtr
+ , v8::Persistent<v8::Value> valuePtr
) : key(key)
, keyPtr(keyPtr)
, value(value)
, valuePtr(valuePtr)
{};
~BatchWrite ();
- void Execute (WriteBatch* batch);
+ void Execute (leveldb::WriteBatch* batch);
private:
- Slice key;
- Persistent<Value> keyPtr;
- Slice value;
- Persistent<Value> valuePtr;
+ leveldb::Slice key;
+ v8::Persistent<v8::Value> keyPtr;
+ leveldb::Slice value;
+ v8::Persistent<v8::Value> valuePtr;
};
+} // namespace levelup
+
#endif
diff --git a/src/database.cc b/src/database.cc
index 1e97fff..ee4cf59 100644
--- a/src/database.cc
+++ b/src/database.cc
@@ -15,10 +15,7 @@
#include "batch.h"
#include "iterator.h"
-using namespace std;
-using namespace v8;
-using namespace node;
-using namespace leveldb;
+namespace levelup {
Database::Database () {
db = NULL;
@@ -76,7 +73,7 @@ void Database::CloseDatabase () {
/* V8 exposed functions *****************************/
-Persistent<Function> Database::constructor;
+v8::Persistent<v8::Function> Database::constructor;
Handle<Value> CreateDatabase (const Arguments& args) {
HandleScope scope;
@@ -84,21 +81,42 @@ Handle<Value> CreateDatabase (const Arguments& args) {
}
void Database::Init () {
- Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
- tpl->SetClassName(String::NewSymbol("Database"));
+ v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(New);
+ tpl->SetClassName(v8::String::NewSymbol("Database"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
- tpl->PrototypeTemplate()->Set(String::NewSymbol("open") , FunctionTemplate::New(Open)->GetFunction());
- tpl->PrototypeTemplate()->Set(String::NewSymbol("close") , FunctionTemplate::New(Close)->GetFunction());
- tpl->PrototypeTemplate()->Set(String::NewSymbol("put") , FunctionTemplate::New(Put)->GetFunction());
- tpl->PrototypeTemplate()->Set(String::NewSymbol("get") , FunctionTemplate::New(Get)->GetFunction());
- tpl->PrototypeTemplate()->Set(String::NewSymbol("del") , FunctionTemplate::New(Delete)->GetFunction());
- tpl->PrototypeTemplate()->Set(String::NewSymbol("batch") , FunctionTemplate::New(Batch)->GetFunction());
- tpl->PrototypeTemplate()->Set(String::NewSymbol("approximateSize"), FunctionTemplate::New(ApproximateSize)->GetFunction());
- constructor = Persistent<Function>::New(tpl->GetFunction());
+ tpl->PrototypeTemplate()->Set(
+ v8::String::NewSymbol("open")
+ , v8::FunctionTemplate::New(Open)->GetFunction()
+ );
+ tpl->PrototypeTemplate()->Set(
+ v8::String::NewSymbol("close")
+ , v8::FunctionTemplate::New(Close)->GetFunction()
+ );
+ tpl->PrototypeTemplate()->Set(
+ v8::String::NewSymbol("put")
+ , v8::FunctionTemplate::New(Put)->GetFunction()
+ );
+ tpl->PrototypeTemplate()->Set(
+ v8::String::NewSymbol("get")
+ , v8::FunctionTemplate::New(Get)->GetFunction()
+ );
+ tpl->PrototypeTemplate()->Set(
+ v8::String::NewSymbol("del")
+ , v8::FunctionTemplate::New(Delete)->GetFunction()
+ );
+ tpl->PrototypeTemplate()->Set(
+ v8::String::NewSymbol("batch")
+ , v8::FunctionTemplate::New(Batch)->GetFunction()
+ );
+ tpl->PrototypeTemplate()->Set(
+ v8::String::NewSymbol("approximateSize")
+ , FunctionTemplate::New(ApproximateSize)->GetFunction()
+ );
+ constructor = v8::Persistent<Function>::New(tpl->GetFunction());
}
-Handle<Value> Database::New (const Arguments& args) {
- HandleScope scope;
+v8::Handle<Value> Database::New (const v8::Arguments& args) {
+ v8::HandleScope scope;
Database* obj = new Database();
obj->Wrap(args.This());
@@ -106,26 +124,27 @@ Handle<Value> Database::New (const Arguments& args) {
return args.This();
}
-Handle<Value> Database::NewInstance (const Arguments& args) {
- HandleScope scope;
+v8::Handle<Value> Database::NewInstance (const v8::Arguments& args) {
+ v8::HandleScope scope;
- Handle<Value> argv[0];
- Local<Object> instance = constructor->NewInstance(0, argv);
+ v8::Handle<v8::Value> argv[0];
+ v8::Local<v8::Object> instance = constructor->NewInstance(0, argv);
return scope.Close(instance);
}
-Handle<Value> Database::Open (const Arguments& args) {
- HandleScope scope;
+v8::Handle<Value> Database::Open (const v8::Arguments& args) {
+ v8::HandleScope scope;
- Database* database = ObjectWrap::Unwrap<Database>(args.This());
- String::Utf8Value location(args[0]->ToString());
- Local<Object> optionsObj = Local<Object>::Cast(args[1]);
+ Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
+ v8::String::Utf8Value location(args[0]->ToString());
+ v8::Local<v8::Object> optionsObj = v8::Local<v8::Object>::Cast(args[1]);
BOOLEAN_OPTION_VALUE(optionsObj, createIfMissing)
BOOLEAN_OPTION_VALUE(optionsObj, errorIfExists)
BOOLEAN_OPTION_VALUE(optionsObj, compression)
UINT32_OPTION_VALUE(optionsObj, cacheSize, 8 << 20)
- Persistent<Function> callback = Persistent<Function>::New(Local<Function>::Cast(args[2]));
+ v8::Persistent<v8::Function> callback =
+ v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[2]));
OpenWorker* worker = new OpenWorker(
database
@@ -138,37 +157,38 @@ Handle<Value> Database::Open (const Arguments& args) {
);
AsyncQueueWorker(worker);
- return Undefined();
+ return v8::Undefined();
}
-Handle<Value> Database::Close (const Arguments& args) {
- HandleScope scope;
+v8::Handle<Value> Database::Close (const v8::Arguments& args) {
+ v8::HandleScope scope;
- Database* database = ObjectWrap::Unwrap<Database>(args.This());
- Persistent<Function> callback;
+ Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
+ v8::Persistent<v8::Function> callback;
if (args.Length() > 0)
- callback = Persistent<Function>::New(Local<Function>::Cast(args[0]));
+ callback = v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[0]));
CloseWorker* worker = new CloseWorker(database, callback);
AsyncQueueWorker(worker);
- return Undefined();
+ return v8::Undefined();
}
-Handle<Value> Database::Put (const Arguments& args) {
- HandleScope scope;
+v8::Handle<v8::Value> Database::Put (const v8::Arguments& args) {
+ v8::HandleScope scope;
- Database* database = ObjectWrap::Unwrap<Database>(args.This());
- Persistent<Function> callback = Persistent<Function>::New(Local<Function>::Cast(args[3]));
+ Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
+ v8::Persistent<v8::Function> callback =
+ v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[3]));
CB_ERR_IF_NULL_OR_UNDEFINED(0, "Key")
CB_ERR_IF_NULL_OR_UNDEFINED(1, "Value")
- Persistent<Value> keyBuffer = Persistent<Value>::New(args[0]);
+ v8::Persistent<v8::Value> keyBuffer = v8::Persistent<v8::Value>::New(args[0]);
STRING_OR_BUFFER_TO_SLICE(key, keyBuffer)
- Persistent<Value> valueBuffer = Persistent<Value>::New(args[1]);
+ v8::Persistent<v8::Value> valueBuffer = v8::Persistent<v8::Value>::New(args[1]);
STRING_OR_BUFFER_TO_SLICE(value, valueBuffer)
- Local<Object> optionsObj = Local<Object>::Cast(args[2]);
+ v8::Local<v8::Object> optionsObj = v8::Local<v8::Object>::Cast(args[2]);
BOOLEAN_OPTION_VALUE(optionsObj, sync)
WriteWorker* worker = new WriteWorker(
@@ -182,20 +202,21 @@ Handle<Value> Database::Put (const Arguments& args) {
);
AsyncQueueWorker(worker);
- return Undefined();
+ return v8::Undefined();
}
-Handle<Value> Database::Get (const Arguments& args) {
- HandleScope scope;
+v8::Handle<Value> Database::Get (const v8::Arguments& args) {
+ v8::HandleScope scope;
- Database* database = ObjectWrap::Unwrap<Database>(args.This());
- Persistent<Function> callback = Persistent<Function>::New(Local<Function>::Cast(args[2]));
+ Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
+ v8::Persistent<v8::Function> callback =
+ v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[2]));
CB_ERR_IF_NULL_OR_UNDEFINED(0, "Key")
- Persistent<Value> keyBuffer = Persistent<Value>::New(args[0]);
+ v8::Persistent<v8::Value> keyBuffer = v8::Persistent<v8::Value>::New(args[0]);
STRING_OR_BUFFER_TO_SLICE(key, keyBuffer)
- Local<Object> optionsObj = Local<Object>::Cast(args[1]);
+ v8::Local<v8::Object> optionsObj = v8::Local<v8::Object>::Cast(args[1]);
BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, asBuffer)
BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, fillCache)
@@ -209,20 +230,21 @@ Handle<Value> Database::Get (const Arguments& args) {
);
AsyncQueueWorker(worker);
- return Undefined();
+ return v8::Undefined();
}
-Handle<Value> Database::Delete (const Arguments& args) {
- HandleScope scope;
+v8::Handle<Value> Database::Delete (const v8::Arguments& args) {
+ v8::HandleScope scope;
- Database* database = ObjectWrap::Unwrap<Database>(args.This());
- Persistent<Function> callback = Persistent<Function>::New(Local<Function>::Cast(args[2]));
+ Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
+ v8::Persistent<v8::Function> callback =
+ v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[2]));
CB_ERR_IF_NULL_OR_UNDEFINED(0, "Key")
- Persistent<Value> keyBuffer = Persistent<Value>::New(args[0]);
+ v8::Persistent<v8::Value> keyBuffer = v8::Persistent<v8::Value>::New(args[0]);
STRING_OR_BUFFER_TO_SLICE(key, keyBuffer)
- Local<Object> optionsObj = Local<Object>::Cast(args[1]);
+ v8::Local<v8::Object> optionsObj = v8::Local<v8::Object>::Cast(args[1]);
BOOLEAN_OPTION_VALUE(optionsObj, sync)
DeleteWorker* worker = new DeleteWorker(
@@ -234,39 +256,48 @@ Handle<Value> Database::Delete (const Arguments& args) {
);
AsyncQueueWorker(worker);
- return Undefined();
+ return v8::Undefined();
}
-Handle<Value> Database::Batch (const Arguments& args) {
- HandleScope scope;
+v8::Handle<v8::Value> Database::Batch (const v8::Arguments& args) {
+ v8::HandleScope scope;
- Database* database = ObjectWrap::Unwrap<Database>(args.This());
- Local<Array> array = Local<Array>::Cast(args[0]);
- Local<Object> optionsObj = Local<Object>::Cast(args[1]);
+ Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
+ v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[0]);
+ v8::Local<v8::Object> optionsObj = v8::Local<v8::Object>::Cast(args[1]);
BOOLEAN_OPTION_VALUE(optionsObj, sync)
- Persistent<Function> callback = Persistent<Function>::New(Local<Function>::Cast(args[2]));
+ v8::Persistent<v8::Function> callback =
+ v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[2]));
- vector<BatchOp*>* operations = new vector<BatchOp*>;
+ std::vector<BatchOp*>* operations = new std::vector<BatchOp*>;
for (unsigned int i = 0; i < array->Length(); i++) {
if (!array->Get(i)->IsObject())
continue;
- Local<Object> obj = Local<Object>::Cast(array->Get(i));
+ v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(array->Get(i));
if (!obj->Has(str_type) && !obj->Has(str_key))
continue;
- Local<Value> keyBuffer = obj->Get(str_key);
+ v8::Local<v8::Value> keyBuffer = obj->Get(str_key);
if (obj->Get(str_type)->StrictEquals(str_del)) {
STRING_OR_BUFFER_TO_SLICE(key, keyBuffer)
- operations->push_back(new BatchDelete(key, Persistent<Value>::New(keyBuffer)));
+ operations->push_back(new BatchDelete(
+ key
+ , v8::Persistent<v8::Value>::New(keyBuffer)
+ ));
} else if (obj->Get(str_type)->StrictEquals(str_put) && obj->Has(str_value)) {
if (!obj->Has(str_value))
continue;
- Local<Value> valueBuffer = obj->Get(str_value);
+ v8::Local<v8::Value> valueBuffer = obj->Get(str_value);
STRING_OR_BUFFER_TO_SLICE(key, keyBuffer)
STRING_OR_BUFFER_TO_SLICE(value, valueBuffer)
- operations->push_back(new BatchWrite(key, value, Persistent<Value>::New(keyBuffer), Persistent<Value>::New(valueBuffer)));
+ operations->push_back(new BatchWrite(
+ key
+ , value
+ , v8::Persistent<v8::Value>::New(keyBuffer)
+ , v8::Persistent<v8::Value>::New(valueBuffer)
+ ));
}
}
@@ -277,21 +308,22 @@ Handle<Value> Database::Batch (const Arguments& args) {
, sync
));
- return Undefined();
+ return v8::Undefined();
}
-Handle<Value> Database::ApproximateSize (const Arguments& args) {
- HandleScope scope;
+v8::Handle<v8::Value> Database::ApproximateSize (const v8::Arguments& args) {
+ v8::HandleScope scope;
- Database* database = ObjectWrap::Unwrap<Database>(args.This());
- Persistent<Function> callback = Persistent<Function>::New(Local<Function>::Cast(args[2]));
+ Database* database = node::ObjectWrap::Unwrap<Database>(args.This());
+ v8::Persistent<v8::Function> callback =
+ v8::Persistent<v8::Function>::New(v8::Local<v8::Function>::Cast(args[2]));
CB_ERR_IF_NULL_OR_UNDEFINED(0, "start")
CB_ERR_IF_NULL_OR_UNDEFINED(1, "end")
- Persistent<Value> startBuffer = Persistent<Value>::New(args[0]);
+ v8::Persistent<v8::Value> startBuffer = v8::Persistent<v8::Value>::New(args[0]);
STRING_OR_BUFFER_TO_SLICE(start, startBuffer)
- Persistent<Value> endBuffer = Persistent<Value>::New(args[1]);
+ v8::Persistent<v8::Value> endBuffer = v8::Persistent<v8::Value>::New(args[1]);
STRING_OR_BUFFER_TO_SLICE(end, endBuffer)
ApproximateSizeWorker* worker = new ApproximateSizeWorker(
@@ -304,5 +336,7 @@ Handle<Value> Database::ApproximateSize (const Arguments& args) {
);
AsyncQueueWorker(worker);
- return Undefined();
+ return v8::Undefined();
}
+
+} // namespace LevelUP
diff --git a/src/database.h b/src/database.h
index 1b953ff..4ee6637 100644
--- a/src/database.h
+++ b/src/database.h
@@ -12,9 +12,7 @@
#include "levelup.h"
-using namespace std;
-using namespace v8;
-using namespace leveldb;
+namespace levelup {
LU_OPTION ( createIfMissing ); // for open()
LU_OPTION ( errorIfExists ); // for open()
@@ -31,20 +29,34 @@ LU_STR ( put );
struct AsyncDescriptor;
-Handle<Value> CreateDatabase (const Arguments& args);
+v8::Handle<v8::Value> CreateDatabase (const v8::Arguments& args);
class Database : public node::ObjectWrap {
public:
static void Init ();
static v8::Handle<v8::Value> NewInstance (const v8::Arguments& args);
- Status OpenDatabase (Options* options, string location);
- Status PutToDatabase (WriteOptions* options, Slice key, Slice value);
- Status GetFromDatabase (ReadOptions* options, Slice key, string& value);
- Status DeleteFromDatabase (WriteOptions* options, Slice key);
- Status WriteBatchToDatabase (WriteOptions* options, WriteBatch* batch);
- uint64_t ApproximateSizeFromDatabase (const Range* range);
- leveldb::Iterator* NewIterator (ReadOptions* options);
+ leveldb::Status OpenDatabase (leveldb::Options* options, std::string location);
+ leveldb::Status PutToDatabase (
+ leveldb::WriteOptions* options
+ , leveldb::Slice key
+ , leveldb::Slice value
+ );
+ leveldb::Status GetFromDatabase (
+ leveldb::ReadOptions* options
+ , leveldb::Slice key
+ , std::string& value
+ );
+ leveldb::Status DeleteFromDatabase (
+ leveldb::WriteOptions* options
+ , leveldb::Slice key
+ );
+ leveldb::Status WriteBatchToDatabase (
+ leveldb::WriteOptions* options
+ , leveldb::WriteBatch* batch
+ );
+ uint64_t ApproximateSizeFromDatabase (const leveldb::Range* range);
+ leveldb::Iterator* NewIterator (leveldb::ReadOptions* options);
const leveldb::Snapshot* NewSnapshot ();
void ReleaseSnapshot (const leveldb::Snapshot* snapshot);
void CloseDatabase ();
@@ -53,7 +65,7 @@ private:
Database ();
~Database ();
- DB* db;
+ leveldb::DB* db;
static v8::Persistent<v8::Function> constructor;
@@ -67,4 +79,6 @@ private:
LU_V8_METHOD( ApproximateSize)
};
+} // namespace levelup
+
#endif
diff --git a/src/database_async.cc b/src/database_async.cc
index 311644d..1dd9b65 100644
--- a/src/database_async.cc
+++ b/src/database_async.cc
@@ -12,17 +12,14 @@
#include "database_async.h"
#include "batch.h"
-using namespace std;
-using namespace v8;
-using namespace node;
-using namespace leveldb;
+namespace levelup {
/** OPEN WORKER **/
OpenWorker::OpenWorker (
Database* database
- , Persistent<Function> callback
- , string location
+ , v8::Persistent<v8::Function> callback
+ , std::string location
, bool createIfMissing
, bool errorIfExists
, bool compression
@@ -30,11 +27,13 @@ OpenWorker::OpenWorker (
) : AsyncWorker(database, callback)
, location(location)
{
- options = new Options();
+ options = new leveldb::Options();
options->create_if_missing = createIfMissing;
options->error_if_exists = errorIfExists;
- options->compression = compression ? kSnappyCompression : kNoCompression;
- options->block_cache = NewLRUCache(cacheSize);
+ options->compression = compression
+ ? leveldb::kSnappyCompression
+ : leveldb::kNoCompression;
+ options->block_cache = leveldb::NewLRUCache(cacheSize);
};
OpenWorker::~OpenWorker () {
@@ -49,7 +48,7 @@ void OpenWorker::Execute () {
CloseWorker::CloseWorker (
Database* database
- , Persistent<Function> callback
+ , v8::Persistent<v8::Function> callback
) : AsyncWorker(database, callback)
{};
@@ -60,7 +59,7 @@ void CloseWorker::Execute () {
}
void CloseWorker::WorkComplete () {
- HandleScope scope;
+ v8::HandleScope scope;
HandleOKCallback();
callback.Dispose();
}
@@ -69,9 +68,9 @@ void CloseWorker::WorkComplete () {
IOWorker::IOWorker (
Database* database
- , Persistent<Function> callback
- , Slice key
- , Persistent<Value> keyPtr
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice key
+ , v8::Persistent<v8::Value> keyPtr
) : AsyncWorker(database, callback)
, key(key)
, keyPtr(keyPtr)
@@ -88,15 +87,15 @@ void IOWorker::WorkComplete () {
ReadWorker::ReadWorker (
Database* database
- , Persistent<Function> callback
- , Slice key
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice key
, bool asBuffer
, bool fillCache
- , Persistent<Value> keyPtr
+ , v8::Persistent<v8::Value> keyPtr
) : IOWorker(database, callback, key, keyPtr)
, asBuffer(asBuffer)
{
- options = new ReadOptions();
+ options = new leveldb::ReadOptions();
options->fill_cache = fillCache;
};
@@ -109,29 +108,31 @@ void ReadWorker::Execute () {
}
void ReadWorker::HandleOKCallback () {
- Local<Value> returnValue;
+ v8::Local<v8::Value> returnValue;
if (asBuffer)
- returnValue = Local<Value>::New(Buffer::New((char*)value.data(), value.size())->handle_);
+ returnValue = v8::Local<v8::Value>::New(
+ node::Buffer::New((char*)value.data(), value.size())->handle_
+ );
else
- returnValue = String::New((char*)value.data(), value.size());
- Local<Value> argv[] = {
- Local<Value>::New(Null())
+ returnValue = v8::String::New((char*)value.data(), value.size());
+ v8::Local<v8::Value> argv[] = {
+ v8::Local<v8::Value>::New(v8::Null())
, returnValue
};
- RunCallback(callback, argv, 2);
+ RUN_CALLBACK(callback, argv, 2);
}
/** DELETE WORKER **/
DeleteWorker::DeleteWorker (
Database* database
- , Persistent<Function> callback
- , Slice key
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice key
, bool sync
- , Persistent<Value> keyPtr
+ , v8::Persistent<v8::Value> keyPtr
) : IOWorker(database, callback, key, keyPtr)
{
- options = new WriteOptions();
+ options = new leveldb::WriteOptions();
options->sync = sync;
};
@@ -147,12 +148,12 @@ void DeleteWorker::Execute () {
WriteWorker::WriteWorker (
Database* database
- , Persistent<Function> callback
- , Slice key
- , Slice value
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice key
+ , leveldb::Slice value
, bool sync
- , Persistent<Value> keyPtr
- , Persistent<Value> valuePtr
+ , v8::Persistent<v8::Value> keyPtr
+ , v8::Persistent<v8::Value> valuePtr
) : DeleteWorker(database, callback, key, sync, keyPtr)
, value(value)
, valuePtr(valuePtr)
@@ -173,18 +174,18 @@ void WriteWorker::WorkComplete () {
BatchWorker::BatchWorker (
Database* database
- , Persistent<Function> callback
- , vector<BatchOp*>* operations
+ , v8::Persistent<v8::Function> callback
+ , std::vector<BatchOp*>* operations
, bool sync
) : AsyncWorker(database, callback)
, operations(operations)
{
- options = new WriteOptions();
+ options = new leveldb::WriteOptions();
options->sync = sync;
};
BatchWorker::~BatchWorker () {
- for (vector<BatchOp*>::iterator it = operations->begin(); it != operations->end();) {
+ for (std::vector<BatchOp*>::iterator it = operations->begin(); it != operations->end();) {
delete *it;
it = operations->erase(it);
}
@@ -193,8 +194,8 @@ BatchWorker::~BatchWorker () {
}
void BatchWorker::Execute () {
- WriteBatch batch;
- for (vector<BatchOp*>::iterator it = operations->begin(); it != operations->end();) {
+ leveldb::WriteBatch batch;
+ for (std::vector<BatchOp*>::iterator it = operations->begin(); it != operations->end();) {
(*it++)->Execute(&batch);
}
status = database->WriteBatchToDatabase(options, &batch);
@@ -204,11 +205,11 @@ void BatchWorker::Execute () {
ApproximateSizeWorker::ApproximateSizeWorker (
Database* database
- , Persistent<Function> callback
- , Slice start
- , Slice end
- , Persistent<Value> startPtr
- , Persistent<Value> endPtr
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice start
+ , leveldb::Slice end
+ , v8::Persistent<v8::Value> startPtr
+ , v8::Persistent<v8::Value> endPtr
) : AsyncWorker(database, callback)
, range(start, end)
, startPtr(startPtr)
@@ -228,11 +229,12 @@ void ApproximateSizeWorker::WorkComplete() {
}
void ApproximateSizeWorker::HandleOKCallback () {
- Local<Value> returnValue = Number::New((double) size);
- Local<Value> argv[] = {
- Local<Value>::New(Null())
+ v8::Local<v8::Value> returnValue = v8::Number::New((double) size);
+ v8::Local<v8::Value> argv[] = {
+ v8::Local<v8::Value>::New(v8::Null())
, returnValue
};
- RunCallback(callback, argv, 2);
+ RUN_CALLBACK(callback, argv, 2);
}
+} // namespleveldb::ace LevelUP
diff --git a/src/database_async.h b/src/database_async.h
index cf97dd5..71b48fc 100644
--- a/src/database_async.h
+++ b/src/database_async.h
@@ -14,16 +14,14 @@
#include "async.h"
#include "batch.h"
-using namespace std;
-using namespace v8;
-using namespace leveldb;
+namespace levelup {
-class OpenWorker : public AsyncWorker {
+class OpenWorker : public AsyncWorker {
public:
OpenWorker (
Database* database
- , Persistent<Function> callback
- , string location
+ , v8::Persistent<v8::Function> callback
+ , std::string location
, bool createIfMissing
, bool errorIfExists
, bool compression
@@ -34,15 +32,15 @@ public:
virtual void Execute ();
private:
- string location;
- Options* options;
+ std::string location;
+ leveldb::Options* options;
};
class CloseWorker : public AsyncWorker {
public:
CloseWorker (
Database* database
- , Persistent<Function> callback
+ , v8::Persistent<v8::Function> callback
);
virtual ~CloseWorker ();
@@ -54,28 +52,28 @@ class IOWorker : public AsyncWorker {
public:
IOWorker (
Database* database
- , Persistent<Function> callback
- , Slice key
- , Persistent<Value> keyPtr
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice key
+ , v8::Persistent<v8::Value> keyPtr
);
virtual ~IOWorker ();
virtual void WorkComplete ();
protected:
- Slice key;
- Persistent<Value> keyPtr;
+ leveldb::Slice key;
+ v8::Persistent<v8::Value> keyPtr;
};
class ReadWorker : public IOWorker {
public:
ReadWorker (
Database* database
- , Persistent<Function> callback
- , Slice key
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice key
, bool asBuffer
, bool fillCache
- , Persistent<Value> keyPtr
+ , v8::Persistent<v8::Value> keyPtr
);
virtual ~ReadWorker ();
@@ -84,37 +82,37 @@ public:
private:
bool asBuffer;
- ReadOptions* options;
- string value;
+ leveldb::ReadOptions* options;
+ std::string value;
};
class DeleteWorker : public IOWorker {
public:
DeleteWorker (
Database* database
- , Persistent<Function> callback
- , Slice key
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice key
, bool sync
- , Persistent<Value> keyPtr
+ , v8::Persistent<v8::Value> keyPtr
);
virtual ~DeleteWorker ();
virtual void Execute ();
protected:
- WriteOptions* options;
+ leveldb::WriteOptions* options;
};
class WriteWorker : public DeleteWorker {
public:
WriteWorker (
Database* database
- , Persistent<Function> callback
- , Slice key
- , Slice value
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice key
+ , leveldb::Slice value
, bool sync
- , Persistent<Value> keyPtr
- , Persistent<Value> valuePtr
+ , v8::Persistent<v8::Value> keyPtr
+ , v8::Persistent<v8::Value> valuePtr
);
virtual ~WriteWorker ();
@@ -122,16 +120,16 @@ public:
virtual void WorkComplete ();
private:
- Slice value;
- Persistent<Value> valuePtr;
+ leveldb::Slice value;
+ v8::Persistent<v8::Value> valuePtr;
};
class BatchWorker : public AsyncWorker {
public:
BatchWorker (
Database* database
- , Persistent<Function> callback
- , vector<BatchOp*>* operations
+ , v8::Persistent<v8::Function> callback
+ , std::vector<BatchOp*>* operations
, bool sync
);
@@ -139,19 +137,19 @@ public:
virtual void Execute ();
private:
- WriteOptions* options;
- vector<BatchOp*>* operations;
+ leveldb::WriteOptions* options;
+ std::vector<BatchOp*>* operations;
};
class ApproximateSizeWorker : public AsyncWorker {
public:
ApproximateSizeWorker (
Database* database
- , Persistent<Function> callback
- , Slice start
- , Slice end
- , Persistent<Value> startPtr
- , Persistent<Value> endPtr
+ , v8::Persistent<v8::Function> callback
+ , leveldb::Slice start
+ , leveldb::Slice end
+ , v8::Persistent<v8::Value> startPtr
+ , v8::Persistent<v8::Value> endPtr
);
virtual ~ApproximateSizeWorker ();
@@ -160,10 +158,12 @@ public:
virtual void WorkComplete ();
private:
- Range range;
- Persistent<Value> startPtr;
- Persistent<Value> endPtr;
+ leveldb::Range range;
+ v8::Persistent<v8::Value> startPtr;
+ v8::Persistent<v8::Value> endPtr;
uint64_t size;
};
+} // namespace levelup
+
#endif
diff --git a/src/iterator.cc b/src/iterator.cc
index 7c90e5b..911f16a 100644
--- a/src/iterator.cc
+++ b/src/iterator.cc
@@ -86,8 +86,10 @@ Handle<Value> levelup::Iterator::Next (const Arguments& args) {
THROW_RETURN("Cannot call next() before previous next() has completed")
}
- Persistent<Function> endCallback = Persistent<Function>::New(Local<Function>::Cast(args[0]));
- Persistent<Function> dataCallback = Persistent<Function>::New(Local<Function>::Cast(args[1]));
+ Persistent<Function> endCallback =
+ Persistent<Function>::New(Local<Function>::Cast(args[0]));
+ Persistent<Function> dataCallback =
+ Persistent<Function>::New(Local<Function>::Cast(args[1]));
NextWorker* worker = new NextWorker(
iterator
@@ -108,7 +110,8 @@ Handle<Value> levelup::Iterator::End (const Arguments& args) {
THROW_RETURN("end() already called on iterator")
}
- Persistent<Function> callback = Persistent<Function>::New(Local<Function>::Cast(args[0]));
+ Persistent<Function> callback =
+ Persistent<Function>::New(Local<Function>::Cast(args[0]));
EndWorker* worker = new EndWorker(
iterator
, callback
@@ -129,8 +132,14 @@ void levelup::Iterator::Init () {
Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
tpl->SetClassName(String::NewSymbol("Iterator"));
tpl->InstanceTemplate()->SetInternalFieldCount(2);
- tpl->PrototypeTemplate()->Set(String::NewSymbol("next") , FunctionTemplate::New(Next)->GetFunction());
- tpl->PrototypeTemplate()->Set(String::NewSymbol("end") , FunctionTemplate::New(End)->GetFunction());
+ tpl->PrototypeTemplate()->Set(
+ String::NewSymbol("next")
+ , FunctionTemplate::New(Next)->GetFunction()
+ );
+ tpl->PrototypeTemplate()->Set(
+ String::NewSymbol("end")
+ , FunctionTemplate::New(End)->GetFunction()
+ );
constructor = Persistent<Function>::New(tpl->GetFunction());
}
@@ -152,14 +161,16 @@ Handle<Value> levelup::Iterator::New (const Arguments& args) {
Database* database = ObjectWrap::Unwrap<Database>(args[0]->ToObject());
Slice* start = NULL;
if (args[1]->ToObject()->Has(option_start)
- && (Buffer::HasInstance(args[1]->ToObject()->Get(option_start)) || args[1]->ToObject()->Get(option_start)->IsString())) {
+ && (Buffer::HasInstance(args[1]->ToObject()->Get(option_start))
+ || args[1]->ToObject()->Get(option_start)->IsString())) {
Local<Value> startBuffer = Local<Value>::New(args[1]->ToObject()->Get(option_start));
STRING_OR_BUFFER_TO_SLICE(_start, startBuffer)
start = new Slice(_start.data(), _start.size());
}
string* end = NULL;
if (args[1]->ToObject()->Has(option_end)
- && (Buffer::HasInstance(args[1]->ToObject()->Get(option_end)) || args[1]->ToObject()->Get(option_end)->IsString())) {
+ && (Buffer::HasInstance(args[1]->ToObject()->Get(option_end))
+ || args[1]->ToObject()->Get(option_end)->IsString())) {
Local<Value> endBuffer = Local<Value>::New(args[1]->ToObject()->Get(option_end));
STRING_OR_BUFFER_TO_SLICE(_end, endBuffer)
end = new string(_end.data(), _end.size());
@@ -175,7 +186,18 @@ Handle<Value> levelup::Iterator::New (const Arguments& args) {
if (args[1]->ToObject()->Has(option_limit)) {
limit = Local<Integer>::Cast(args[1]->ToObject()->Get(option_limit))->Value();
}
- Iterator* iterator = new Iterator(database, start, end, reverse, keys, values, limit, fillCache, keyAsBuffer, valueAsBuffer);
+ Iterator* iterator = new Iterator(
+ database
+ , start
+ , end
+ , reverse
+ , keys
+ , values
+ , limit
+ , fillCache
+ , keyAsBuffer
+ , valueAsBuffer
+ );
iterator->Wrap(args.This());
return args.This();
diff --git a/src/iterator.h b/src/iterator.h
index ada8c47..d62b2ba 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -26,7 +26,6 @@ LU_OPTION ( keys );
LU_OPTION ( values );
LU_OPTION ( keyAsBuffer );
LU_OPTION ( valueAsBuffer );
-LU_OPTION ( fillCache );
Handle<Value> CreateIterator (const Arguments& args);
diff --git a/src/iterator_async.cc b/src/iterator_async.cc
index dd9da76..cb33a0b 100644
--- a/src/iterator_async.cc
+++ b/src/iterator_async.cc
@@ -11,10 +11,7 @@
#include "async.h"
#include "iterator_async.h"
-using namespace std;
-using namespace v8;
-using namespace node;
-using namespace leveldb;
+namespace levelup {
/** NEXT WORKER **/
@@ -40,30 +37,36 @@ void NextWorker::Execute () {
}
void NextWorker::HandleOKCallback () {
- Local<Value> returnKey;
- if (iterator->keyAsBuffer)
- returnKey = Local<Value>::New(Buffer::New((char*)key.data(), key.size())->handle_);
- else
+ v8::Local<v8::Value> returnKey;
+ if (iterator->keyAsBuffer) {
+ returnKey = v8::Local<v8::Value>::New(
+ node::Buffer::New((char*)key.data(), key.size())->handle_
+ );
+ } else {
returnKey = String::New((char*)key.data(), key.size());
- Local<Value> returnValue;
- if (iterator->valueAsBuffer)
- returnValue = Local<Value>::New(Buffer::New((char*)value.data(), value.size())->handle_);
- else
+ }
+ v8::Local<v8::Value> returnValue;
+ if (iterator->valueAsBuffer) {
+ returnValue = v8::Local<v8::Value>::New(
+ node::Buffer::New((char*)value.data(), value.size())->handle_
+ );
+ } else {
returnValue = String::New((char*)value.data(), value.size());
+ }
// clean up & handle the next/end state see iterator.cc/checkEndCallback
localCallback(iterator);
if (ok) {
- Local<Value> argv[] = {
- Local<Value>::New(Null())
+ v8::Local<v8::Value> argv[] = {
+ v8::Local<v8::Value>::New(Null())
, returnKey
, returnValue
};
- RunCallback(callback, argv, 3);
+ RUN_CALLBACK(callback, argv, 3);
} else {
- Local<Value> argv[0];
- RunCallback(endCallback, argv, 0);
+ v8::Local<v8::Value> argv[0];
+ RUN_CALLBACK(endCallback, argv, 0);
}
}
@@ -81,3 +84,5 @@ EndWorker::~EndWorker () {}
void EndWorker::Execute () {
iterator->IteratorEnd();
}
+
+} // namespace levelup
diff --git a/src/iterator_async.h b/src/iterator_async.h
index d62ea31..e0362a7 100644
--- a/src/iterator_async.h
+++ b/src/iterator_async.h
@@ -11,16 +11,14 @@
#include "async.h"
#include "iterator.h"
-using namespace std;
-using namespace v8;
-using namespace leveldb;
+namespace levelup {
class NextWorker : public AsyncWorker {
public:
NextWorker (
levelup::Iterator* iterator
- , Persistent<Function> dataCallback
- , Persistent<Function> endCallback
+ , v8::Persistent<v8::Function> dataCallback
+ , v8::Persistent<v8::Function> endCallback
, void (*localCallback)(levelup::Iterator*)
);
@@ -30,10 +28,10 @@ public:
private:
levelup::Iterator* iterator;
- Persistent<Function> endCallback;
+ v8::Persistent<v8::Function> endCallback;
void (*localCallback)(levelup::Iterator*);
- string key;
- string value;
+ std::string key;
+ std::string value;
bool ok;
};
@@ -41,7 +39,7 @@ class EndWorker : public AsyncWorker {
public:
EndWorker (
levelup::Iterator* iterator
- , Persistent<Function> endCallback
+ , v8::Persistent<v8::Function> endCallback
);
virtual ~EndWorker ();
@@ -51,4 +49,6 @@ private:
levelup::Iterator* iterator;
};
+} // namespace levelup
+
#endif
diff --git a/src/levelup.cc b/src/levelup.cc
index e920959..012619f 100644
--- a/src/levelup.cc
+++ b/src/levelup.cc
@@ -9,6 +9,8 @@
#include "database.h"
#include "iterator.h"
+namespace levelup {
+
void Init (v8::Handle<v8::Object> exports) {
Database::Init();
levelup::Iterator::Init();
@@ -27,15 +29,4 @@ NODE_MODULE(levelup, Init)
// util
-void RunCallback (
- v8::Persistent<v8::Function> callback
- , v8::Local<v8::Value> argv[], int length
- ) {
-
- v8::TryCatch try_catch;
-
- callback->Call(v8::Context::GetCurrent()->Global(), length, argv);
- if (try_catch.HasCaught()) {
- node::FatalException(try_catch);
- }
-}
+} // namespace levelup
diff --git a/src/levelup.h b/src/levelup.h
index 7e2e17e..8928a57 100644
--- a/src/levelup.h
+++ b/src/levelup.h
@@ -7,48 +7,61 @@
#define LU_LEVELUP_H
#define LU_STR(key) \
- static Persistent<String> str_ ## key = Persistent<String>::New(String::New(#key));
+ static v8::Persistent<v8::String> str_ ## key = \
+ v8::Persistent<v8::String>::New(v8::String::New(#key));
#define LU_OPTION(key) \
- static Persistent<String> option_ ## key = Persistent<String>::New(String::New(#key));
+ static v8::Persistent<v8::String> option_ ## key = \
+ v8::Persistent<v8::String>::New(v8::String::New(#key));
#define LU_V8_METHOD(name) \
static v8::Handle<v8::Value> name (const v8::Arguments& args);
#define CB_ERR_IF_NULL_OR_UNDEFINED(index, name) \
if (args[index]->IsNull() || args[index]->IsUndefined()) { \
- Local<Value> argv[] = { \
- Local<Value>::New(Exception::Error(String::New("#name cannot be `null` or `undefined`"))) \
+ v8::Local<Value> argv[] = { \
+ v8::Local<Value>::New(v8::Exception::Error( \
+ v8::String::New("#name cannot be `null` or `undefined`"))) \
}; \
- RunCallback(callback, argv, 1); \
- return Undefined(); \
+ RUN_CALLBACK(callback, argv, 1); \
+ return v8::Undefined(); \
}
#define STRING_OR_BUFFER_TO_SLICE(to, from) \
size_t to ## Sz_; \
char* to ## Ch_; \
- if (Buffer::HasInstance(from->ToObject())) { \
- to ## Sz_ = Buffer::Length(from->ToObject()); \
- to ## Ch_ = Buffer::Data(from->ToObject()); \
+ if (node::Buffer::HasInstance(from->ToObject())) { \
+ to ## Sz_ = node::Buffer::Length(from->ToObject()); \
+ to ## Ch_ = node::Buffer::Data(from->ToObject()); \
} else { \
- Local<String> to ## Str = from->ToString(); \
+ v8::Local<v8::String> to ## Str = from->ToString(); \
to ## Sz_ = to ## Str->Utf8Length(); \
to ## Ch_ = new char[to ## Sz_]; \
- to ## Str->WriteUtf8(to ## Ch_, -1, NULL, String::NO_NULL_TERMINATION); \
+ to ## Str->WriteUtf8(to ## Ch_, -1, NULL, v8::String::NO_NULL_TERMINATION); \
} \
Slice to(to ## Ch_, to ## Sz_);
#define BOOLEAN_OPTION_VALUE(optionsObj, opt) \
- bool opt = optionsObj->Has(option_ ## opt) && optionsObj->Get(option_ ## opt)->BooleanValue();
+ bool opt = optionsObj->Has(option_ ## opt) && \
+ optionsObj->Get(option_ ## opt)->BooleanValue();
#define BOOLEAN_OPTION_VALUE_DEFTRUE(optionsObj, opt) \
- bool opt = !optionsObj->Has(option_ ## opt) || optionsObj->Get(option_ ## opt)->BooleanValue();
+ bool opt = !optionsObj->Has(option_ ## opt) || \
+ optionsObj->Get(option_ ## opt)->BooleanValue();
#define UINT32_OPTION_VALUE(optionsObj, opt, default) \
- uint32_t opt = optionsObj->Has(option_ ## opt) && optionsObj->Get(option_ ## opt)->IsUint32() ? optionsObj->Get(option_ ## opt)->Uint32Value() : default;
+ uint32_t opt = optionsObj->Has(option_ ## opt) \
+ && optionsObj->Get(option_ ## opt)->IsUint32() \
+ ? optionsObj->Get(option_ ## opt)->Uint32Value() \
+ : default;
#define THROW_RETURN(msg) \
- ThrowException(Exception::Error(String::New(#msg))); \
- return Undefined();
+ v8::ThrowException(Exception::Error(v8::String::New(#msg))); \
+ return v8::Undefined();
-void RunCallback (v8::Persistent<v8::Function> callback, v8::Local<v8::Value> argv[], int length);
+#define RUN_CALLBACK(callback, argv, length) \
+ v8::TryCatch try_catch; \
+ callback->Call(v8::Context::GetCurrent()->Global(), length, argv); \
+ if (try_catch.HasCaught()) { \
+ node::FatalException(try_catch); \
+ }
#endif
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git
More information about the Pkg-javascript-commits
mailing list