Skip to content

Commit

Permalink
removed nan
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaWise committed Jun 2, 2017
1 parent 17d1c23 commit 44248bf
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 100 deletions.
1 change: 0 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"targets": [
{
"target_name": "better_sqlite3",
"include_dirs": ["<!(node -e \"require('nan')\")"],
"dependencies": [
"deps/sqlite3.gyp:sqlite3"
],
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"dependencies": {
"bindings": "^1.2.1",
"nan": "^2.5.1",
"to-descriptor": "^1.0.1"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions src2/better_sqlite3.lzz
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <set>
#include <unordered_map>
#include <sqlite3.h>
#include <nan.h>
#include <node.h>
#include <node_object_wrap.h>
#include <node_buffer.h>
#end
#src
NODE_MODULE(better_sqlite3, RegisterModule);
Expand All @@ -28,7 +30,7 @@ NODE_MODULE(better_sqlite3, RegisterModule);
#insert "binding/multi-binder.lzz"

void RegisterModule(v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {
v8::Isolate* isolate = exports->CreationContext()->GetIsolate();
EasyIsolate;
NewHandleScope;
CS::_Init(isolate);
ResultCodes::_Init(isolate);
Expand Down
36 changes: 14 additions & 22 deletions src2/objects/database.lzz
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Statement;
class Transaction;
class Database : public Nan::ObjectWrap {
class Database : public node::ObjectWrap {
public:

// Proper error handling logic for when an sqlite3 operation fails.
Expand Down Expand Up @@ -51,7 +51,7 @@ public:

private:

explicit Database(DatabaseHandles* handles) : Nan::ObjectWrap(),
explicit Database(DatabaseHandles* handles) : node::ObjectWrap(),
db_handle(handles->db_handle),
extras(new DatabaseExtras(handles)),
open(true),
Expand All @@ -76,29 +76,21 @@ private:
};

REGISTER(Init) {
v8::Local<v8::FunctionTemplate> t = Nan::New<v8::FunctionTemplate>(JS_new);
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate, JS_new);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(CS::Get(isolate, CS::Database));
t->SetClassName(StringFromUtf8(isolate, "Database"));

Nan::SetPrototypeMethod(t, "prepare", JS_prepare);
Nan::SetPrototypeMethod(t, "transaction", JS_transaction);
Nan::SetPrototypeMethod(t, "exec", JS_exec);
Nan::SetPrototypeMethod(t, "pragma", JS_pragma);
Nan::SetPrototypeMethod(t, "checkpoint", JS_checkpoint);
Nan::SetPrototypeMethod(t, "register", JS_register);
Nan::SetPrototypeMethod(t, "close", JS_close);
Nan::SetPrototypeMethod(t, "defaultSafeIntegers", JS_defaultSafeIntegers);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::prepare), JS_prepare);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::transaction), JS_transaction);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::exec), JS_exec);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::pragma), JS_pragma);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::checkpoint), JS_checkpoint);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::register_), JS_register);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::close), JS_close);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::defaultSafeIntegers), JS_defaultSafeIntegers);
Nan::SetAccessor(t->InstanceTemplate(), CS::Get(isolate, CS::open), JS_open);
NODE_SET_PROTOTYPE_METHOD(t, "prepare", JS_prepare);
NODE_SET_PROTOTYPE_METHOD(t, "transaction", JS_transaction);
NODE_SET_PROTOTYPE_METHOD(t, "exec", JS_exec);
NODE_SET_PROTOTYPE_METHOD(t, "pragma", JS_pragma);
NODE_SET_PROTOTYPE_METHOD(t, "checkpoint", JS_checkpoint);
NODE_SET_PROTOTYPE_METHOD(t, "register", JS_register);
NODE_SET_PROTOTYPE_METHOD(t, "close", JS_close);
NODE_SET_PROTOTYPE_METHOD(t, "defaultSafeIntegers", JS_defaultSafeIntegers);
NODE_SET_PROTOTYPE_GETTER(t, "open", JS_open);

Nan::Set(exports, CS::Get(isolate, CS::Database), Nan::GetFunction(t).ToLocalChecked());
exports->Set(StringFromUtf8(isolate, "Database"), t->GetFunction(OnlyContext).ToLocalChecked());
}

