Skip to content

Commit

Permalink
Upgrade to Node 12 V8 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp authored and Venemo committed May 31, 2019
1 parent f6ac8e6 commit 7dd8107
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 124 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"gypfile": true,
"dependencies": {
"bindings": "^1.2.1",
"bindings": "^1.5.0",
"prebuild-install": "^5.2.5",
"nan": "^2.12.0"
"nan": "^2.13.1"
},
"devDependencies": {
"benchmark": "^2.1.4",
Expand Down
6 changes: 3 additions & 3 deletions src/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ MAKE_GET_FUNC(goToPrevDup, MDB_PREV_DUP);

static void fillDataFromArg1(CursorWrap* cw, Nan::NAN_METHOD_ARGS_TYPE info, MDB_val &data) {
if (info[1]->IsString()) {
CustomExternalStringResource::writeTo(info[1]->ToString(), &data);
CustomExternalStringResource::writeTo(Local<String>::Cast(info[1]), &data);
}
else if (node::Buffer::HasInstance(info[1])) {
data.mv_size = node::Buffer::Length(info[1]);
Expand Down Expand Up @@ -350,7 +350,7 @@ NAN_METHOD(CursorWrap::goToDupRange) {
return getCommon(info, MDB_GET_BOTH_RANGE, cursorArgToKey<0, 2>, fillDataFromArg1, freeDataFromArg1, nullptr);
}

void CursorWrap::setupExports(Handle<Object> exports) {
void CursorWrap::setupExports(Local<Object> exports) {
// CursorWrap: Prepare constructor template
Local<FunctionTemplate> cursorTpl = Nan::New<FunctionTemplate>(CursorWrap::ctor);
cursorTpl->SetClassName(Nan::New<String>("Cursor").ToLocalChecked());
Expand Down Expand Up @@ -378,5 +378,5 @@ void CursorWrap::setupExports(Handle<Object> exports) {
cursorTpl->PrototypeTemplate()->Set(Nan::New<String>("del").ToLocalChecked(), Nan::New<FunctionTemplate>(CursorWrap::del));

// Set exports
exports->Set(Nan::New<String>("Cursor").ToLocalChecked(), cursorTpl->GetFunction());
exports->Set(Nan::GetCurrentContext(), Nan::New<String>("Cursor").ToLocalChecked(), cursorTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
}
42 changes: 22 additions & 20 deletions src/dbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ NAN_METHOD(DbiWrap::ctor) {
bool needsTransaction = true;
bool isOpen = false;

EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(info[0]->ToObject());
EnvWrap *ew = Nan::ObjectWrap::Unwrap<EnvWrap>(Local<Object>::Cast(info[0]));

if (info[1]->IsObject()) {
Local<Object> options = info[1]->ToObject();
nameIsNull = options->Get(Nan::New<String>("name").ToLocalChecked())->IsNull();
name = options->Get(Nan::New<String>("name").ToLocalChecked())->ToString();
Local<Object> options = Local<Object>::Cast(info[1]);
nameIsNull = options->Get(Nan::GetCurrentContext(), Nan::New<String>("name").ToLocalChecked()).ToLocalChecked()->IsNull();
name = Local<String>::Cast(options->Get(Nan::GetCurrentContext(), Nan::New<String>("name").ToLocalChecked()).ToLocalChecked());

// Get flags from options

Expand All @@ -102,14 +102,14 @@ NAN_METHOD(DbiWrap::ctor) {
}

// Set flags for txn used to open database
Local<Value> create = options->Get(Nan::New<String>("create").ToLocalChecked());
if (create->IsBoolean() ? !create->BooleanValue() : true) {
Local<Value> create = options->Get(Nan::GetCurrentContext(), Nan::New<String>("create").ToLocalChecked()).ToLocalChecked();
if (create->IsBoolean() ? !create->BooleanValue(Nan::GetCurrentContext()).ToChecked() : true) {
txnFlags |= MDB_RDONLY;
}

auto txnObj = options->Get(Nan::New<String>("txn").ToLocalChecked());
auto txnObj = options->Get(Nan::GetCurrentContext(), Nan::New<String>("txn").ToLocalChecked()).ToLocalChecked();
if (!txnObj->IsNull() && !txnObj->IsUndefined() && txnObj->IsObject()) {
TxnWrap *tw = Nan::ObjectWrap::Unwrap<TxnWrap>(txnObj->ToObject());
TxnWrap *tw = Nan::ObjectWrap::Unwrap<TxnWrap>(Local<Object>::Cast(txnObj));
needsTransaction = false;
txn = tw->txn;
}
Expand All @@ -129,7 +129,7 @@ NAN_METHOD(DbiWrap::ctor) {

// Open database
// NOTE: nullptr in place of the name means using the unnamed database.
rc = mdb_dbi_open(txn, nameIsNull ? nullptr : *String::Utf8Value(name), flags, &dbi);
rc = mdb_dbi_open(txn, nameIsNull ? nullptr : *String::Utf8Value(Isolate::GetCurrent(), name), flags, &dbi);
if (rc != 0) {
if (needsTransaction) {
mdb_txn_abort(txn);
Expand Down Expand Up @@ -192,16 +192,16 @@ NAN_METHOD(DbiWrap::drop) {

// Check if the database should be deleted
if (info.Length() == 1 && info[0]->IsObject()) {
Handle<Object> options = info[0]->ToObject();
Local<Object> options = Local<Object>::Cast(info[0]);

// Just free pages
Local<Value> opt = options->Get(Nan::New<String>("justFreePages").ToLocalChecked());
del = opt->IsBoolean() ? !(opt->BooleanValue()) : 1;
Local<Value> opt = options->Get(Nan::GetCurrentContext(), Nan::New<String>("justFreePages").ToLocalChecked()).ToLocalChecked();
del = opt->IsBoolean() ? !(opt->BooleanValue(Nan::GetCurrentContext()).ToChecked()) : 1;

// User-supplied txn
auto txnObj = options->Get(Nan::New<String>("txn").ToLocalChecked());
auto txnObj = options->Get(Nan::GetCurrentContext(), Nan::New<String>("txn").ToLocalChecked()).ToLocalChecked();
if (!txnObj->IsNull() && !txnObj->IsUndefined() && txnObj->IsObject()) {
TxnWrap *tw = Nan::ObjectWrap::Unwrap<TxnWrap>(txnObj->ToObject());
TxnWrap *tw = Nan::ObjectWrap::Unwrap<TxnWrap>(Local<Object>::Cast(txnObj));
needsTransaction = false;
txn = tw->txn;
}
Expand Down Expand Up @@ -249,17 +249,19 @@ NAN_METHOD(DbiWrap::stat) {
return Nan::ThrowError("dbi.stat should be called with a single argument which is a txn.");
}

TxnWrap *txn = Nan::ObjectWrap::Unwrap<TxnWrap>(info[0]->ToObject());
TxnWrap *txn = Nan::ObjectWrap::Unwrap<TxnWrap>(Local<Object>::Cast(info[0]));

MDB_stat stat;
mdb_stat(txn->txn, dw->dbi, &stat);

Local<Context> context = Nan::GetCurrentContext();
Local<Object> obj = Nan::New<Object>();
obj->Set(Nan::New<String>("pageSize").ToLocalChecked(), Nan::New<Number>(stat.ms_psize));
obj->Set(Nan::New<String>("treeDepth").ToLocalChecked(), Nan::New<Number>(stat.ms_depth));
obj->Set(Nan::New<String>("treeBranchPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_branch_pages));
obj->Set(Nan::New<String>("treeLeafPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_leaf_pages));
obj->Set(Nan::New<String>("entryCount").ToLocalChecked(), Nan::New<Number>(stat.ms_entries));
obj->Set(context, Nan::New<String>("pageSize").ToLocalChecked(), Nan::New<Number>(stat.ms_psize));
obj->Set(context, Nan::New<String>("treeDepth").ToLocalChecked(), Nan::New<Number>(stat.ms_depth));
obj->Set(context, Nan::New<String>("treeBranchPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_branch_pages));
obj->Set(context, Nan::New<String>("treeLeafPageCount").ToLocalChecked(), Nan::New<Number>(stat.ms_leaf_pages));
obj->Set(context, Nan::New<String>("entryCount").ToLocalChecked(), Nan::New<Number>(stat.ms_entries));
obj->Set(context, Nan::New<String>("overflowPages").ToLocalChecked(), Nan::New<Number>(stat.ms_overflow_pages));

info.GetReturnValue().Set(obj);
}
Loading

0 comments on commit 7dd8107

Please sign in to comment.