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

Commit

Permalink
NanBooleanOptionValue -> BooleanOptionValue
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphtheninja committed May 12, 2015
1 parent 5d5a7e9 commit 39c614a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ bench/
*.obj
*.1sdk.pdb
*.lastbuildstate
npm-debug.log
3 changes: 2 additions & 1 deletion src/batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "database.h"
#include "batch_async.h"
#include "batch.h"
#include "common.h"

namespace leveldown {

Expand Down Expand Up @@ -47,7 +48,7 @@ NAN_METHOD(Batch::New) {
optionsObj = v8::Local<v8::Object>::Cast(args[1]);
}

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

Batch* batch = new Batch(database, sync);
batch->Wrap(args.This());
Expand Down
29 changes: 29 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright (c) 2012-2015 LevelDOWN contributors
* See list at <https://github.com/level/leveldown#contributing>
* MIT License <https://github.com/level/leveldown/blob/master/LICENSE.md>
*/

#ifndef LD_COMMON_H
#define LD_COMMON_H

#include <nan.h>

namespace leveldown {

NAN_INLINE bool BooleanOptionValue(v8::Local<v8::Object> options,
v8::Handle<v8::String> key,
bool def = false) {
if (def) {
return options.IsEmpty()
|| !options->Has(key)
|| options->Get(key)->BooleanValue();
} else {
return !options.IsEmpty()
&& options->Has(key)
&& options->Get(key)->BooleanValue();
}
}

} // namespace leveldown

#endif
18 changes: 9 additions & 9 deletions src/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "database_async.h"
#include "batch.h"
#include "iterator.h"
#include "common.h"

namespace leveldown {

Expand Down Expand Up @@ -187,15 +188,14 @@ NAN_METHOD(Database::Open) {

LD_METHOD_SETUP_COMMON(open, 0, 1)

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

uint32_t cacheSize = NanUInt32OptionValue(
optionsObj
Expand Down Expand Up @@ -318,7 +318,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, NanNew("sync"));
bool sync = BooleanOptionValue(optionsObj, NanNew("sync"));

WriteWorker* worker = new WriteWorker(
database
Expand Down Expand Up @@ -346,8 +346,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, NanNew("asBuffer"), true);
bool fillCache = NanBooleanOptionValue(optionsObj, NanNew("fillCache"), true);
bool asBuffer = BooleanOptionValue(optionsObj, NanNew("asBuffer"), true);
bool fillCache = BooleanOptionValue(optionsObj, NanNew("fillCache"), true);

ReadWorker* worker = new ReadWorker(
database
Expand All @@ -373,7 +373,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, NanNew("sync"));
bool sync = BooleanOptionValue(optionsObj, NanNew("sync"));

DeleteWorker* worker = new DeleteWorker(
database
Expand Down Expand Up @@ -403,7 +403,7 @@ NAN_METHOD(Database::Batch) {

LD_METHOD_SETUP_COMMON(batch, 1, 2)

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

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

Expand Down
13 changes: 7 additions & 6 deletions src/iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "database.h"
#include "iterator.h"
#include "iterator_async.h"
#include "common.h"

namespace leveldown {

Expand Down Expand Up @@ -314,7 +315,7 @@ NAN_METHOD(Iterator::New) {
if (args.Length() > 1 && args[2]->IsObject()) {
optionsObj = v8::Local<v8::Object>::Cast(args[2]);

reverse = NanBooleanOptionValue(optionsObj, NanNew("reverse"));
reverse = BooleanOptionValue(optionsObj, NanNew("reverse"));

if (optionsObj->Has(NanNew("start"))
&& (node::Buffer::HasInstance(optionsObj->Get(NanNew("start")))
Expand Down Expand Up @@ -414,19 +415,19 @@ NAN_METHOD(Iterator::New) {

}

bool keys = NanBooleanOptionValue(optionsObj, NanNew("keys"), true);
bool values = NanBooleanOptionValue(optionsObj, NanNew("values"), true);
bool keyAsBuffer = NanBooleanOptionValue(
bool keys = BooleanOptionValue(optionsObj, NanNew("keys"), true);
bool values = BooleanOptionValue(optionsObj, NanNew("values"), true);
bool keyAsBuffer = BooleanOptionValue(
optionsObj
, NanNew("keyAsBuffer")
, true
);
bool valueAsBuffer = NanBooleanOptionValue(
bool valueAsBuffer = BooleanOptionValue(
optionsObj
, NanNew("valueAsBuffer")
, true
);
bool fillCache = NanBooleanOptionValue(optionsObj, NanNew("fillCache"));
bool fillCache = BooleanOptionValue(optionsObj, NanNew("fillCache"));

Iterator* iterator = new Iterator(
database
Expand Down

0 comments on commit 39c614a

Please sign in to comment.