Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

v0.10.x iojs support #146

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "leveldown",
"description": "A Node.js LevelDB binding, primary backend for LevelUP",
"version": "0.10.2",
"version": "0.10.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should leave this to the releaser (me) btw, it's part of the npm version workflow and the commit gets signed as well.

"contributors": [
"Rod Vagg <r@va.gg> (https://github.com/rvagg)",
"John Chesley <john@chesl.es> (https://github.com/chesles/)",
Expand All @@ -28,18 +28,18 @@
],
"main": "index.js",
"dependencies": {
"bindings": "~1.1.1",
"nan": "~0.6.0"
"bindings": "~1.2.1",
"nan": "~1.5.1"
},
"devDependencies": {
"tap": "~0.4.1",
"rimraf": "~2.1.4",
"mkfiletree": "~0.0.0",
"readfiletree": "~0.0.0",
"abstract-leveldown": "~0.11.1",
"du": "~0.1.0",
"mkfiletree": "~0.0.1",
"monotonic-timestamp": "~0.0.8",
"du": "~0.0.1",
"node-gyp": "~0.12.1"
"node-gyp": "~1.0.1",
"readfiletree": "~0.0.1",
"rimraf": "~2.2.8",
"tap": "~0.4.12"
},
"scripts": {
"test": "tap test/*-test.js --stderr"
Expand Down
6 changes: 3 additions & 3 deletions src/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class Database;
, NanCallback *callback
) : NanAsyncWorker(callback), database(database) {
NanScope();
v8::Local<v8::Object> obj = v8::Object::New();
NanAssignPersistent(v8::Object, persistentHandle, obj);
v8::Local<v8::Object> obj = NanNew<v8::Object>();
NanAssignPersistent(persistentHandle, obj);
}

protected:
void SetStatus(leveldb::Status status) {
this->status = status;
if (!status.ok())
this->errmsg = strdup(status.ToString().c_str());
SetErrorMessage(status.ToString().c_str());
}
Database* database;
private:
Expand Down
18 changes: 9 additions & 9 deletions src/batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ leveldb::Status Batch::Write () {
}

