diff --git a/binding.gyp b/binding.gyp index fba5763f..d2bba5b4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -3,7 +3,6 @@ "targets": [ { "target_name": "better_sqlite3", - "include_dirs": [" #include #include -#include +#include +#include +#include #end #src NODE_MODULE(better_sqlite3, RegisterModule); @@ -28,7 +30,7 @@ NODE_MODULE(better_sqlite3, RegisterModule); #insert "binding/multi-binder.lzz" void RegisterModule(v8::Local exports, v8::Local module) { - v8::Isolate* isolate = exports->CreationContext()->GetIsolate(); + EasyIsolate; NewHandleScope; CS::_Init(isolate); ResultCodes::_Init(isolate); diff --git a/src2/objects/database.lzz b/src2/objects/database.lzz index 20f1e58f..7d9fa510 100644 --- a/src2/objects/database.lzz +++ b/src2/objects/database.lzz @@ -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. @@ -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), @@ -76,29 +76,21 @@ private: }; REGISTER(Init) { - v8::Local t = Nan::New(JS_new); + v8::Local 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) { diff --git a/src2/objects/statement.lzz b/src2/objects/statement.lzz index 1ea41982..1dd478f1 100644 --- a/src2/objects/statement.lzz +++ b/src2/objects/statement.lzz @@ -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. @@ -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), @@ -57,27 +57,20 @@ private: } REGISTER(Init) { - v8::Local t = Nan::New(JS_new); + v8::Local 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; } diff --git a/src2/objects/transaction.lzz b/src2/objects/transaction.lzz index ac975493..eab724b8 100644 --- a/src2/objects/transaction.lzz +++ b/src2/objects/transaction.lzz @@ -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. @@ -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), @@ -64,18 +64,15 @@ private: } REGISTER(Init) { - v8::Local t = Nan::New(JS_new); + v8::Local 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; } diff --git a/src2/util/constants.lzz b/src2/util/constants.lzz index 586aa1b9..63ef827a 100644 --- a/src2/util/constants.lzz +++ b/src2/util/constants.lzz @@ -1,7 +1,5 @@ namespace CS { - ConstantString Database; ConstantString database; - ConstantString open; ConstantString source; ConstantString memory; ConstantString readonly; @@ -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 _InternalizedFromLatin1(v8::Isolate* isolate, const char* data) { @@ -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")); @@ -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")); } } diff --git a/src2/util/macros.lzz b/src2/util/macros.lzz index a43b760e..a6a1296d 100644 --- a/src2/util/macros.lzz +++ b/src2/util/macros.lzz @@ -1,6 +1,6 @@ -#define NODE_ARGUMENTS const Nan::FunctionCallbackInfo& +#define NODE_ARGUMENTS const v8::FunctionCallbackInfo& #define NODE_METHOD(name) static void name(NODE_ARGUMENTS info) -#define NODE_GETTER(name) static void name(v8::Local _, const Nan::PropertyCallbackInfo& info) +#define NODE_GETTER(name) static void name(v8::Local _, const v8::PropertyCallbackInfo& info) #define REGISTER(name) friend void RegisterModule(v8::Local exports, v8::Local module); static void name(v8::Isolate* isolate, v8::Local exports) #define NewHandleScope v8::HandleScope scope(isolate) @@ -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 StringFromUtf8(v8::Isolate* isolate, const char* data, int length) { return v8::String::NewFromUtf8(isolate, data, v8::NewStringType::kNormal, length).ToLocalChecked(); @@ -107,6 +107,20 @@ template inline void FREE_ARRAY(T* array_pointer) { ::operator delete[](array_pointer); } +inline void NODE_SET_PROTOTYPE_GETTER(v8::Local recv, const char* name, v8::AccessorGetterCallback getter) { + EasyIsolate; + NewHandleScope; + recv->InstanceTemplate()->SetAccessor( + StringFromLatin1(isolate, name), + getter, + 0, + v8::Local(), + v8::AccessControl::ALL_CAN_READ, + v8::PropertyAttribute::None, + v8::AccessorSignature::New(isolate, recv) + ); +} + #hdr typedef v8::Local (*ErrorType)(v8::Local); typedef v8::Persistent ConstantString;