NODE_METHOD(JS_new) {
Expand Down
33 changes: 13 additions & 20 deletions src2/objects/statement.lzz
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Statement : public Nan::ObjectWrap, public Query {
class Statement : public node::ObjectWrap, public Query {
public:

// Provides public access to the constructor.
Expand Down Expand Up @@ -40,7 +40,7 @@ public:

private:

explicit Statement(Database* _db, sqlite3_stmt* _handle, bool _returns_data) : Nan::ObjectWrap(), Query(next_id++),
explicit Statement(Database* _db, sqlite3_stmt* _handle, bool _returns_data) : node::ObjectWrap(), Query(next_id++),
db(_db),
handle(_handle),
alive(true),
Expand All @@ -57,27 +57,20 @@ private:
}

REGISTER(Init) {
v8::Local<v8::FunctionTemplate> t = Nan::New<v8::FunctionTemplate>(JS_new);
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate, JS_new);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(CS::Get(isolate, CS::Statement));
t->SetClassName(StringFromUtf8(isolate, "Statement"));

Nan::SetPrototypeMethod(t, "run", JS_run);
Nan::SetPrototypeMethod(t, "get", JS_get);
Nan::SetPrototypeMethod(t, "all", JS_all);
Nan::SetPrototypeMethod(t, "each", JS_each);
Nan::SetPrototypeMethod(t, "bind", JS_bind);
Nan::SetPrototypeMethod(t, "pluck", JS_pluck);
Nan::SetPrototypeMethod(t, "safeIntegers", JS_safeIntegers);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::run), JS_run);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::get), JS_get);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::all), JS_all);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::each), JS_each);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::bind), JS_bind);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::pluck), JS_pluck);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::safeIntegers), JS_safeIntegers);
Nan::SetAccessor(t->InstanceTemplate(), CS::Get(isolate, CS::returnsData), JS_returnsData);
NODE_SET_PROTOTYPE_METHOD(t, "run", JS_run);
NODE_SET_PROTOTYPE_METHOD(t, "get", JS_get);
NODE_SET_PROTOTYPE_METHOD(t, "all", JS_all);
NODE_SET_PROTOTYPE_METHOD(t, "each", JS_each);
NODE_SET_PROTOTYPE_METHOD(t, "bind", JS_bind);
NODE_SET_PROTOTYPE_METHOD(t, "pluck", JS_pluck);
NODE_SET_PROTOTYPE_METHOD(t, "safeIntegers", JS_safeIntegers);
NODE_SET_PROTOTYPE_GETTER(t, "returnsData", JS_returnsData);

constructor.Reset(isolate, Nan::GetFunction(t).ToLocalChecked());
constructor.Reset(isolate, t->GetFunction(OnlyContext).ToLocalChecked());
next_id = 0;
constructing_privileges = false;
}
Expand Down
19 changes: 8 additions & 11 deletions src2/objects/transaction.lzz
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Transaction : public Nan::ObjectWrap, public Query {
class Transaction : public node::ObjectWrap, public Query {
public:

// Provides public access to the constructor.
Expand Down Expand Up @@ -46,7 +46,7 @@ public:

private:

explicit Transaction(Database* _db, TransactionHandles* _handles) : Nan::ObjectWrap(), Query(next_id++),
explicit Transaction(Database* _db, TransactionHandles* _handles) : node::ObjectWrap(), Query(next_id++),
db(_db),
handles(_handles->handles),
handle_count(_handles->handle_count),
Expand All @@ -64,18 +64,15 @@ private:
}

REGISTER(Init) {
v8::Local<v8::FunctionTemplate> t = Nan::New<v8::FunctionTemplate>(JS_new);
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate, JS_new);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(CS::Get(isolate, CS::Transaction));
t->SetClassName(StringFromUtf8(isolate, "Transaction"));

Nan::SetPrototypeMethod(t, "run", JS_run);
Nan::SetPrototypeMethod(t, "bind", JS_bind);
Nan::SetPrototypeMethod(t, "safeIntegers", JS_safeIntegers);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::run), JS_run);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::bind), JS_bind);
// Nan::SetPrototypeMethod(t, CS::Get(isolate, CS::safeIntegers), JS_safeIntegers);
NODE_SET_PROTOTYPE_METHOD(t, "run", JS_run);
NODE_SET_PROTOTYPE_METHOD(t, "bind", JS_bind);
NODE_SET_PROTOTYPE_METHOD(t, "safeIntegers", JS_safeIntegers);

