From a0227e3fd4567ebc9683c0e21c0ac4719c51d2f7 Mon Sep 17 00:00:00 2001 From: neoxpert <18628980+neoxpert@users.noreply.github.com> Date: Sun, 11 Sep 2022 00:23:12 +0200 Subject: [PATCH] conditional compile with CreationContext for NodeJs < 16 --- src/better_sqlite3.cpp | 50 +++++++++++++++++++++++------------------- src/better_sqlite3.hpp | 24 ++++++++++---------- src/util/binder.lzz | 12 +++++++++- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/better_sqlite3.cpp b/src/better_sqlite3.cpp index 0cfaf5184..49072e678 100644 --- a/src/better_sqlite3.cpp +++ b/src/better_sqlite3.cpp @@ -2,6 +2,21 @@ // #include "better_sqlite3.hpp" +#line 39 "./src/util/binder.lzz" + static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj) { + v8::Local proto = obj->GetPrototype(); + + #if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 93 + v8::Local ctx = obj->CreationContext(); + #else + v8::Local ctx = obj->GetCreationContext().ToLocalChecked(); + #endif + + ctx->Enter(); + v8::Local baseProto = v8::Object::New(isolate)->GetPrototype(); + ctx->Exit(); + return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate)); + } #line 67 "./src/better_sqlite3.lzz" NODE_MODULE_INIT(/* exports, context */) { v8::Isolate* isolate = context->GetIsolate(); @@ -1943,20 +1958,9 @@ bool Binder::Bind (v8::FunctionCallbackInfo const & info, int argc } return success; } -#line 35 "./src/util/binder.lzz" -bool Binder::IsPlainObject (v8::Isolate * isolate, v8::Local obj) -#line 35 "./src/util/binder.lzz" - { - v8::Local proto = obj->GetPrototype(); - v8::Local ctx = obj->GetCreationContext().ToLocalChecked(); - ctx->Enter(); - v8::Local baseProto = v8::Object::New(isolate)->GetPrototype(); - ctx->Exit(); - return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate)); -} -#line 44 "./src/util/binder.lzz" +#line 54 "./src/util/binder.lzz" void Binder::Fail (void (* Throw) (char const *), char const * message) -#line 44 "./src/util/binder.lzz" +#line 54 "./src/util/binder.lzz" { assert(success == true); assert((Throw == NULL) == (message == NULL)); @@ -1964,16 +1968,16 @@ void Binder::Fail (void (* Throw) (char const *), char const * message) if (Throw) Throw(message); success = false; } -#line 52 "./src/util/binder.lzz" +#line 62 "./src/util/binder.lzz" int Binder::NextAnonIndex () -#line 52 "./src/util/binder.lzz" +#line 62 "./src/util/binder.lzz" { while (sqlite3_bind_parameter_name(handle, ++anon_index) != NULL) {} return anon_index; } -#line 58 "./src/util/binder.lzz" +#line 68 "./src/util/binder.lzz" void Binder::BindValue (v8::Isolate * isolate, v8::Local value, int index) -#line 58 "./src/util/binder.lzz" +#line 68 "./src/util/binder.lzz" { int status = Data::BindValueFromJS(isolate, handle, index, value); if (status != SQLITE_OK) { @@ -1992,9 +1996,9 @@ void Binder::BindValue (v8::Isolate * isolate, v8::Local value, int assert(false); } } -#line 79 "./src/util/binder.lzz" +#line 89 "./src/util/binder.lzz" int Binder::BindArray (v8::Isolate * isolate, v8::Local arr) -#line 79 "./src/util/binder.lzz" +#line 89 "./src/util/binder.lzz" { v8 :: Local < v8 :: Context > ctx = isolate -> GetCurrentContext ( ) ; uint32_t length = arr->Length(); @@ -2016,9 +2020,9 @@ int Binder::BindArray (v8::Isolate * isolate, v8::Local arr) } return len; } -#line 105 "./src/util/binder.lzz" +#line 115 "./src/util/binder.lzz" int Binder::BindObject (v8::Isolate * isolate, v8::Local obj, Statement * stmt) -#line 105 "./src/util/binder.lzz" +#line 115 "./src/util/binder.lzz" { v8 :: Local < v8 :: Context > ctx = isolate -> GetCurrentContext ( ) ; BindMap* bind_map = stmt->GetBindMap(isolate); @@ -2055,9 +2059,9 @@ int Binder::BindObject (v8::Isolate * isolate, v8::Local obj, State return len; } -#line 149 "./src/util/binder.lzz" +#line 159 "./src/util/binder.lzz" Binder::Result Binder::BindArgs (v8::FunctionCallbackInfo const & info, int argc, Statement * stmt) -#line 149 "./src/util/binder.lzz" +#line 159 "./src/util/binder.lzz" { v8 :: Isolate * isolate = info . GetIsolate ( ) ; int count = 0; diff --git a/src/better_sqlite3.hpp b/src/better_sqlite3.hpp index 5d25ee970..17e903590 100644 --- a/src/better_sqlite3.hpp +++ b/src/better_sqlite3.hpp @@ -18,6 +18,8 @@ #include #line 31 "./src/util/macros.lzz" template using CopyablePersistent = v8::Persistent>; +#line 36 "./src/util/binder.lzz" + static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj); #define LZZ_INLINE inline #line 16 "./src/util/macros.lzz" v8::Local StringFromUtf8 (v8::Isolate * isolate, char const * data, int length); @@ -752,27 +754,25 @@ class Binder #line 32 "./src/util/binder.lzz" bool bound_object; }; -#line 35 "./src/util/binder.lzz" - static bool IsPlainObject (v8::Isolate * isolate, v8::Local obj); -#line 44 "./src/util/binder.lzz" +#line 54 "./src/util/binder.lzz" void Fail (void (* Throw) (char const *), char const * message); -#line 52 "./src/util/binder.lzz" +#line 62 "./src/util/binder.lzz" int NextAnonIndex (); -#line 58 "./src/util/binder.lzz" +#line 68 "./src/util/binder.lzz" void BindValue (v8::Isolate * isolate, v8::Local value, int index); -#line 79 "./src/util/binder.lzz" +#line 89 "./src/util/binder.lzz" int BindArray (v8::Isolate * isolate, v8::Local arr); -#line 105 "./src/util/binder.lzz" +#line 115 "./src/util/binder.lzz" int BindObject (v8::Isolate * isolate, v8::Local obj, Statement * stmt); -#line 149 "./src/util/binder.lzz" +#line 159 "./src/util/binder.lzz" Result BindArgs (v8::FunctionCallbackInfo const & info, int argc, Statement * stmt); -#line 189 "./src/util/binder.lzz" +#line 199 "./src/util/binder.lzz" sqlite3_stmt * handle; -#line 190 "./src/util/binder.lzz" +#line 200 "./src/util/binder.lzz" int param_count; -#line 191 "./src/util/binder.lzz" +#line 201 "./src/util/binder.lzz" int anon_index; -#line 192 "./src/util/binder.lzz" +#line 202 "./src/util/binder.lzz" bool success; }; #line 34 "./src/better_sqlite3.lzz" diff --git a/src/util/binder.lzz b/src/util/binder.lzz index 512249668..479bbf8f1 100644 --- a/src/util/binder.lzz +++ b/src/util/binder.lzz @@ -32,15 +32,25 @@ private: bool bound_object; }; +#hdr + static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj); +#end +#src static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj) { v8::Local proto = obj->GetPrototype(); + + #if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 93 + v8::Local ctx = obj->CreationContext(); + #else v8::Local ctx = obj->GetCreationContext().ToLocalChecked(); + #endif + ctx->Enter(); v8::Local baseProto = v8::Object::New(isolate)->GetPrototype(); ctx->Exit(); return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate)); } - +#end void Fail(void (*Throw)(const char* _), const char* message) { assert(success == true); assert((Throw == NULL) == (message == NULL));