void Batch::Init () {
v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(Batch::New);
NanAssignPersistent(v8::FunctionTemplate, batch_constructor, tpl);
tpl->SetClassName(NanSymbol("Batch"));
v8::Local<v8::FunctionTemplate> tpl = NanNew<v8::FunctionTemplate>(Batch::New);
NanAssignPersistent(batch_constructor, tpl);
tpl->SetClassName(NanNew("Batch"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_PROTOTYPE_METHOD(tpl, "put", Batch::Put);
NODE_SET_PROTOTYPE_METHOD(tpl, "del", Batch::Del);
Expand All @@ -49,7 +49,7 @@ NAN_METHOD(Batch::New) {
optionsObj = v8::Local<v8::Object>::Cast(args[1]);
}

bool sync = NanBooleanOptionValue(optionsObj, NanSymbol("sync"));
bool sync = NanBooleanOptionValue(optionsObj, NanNew("sync"));

Batch* batch = new Batch(database, sync);
batch->Wrap(args.This());
Expand All @@ -62,12 +62,12 @@ v8::Handle<v8::Value> Batch::NewInstance (
, v8::Handle<v8::Object> optionsObj
) {

NanScope();
NanEscapableScope();

v8::Local<v8::Object> instance;

v8::Local<v8::FunctionTemplate> constructorHandle =
NanPersistentToLocal(batch_constructor);
NanNew(batch_constructor);

if (optionsObj.IsEmpty()) {
v8::Handle<v8::Value> argv[1] = { database };
Expand All @@ -77,7 +77,7 @@ v8::Handle<v8::Value> Batch::NewInstance (
instance = constructorHandle->GetFunction()->NewInstance(2, argv);
}

return scope.Close(instance);
return NanEscapeScope(instance);
}

NAN_METHOD(Batch::Put) {
Expand Down Expand Up @@ -153,7 +153,7 @@ NAN_METHOD(Batch::Write) {

if (batch->written)
return NanThrowError("write() already called on this batch");

if (args.Length() == 0)
return NanThrowError("write() requires a callback argument");

Expand All @@ -165,7 +165,7 @@ NAN_METHOD(Batch::Write) {
BatchWriteWorker* worker = new BatchWriteWorker(batch, callback);
// persist to prevent accidental GC
v8::Local<v8::Object> _this = args.This();
worker->SavePersistent("batch", _this);
worker->SaveToPersistent("batch", _this);
NanAsyncQueueWorker(worker);
} else {
LD_RUN_CALLBACK(v8::Local<v8::Function>::Cast(args[0]), 0, NULL);
Expand Down
84 changes: 42 additions & 42 deletions src/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace leveldown {

static v8::Persistent<v8::FunctionTemplate> database_constructor;

Database::Database (char* location) : location(location) {
Database::Database (NanUtf8String* location) : location(location) {
db = NULL;
currentIteratorId = 0;
pendingCloseWorker = NULL;
Expand All @@ -30,10 +30,10 @@ Database::Database (char* location) : location(location) {
Database::~Database () {
if (db != NULL)
delete db;
delete[] location;
delete location;
};

const char* Database::Location() const { return location; }
NanUtf8String* Database::Location() { return location; }

/* Calls from worker threads, NO V8 HERE *****************************/

Expand Down Expand Up @@ -129,9 +129,9 @@ NAN_METHOD(LevelDOWN) {
}

void Database::Init () {
v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(Database::New);
NanAssignPersistent(v8::FunctionTemplate, database_constructor, tpl);
tpl->SetClassName(NanSymbol("Database"));
v8::Local<v8::FunctionTemplate> tpl = NanNew<v8::FunctionTemplate>(Database::New);
NanAssignPersistent(database_constructor, tpl);
tpl->SetClassName(NanNew<v8::String>("Database"));
tpl->InstanceTemplate()->SetInternalFieldCount(1);
NODE_SET_PROTOTYPE_METHOD(tpl, "open", Database::Open);
NODE_SET_PROTOTYPE_METHOD(tpl, "close", Database::Close);
Expand All @@ -153,7 +153,7 @@ NAN_METHOD(Database::New) {
if (!args[0]->IsString())
return NanThrowError("constructor requires a location string argument");

char* location = NanFromV8String(args[0].As<v8::Object>(), Nan::UTF8, NULL, NULL, 0, v8::String::NO_OPTIONS);
NanUtf8String* location = new NanUtf8String(args[0]);

Database* obj = new Database(location);
obj->Wrap(args.This());
Expand All @@ -167,7 +167,7 @@ v8::Handle<v8::Value> Database::NewInstance (v8::Local<v8::String> &location) {
v8::Local<v8::Object> instance;

v8::Local<v8::FunctionTemplate> constructorHandle =
NanPersistentToLocal(database_constructor);
NanNew(database_constructor);

if (location.IsEmpty()) {
instance = constructorHandle->GetFunction()->NewInstance(0, NULL);
Expand All @@ -186,37 +186,37 @@ NAN_METHOD(Database::Open) {

bool createIfMissing = NanBooleanOptionValue(
optionsObj
, NanSymbol("createIfMissing")
, NanNew("createIfMissing")
, true
);
bool errorIfExists =
NanBooleanOptionValue(optionsObj, NanSymbol("errorIfExists"));
bool compression =
NanBooleanOptionValue(optionsObj, NanSymbol("compression"), true);
NanBooleanOptionValue(optionsObj, NanNew("errorIfExists"));
bool compression =
NanBooleanOptionValue(optionsObj, NanNew("compression"), true);

uint32_t cacheSize = NanUInt32OptionValue(
optionsObj
, NanSymbol("cacheSize")
, NanNew("cacheSize")
, 8 << 20
);
uint32_t writeBufferSize = NanUInt32OptionValue(
optionsObj
, NanSymbol("writeBufferSize")
, NanNew("writeBufferSize")
, 4 << 20
);
uint32_t blockSize = NanUInt32OptionValue(
optionsObj
, NanSymbol("blockSize")
, NanNew("blockSize")
, 4096
);
uint32_t maxOpenFiles = NanUInt32OptionValue(
optionsObj
, NanSymbol("maxOpenFiles")
, NanNew("maxOpenFiles")
, 1000
);
uint32_t blockRestartInterval = NanUInt32OptionValue(
optionsObj
, NanSymbol("blockRestartInterval")
, NanNew("blockRestartInterval")
, 16
);

Expand All @@ -234,7 +234,7 @@ NAN_METHOD(Database::Open) {
);
// persist to prevent accidental GC
v8::Local<v8::Object> _this = args.This();
worker->SavePersistent("database", _this);
worker->SaveToPersistent("database", _this);
NanAsyncQueueWorker(worker);

NanReturnUndefined();
Expand All @@ -251,7 +251,7 @@ NAN_METHOD(Database::Close) {
);
// persist to prevent accidental GC
v8::Local<v8::Object> _this = args.This();
worker->SavePersistent("database", _this);
worker->SaveToPersistent("database", _this);

if (!database->iterators.empty()) {
// yikes, we still have iterators open! naughty naughty.
Expand All @@ -275,18 +275,18 @@ NAN_METHOD(Database::Close) {
v8::Local<v8::Object> localHandle = NanPersistentToLocal(it->second);
leveldown::Iterator* iterator =
node::ObjectWrap::Unwrap<leveldown::Iterator>(localHandle->
Get(NanSymbol("iterator")).As<v8::Object>());
Get(NanNew("iterator")).As<v8::Object>());
*/
leveldown::Iterator *iterator = it->second;

if (!iterator->ended) {
v8::Local<v8::Function> end =
v8::Local<v8::Function>::Cast(NanObjectWrapHandle(iterator)->Get(
v8::String::NewSymbol("end")));
NanNew<v8::String>("end")));
v8::Local<v8::Value> argv[] = {
v8::FunctionTemplate::New()->GetFunction() // empty callback
NanNew<v8::FunctionTemplate>()->GetFunction() // empty callback
};
node::MakeCallback(
NanMakeCallback(
NanObjectWrapHandle(iterator)
, end
, 1
Expand Down Expand Up @@ -314,7 +314,7 @@ NAN_METHOD(Database::Put) {
LD_STRING_OR_BUFFER_TO_SLICE(key, keyHandle, key)
LD_STRING_OR_BUFFER_TO_SLICE(value, valueHandle, value)

bool sync = NanBooleanOptionValue(optionsObj, NanSymbol("sync"));
bool sync = NanBooleanOptionValue(optionsObj, NanNew("sync"));

WriteWorker* worker = new WriteWorker(
database
Expand All @@ -327,7 +327,7 @@ NAN_METHOD(Database::Put) {
);
// persist to prevent accidental GC
v8::Local<v8::Object> _this = args.This();
worker->SavePersistent("database", _this);
worker->SaveToPersistent("database", _this);
NanAsyncQueueWorker(worker);

NanReturnUndefined();
Expand All @@ -343,8 +343,8 @@ NAN_METHOD(Database::Get) {
v8::Local<v8::Object> keyHandle = args[0].As<v8::Object>();
LD_STRING_OR_BUFFER_TO_SLICE(key, keyHandle, key)

bool asBuffer = NanBooleanOptionValue(optionsObj, NanSymbol("asBuffer"), true);
bool fillCache = NanBooleanOptionValue(optionsObj, NanSymbol("fillCache"), true);
bool asBuffer = NanBooleanOptionValue(optionsObj, NanNew("asBuffer"), true);
bool fillCache = NanBooleanOptionValue(optionsObj, NanNew("fillCache"), true);

ReadWorker* worker = new ReadWorker(
database
Expand All @@ -356,7 +356,7 @@ NAN_METHOD(Database::Get) {
);
// persist to prevent accidental GC
v8::Local<v8::Object> _this = args.This();
worker->SavePersistent("database", _this);
worker->SaveToPersistent("database", _this);
NanAsyncQueueWorker(worker);

NanReturnUndefined();
Expand All @@ -372,7 +372,7 @@ NAN_METHOD(Database::Delete) {
v8::Local<v8::Object> keyHandle = args[0].As<v8::Object>();
LD_STRING_OR_BUFFER_TO_SLICE(key, keyHandle, key)

bool sync = NanBooleanOptionValue(optionsObj, NanSymbol("sync"));
bool sync = NanBooleanOptionValue(optionsObj, NanNew("sync"));

DeleteWorker* worker = new DeleteWorker(
database
Expand All @@ -383,7 +383,7 @@ NAN_METHOD(Database::Delete) {
);
// persist to prevent accidental GC
v8::Local<v8::Object> _this = args.This();
worker->SavePersistent("database", _this);
worker->SaveToPersistent("database", _this);
NanAsyncQueueWorker(worker);

NanReturnUndefined();
Expand All @@ -402,7 +402,7 @@ NAN_METHOD(Database::Batch) {

LD_METHOD_SETUP_COMMON(batch, 1, 2)

bool sync = NanBooleanOptionValue(optionsObj, NanSymbol("sync"));
bool sync = NanBooleanOptionValue(optionsObj, NanNew("sync"));

v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(args[0]);

Expand All @@ -415,21 +415,21 @@ NAN_METHOD(Database::Batch) {

v8::Local<v8::Object> obj = v8::Local<v8::Object>::Cast(array->Get(i));

LD_CB_ERR_IF_NULL_OR_UNDEFINED(obj->Get(NanSymbol("type")), type)
LD_CB_ERR_IF_NULL_OR_UNDEFINED(obj->Get(NanNew("type")), type)

v8::Local<v8::Value> keyBuffer = obj->Get(NanSymbol("key"));
v8::Local<v8::Value> keyBuffer = obj->Get(NanNew("key"));
LD_CB_ERR_IF_NULL_OR_UNDEFINED(keyBuffer, key)

if (obj->Get(NanSymbol("type"))->StrictEquals(NanSymbol("del"))) {
if (obj->Get(NanNew("type"))->StrictEquals(NanNew("del"))) {
LD_STRING_OR_BUFFER_TO_SLICE(key, keyBuffer, key)

batch->Delete(key);
if (!hasData)
hasData = true;

DisposeStringOrBufferFromSlice(keyBuffer, key);
} else if (obj->Get(NanSymbol("type"))->StrictEquals(NanSymbol("put"))) {
v8::Local<v8::Value> valueBuffer = obj->Get(NanSymbol("value"));
} else if (obj->Get(NanNew("type"))->StrictEquals(NanNew("put"))) {
v8::Local<v8::Value> valueBuffer = obj->Get(NanNew("value"));
LD_CB_ERR_IF_NULL_OR_UNDEFINED(valueBuffer, value)

LD_STRING_OR_BUFFER_TO_SLICE(key, keyBuffer, key)
Expand All @@ -454,7 +454,7 @@ NAN_METHOD(Database::Batch) {
);
// persist to prevent accidental GC
v8::Local<v8::Object> _this = args.This();
worker->SavePersistent("database", _this);
worker->SaveToPersistent("database", _this);
NanAsyncQueueWorker(worker);
} else {
LD_RUN_CALLBACK(callback, 0, NULL);
Expand Down Expand Up @@ -497,7 +497,7 @@ NAN_METHOD(Database::ApproximateSize) {
);
// persist to prevent accidental GC
v8::Local<v8::Object> _this = args.This();
worker->SavePersistent("database", _this);
worker->SaveToPersistent("database", _this);
NanAsyncQueueWorker(worker);

NanReturnUndefined();
Expand All @@ -522,7 +522,7 @@ NAN_METHOD(Database::GetProperty) {
std::string* value = new std::string();
database->GetPropertyFromDatabase(property, value);
v8::Local<v8::String> returnValue
= v8::String::New(value->c_str(), value->length());
= NanNew<v8::String>(value->c_str(), value->length());
delete value;
delete[] property.data();

Expand All @@ -545,7 +545,7 @@ NAN_METHOD(Database::Iterator) {
v8::TryCatch try_catch;
v8::Local<v8::Object> iteratorHandle = Iterator::NewInstance(
args.This()
, v8::Number::New(id)
, NanNew<v8::Number>(id)
, optionsObj
);
if (try_catch.HasCaught()) {
Expand All @@ -559,8 +559,8 @@ NAN_METHOD(Database::Iterator) {

// register our iterator
/*
v8::Local<v8::Object> obj = v8::Object::New();
obj->Set(NanSymbol("iterator"), iteratorHandle);
v8::Local<v8::Object> obj = NanNew<v8::Object>();
obj->Set(NanNew("iterator"), iteratorHandle);
v8::Persistent<v8::Object> persistent;
persistent.Reset(nan_isolate, obj);
database->iterators.insert(std::pair< uint32_t, v8::Persistent<v8::Object> & >
Expand Down
Loading