Skip to content

Commit

Permalink
upgrade nan, remove Function::NewInstance() deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Aug 23, 2016
1 parent 21dc91e commit a0f91ad
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"abstract-leveldown": "~2.4.0",
"bindings": "~1.2.1",
"fast-future": "~1.0.0",
"nan": "~2.3.0",
"nan": "~2.4.0",
"prebuild": "^4.1.1"
},
"devDependencies": {
Expand Down
9 changes: 7 additions & 2 deletions src/batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,24 @@ v8::Local<v8::Value> Batch::NewInstance (

Nan::EscapableHandleScope scope;

Nan::MaybeLocal<v8::Object> maybeInstance;
v8::Local<v8::Object> instance;

v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New<v8::FunctionTemplate>(batch_constructor);

if (optionsObj.IsEmpty()) {
v8::Local<v8::Value> argv[1] = { database };
instance = constructorHandle->GetFunction()->NewInstance(1, argv);
maybeInstance = Nan::NewInstance(constructorHandle->GetFunction(), 1, argv);
} else {
v8::Local<v8::Value> argv[2] = { database, optionsObj };
instance = constructorHandle->GetFunction()->NewInstance(2, argv);
maybeInstance = Nan::NewInstance(constructorHandle->GetFunction(), 2, argv);
}

if (maybeInstance.IsEmpty())
Nan::ThrowError("Could not create new Batch instance");
else
instance = maybeInstance.ToLocalChecked();
return scope.Escape(instance);
}

Expand Down
9 changes: 7 additions & 2 deletions src/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,19 @@ NAN_METHOD(Database::New) {
v8::Local<v8::Value> Database::NewInstance (v8::Local<v8::String> &location) {
Nan::EscapableHandleScope scope;

Nan::MaybeLocal<v8::Object> maybeInstance;
v8::Local<v8::Object> instance;

v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New<v8::FunctionTemplate>(database_constructor);

v8::Local<v8::Value> argv[] = { location };
instance = constructorHandle->GetFunction()->NewInstance(1, argv);
maybeInstance = Nan::NewInstance(constructorHandle->GetFunction(), 1, argv);

if (maybeInstance.IsEmpty())
Nan::ThrowError("Could not create new Database instance");
else
instance = maybeInstance.ToLocalChecked();
return scope.Escape(instance);
}

Expand Down Expand Up @@ -455,7 +460,7 @@ NAN_METHOD(Database::Iterator) {
// each iterator gets a unique id for this Database, so we can
// easily store & lookup on our `iterators` map
uint32_t id = database->currentIteratorId++;
v8::TryCatch try_catch;
Nan::TryCatch try_catch;
v8::Local<v8::Object> iteratorHandle = Iterator::NewInstance(
info.This()
, Nan::New<v8::Number>(id)
Expand Down
9 changes: 7 additions & 2 deletions src/iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,18 +322,23 @@ v8::Local<v8::Object> Iterator::NewInstance (

Nan::EscapableHandleScope scope;

Nan::MaybeLocal<v8::Object> maybeInstance;
v8::Local<v8::Object> instance;
v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New<v8::FunctionTemplate>(iterator_constructor);

if (optionsObj.IsEmpty()) {
v8::Local<v8::Value> argv[2] = { database, id };
instance = constructorHandle->GetFunction()->NewInstance(2, argv);
maybeInstance = Nan::NewInstance(constructorHandle->GetFunction(), 2, argv);
} else {
v8::Local<v8::Value> argv[3] = { database, id, optionsObj };
instance = constructorHandle->GetFunction()->NewInstance(3, argv);
maybeInstance = Nan::NewInstance(constructorHandle->GetFunction(), 3, argv);
}

if (maybeInstance.IsEmpty())
Nan::ThrowError("Could not create new Iterator instance");
else
instance = maybeInstance.ToLocalChecked();
return scope.Escape(instance);
}

Expand Down
15 changes: 8 additions & 7 deletions test/iterator-recursion-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ var db

test('setUp common', testCommon.setUp)

test('setUp db', function (t) {
db = leveldown(testCommon.location())
db.open(function () {
db.batch(sourceData, t.end.bind(t))
})
})

test('try to create an iterator with a blown stack', function (t) {
// Reducing the stack size down from the default 984 for the child node
// process makes it easier to trigger the bug condition. But making it too low
Expand All @@ -47,6 +40,14 @@ test('try to create an iterator with a blown stack', function (t) {
})
})

test('setUp db', function (t) {
db = leveldown(testCommon.location())
db.open(function (err) {
t.error(err)
db.batch(sourceData, t.end.bind(t))
})
})

test('iterate over a large iterator with a large watermark', function (t) {
var iterator = db.iterator({
highWaterMark: 10000000
Expand Down

0 comments on commit a0f91ad

Please sign in to comment.