constructor.Reset(isolate, Nan::GetFunction(t).ToLocalChecked());
constructor.Reset(isolate, t->GetFunction(OnlyContext).ToLocalChecked());
next_id = 0;
constructing_privileges = false;
}
Expand Down
40 changes: 0 additions & 40 deletions src2/util/constants.lzz
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace CS {
ConstantString Database;
ConstantString database;
ConstantString open;
ConstantString source;
ConstantString memory;
ConstantString readonly;
Expand All @@ -10,26 +8,8 @@ namespace CS {
ConstantString length;
ConstantString done;
ConstantString value;
ConstantString Statement;
ConstantString returnsData;
ConstantString Transaction;
ConstantString changes;
ConstantString lastInsertROWID;
ConstantString prepare;
ConstantString transaction;
ConstantString exec;
ConstantString pragma;
ConstantString checkpoint;
ConstantString register_;
ConstantString close;
ConstantString defaultSafeIntegers;
ConstantString run;
ConstantString get;
ConstantString all;
ConstantString each;
ConstantString bind;
ConstantString pluck;
ConstantString safeIntegers;
ConstantString code;

v8::Local<v8::String> _InternalizedFromLatin1(v8::Isolate* isolate, const char* data) {
Expand All @@ -40,9 +20,7 @@ namespace CS {
}

void _Init(v8::Isolate* isolate) {
CS::Database.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "Database"));
CS::database.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "database"));
CS::open.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "open"));
CS::source.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "source"));
CS::memory.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "memory"));
CS::readonly.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "readonly"));
Expand All @@ -51,26 +29,8 @@ namespace CS {
CS::length.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "length"));
CS::done.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "done"));
CS::value.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "value"));
CS::Statement.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "Statement"));
CS::returnsData.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "returnsData"));
CS::Transaction.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "Transaction"));
CS::changes.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "changes"));
CS::lastInsertROWID.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "lastInsertROWID"));
CS::prepare.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "prepare"));
CS::transaction.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "transaction"));
CS::exec.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "exec"));
CS::pragma.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "pragma"));
CS::checkpoint.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "checkpoint"));
CS::register_.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "register"));
CS::close.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "close"));
CS::defaultSafeIntegers.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "defaultSafeIntegers"));
CS::run.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "run"));
CS::get.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "get"));
CS::all.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "all"));
CS::each.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "each"));
CS::bind.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "bind"));
CS::pluck.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "pluck"));
CS::safeIntegers.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "safeIntegers"));
CS::code.Reset(isolate, CS::_InternalizedFromLatin1(isolate, "code"));
}
}
20 changes: 17 additions & 3 deletions src2/util/macros.lzz
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define NODE_ARGUMENTS const Nan::FunctionCallbackInfo<v8::Value>&
#define NODE_ARGUMENTS const v8::FunctionCallbackInfo<v8::Value>&
#define NODE_METHOD(name) static void name(NODE_ARGUMENTS info)
#define NODE_GETTER(name) static void name(v8::Local<v8::String> _, const Nan::PropertyCallbackInfo<v8::Value>& info)
#define NODE_GETTER(name) static void name(v8::Local<v8::String> _, const v8::PropertyCallbackInfo<v8::Value>& info)
#define REGISTER(name) friend void RegisterModule(v8::Local<v8::Object> exports, v8::Local<v8::Object> module); static void name(v8::Isolate* isolate, v8::Local<v8::Object> exports)

#define NewHandleScope v8::HandleScope scope(isolate)
Expand All @@ -12,7 +12,7 @@
#define OnlyContext isolate->GetCurrentContext()
#define OnlyIsolateAndContext info.GetIsolate()->GetCurrentContext()

#define Unwrap Nan::ObjectWrap::Unwrap
#define Unwrap node::ObjectWrap::Unwrap

inline v8::Local<v8::String> StringFromUtf8(v8::Isolate* isolate, const char* data, int length) {
return v8::String::NewFromUtf8(isolate, data, v8::NewStringType::kNormal, length).ToLocalChecked();
Expand Down Expand Up @@ -107,6 +107,20 @@ template<class T> inline void FREE_ARRAY(T* array_pointer) {
::operator delete[](array_pointer);
}

inline void NODE_SET_PROTOTYPE_GETTER(v8::Local<v8::FunctionTemplate> recv, const char* name, v8::AccessorGetterCallback getter) {
EasyIsolate;
NewHandleScope;
recv->InstanceTemplate()->SetAccessor(
StringFromLatin1(isolate, name),
getter,
0,
v8::Local<v8::Value>(),
v8::AccessControl::ALL_CAN_READ,
v8::PropertyAttribute::None,
v8::AccessorSignature::New(isolate, recv)
);
}

#hdr
typedef v8::Local<v8::Value> (*ErrorType)(v8::Local<v8::String>);
typedef v8::Persistent<v8::String> ConstantString;
Expand Down

0 comments on commit 44248bf

Please sign in to comment.