From ab93015346489265a2e90242c04e9a5dba11cea0 Mon Sep 17 00:00:00 2001 From: Mahesh Bandara Wijerathna Date: Fri, 5 Apr 2024 09:52:39 +0530 Subject: [PATCH] Support builds for Electron v29 Co-authored-by: neoxpert <18628980+neoxpert@users.noreply.github.com> --- .github/workflows/prebuild.yml | 2 +- package.json | 2 +- src/better_sqlite3.cpp | 44 ++++++++++++++++++++++------------ src/better_sqlite3.hpp | 10 ++++++-- src/util/macros.lzz | 22 +++++++++++++++++ 5 files changed, 61 insertions(+), 19 deletions(-) diff --git a/.github/workflows/prebuild.yml b/.github/workflows/prebuild.yml index 1f09a48a..87809362 100644 --- a/.github/workflows/prebuild.yml +++ b/.github/workflows/prebuild.yml @@ -7,7 +7,7 @@ on: env: NODE_BUILD_CMD: npx --no-install prebuild -r node -t 18.0.0 -t 20.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }} - ELECTRON_BUILD_CMD: npx --no-install prebuild -r electron -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 -t 22.0.0 -t 23.0.0 -t 24.0.0 -t 25.0.0 -t 26.0.0 -t 27.0.0 -t 28.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }} + ELECTRON_BUILD_CMD: npx --no-install prebuild -r electron -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 -t 22.0.0 -t 23.0.0 -t 24.0.0 -t 25.0.0 -t 26.0.0 -t 27.0.0 -t 28.0.0 -t 29.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }} jobs: prebuild: diff --git a/package.json b/package.json index 3dc6beaf..55118e79 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "fs-extra": "^11.1.1", "mocha": "^10.2.0", "nodemark": "^0.3.0", - "prebuild": "^12.0.0", + "prebuild": "^13.0.0", "sqlite": "^5.0.1", "sqlite3": "^5.1.6" }, diff --git a/src/better_sqlite3.cpp b/src/better_sqlite3.cpp index 8851d9c1..76fe087e 100644 --- a/src/better_sqlite3.cpp +++ b/src/better_sqlite3.cpp @@ -2,7 +2,35 @@ // #include "better_sqlite3.hpp" -#line 161 "./src/util/macros.lzz" +#line 153 "./src/util/macros.lzz" +void SetPrototypeGetter( + v8::Isolate* isolate, + v8::Local data, + v8::Local recv, + const char* name, + v8::AccessorGetterCallback func +) { + v8::HandleScope scope(isolate); + + #if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 121 + recv->InstanceTemplate()->SetAccessor( + InternalizedFromLatin1(isolate, name), + func, + 0, + data, + v8::AccessControl::DEFAULT, + v8::PropertyAttribute::None + ); + #else + recv->InstanceTemplate()->SetAccessor( + InternalizedFromLatin1(isolate, name), + func, + 0, + data + ); + #endif +} +#line 183 "./src/util/macros.lzz" #ifndef V8_COMPRESS_POINTERS_IN_SHARED_CAGE #define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) node::Buffer::New(env, data, length, finalizeCallback, finalizeHint) #else @@ -119,20 +147,6 @@ void SetPrototypeSymbolMethod (v8::Isolate * isolate, v8::Local d v8::FunctionTemplate::New(isolate, func, data, v8::Signature::New(isolate, recv)) ); } -#line 142 "./src/util/macros.lzz" -void SetPrototypeGetter (v8::Isolate * isolate, v8::Local data, v8::Local recv, char const * name, v8::AccessorGetterCallback func) -#line 148 "./src/util/macros.lzz" - { - v8::HandleScope scope(isolate); - recv->InstanceTemplate()->SetAccessor( - InternalizedFromLatin1(isolate, name), - func, - 0, - data, - v8::AccessControl::DEFAULT, - v8::PropertyAttribute::None - ); -} #line 4 "./src/util/constants.lzz" v8::Local CS::Code (v8::Isolate * isolate, int code) #line 4 "./src/util/constants.lzz" diff --git a/src/better_sqlite3.hpp b/src/better_sqlite3.hpp index 4e82644e..dc540dcb 100644 --- a/src/better_sqlite3.hpp +++ b/src/better_sqlite3.hpp @@ -18,6 +18,14 @@ #include #line 31 "./src/util/macros.lzz" template using CopyablePersistent = v8::Persistent>; +#line 144 "./src/util/macros.lzz" +void SetPrototypeGetter( + v8::Isolate* isolate, + v8::Local data, + v8::Local recv, + const char* name, + v8::AccessorGetterCallback func +); #line 36 "./src/util/binder.lzz" static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj); #define LZZ_INLINE inline @@ -53,8 +61,6 @@ v8::Local NewConstructorTemplate (v8::Isolate * isolate, void SetPrototypeMethod (v8::Isolate * isolate, v8::Local data, v8::Local recv, char const * name, v8::FunctionCallback func); #line 129 "./src/util/macros.lzz" void SetPrototypeSymbolMethod (v8::Isolate * isolate, v8::Local data, v8::Local recv, v8::Local symbol, v8::FunctionCallback func); -#line 142 "./src/util/macros.lzz" -void SetPrototypeGetter (v8::Isolate * isolate, v8::Local data, v8::Local recv, char const * name, v8::AccessorGetterCallback func); #line 1 "./src/util/constants.lzz" class CS { diff --git a/src/util/macros.lzz b/src/util/macros.lzz index 120be682..31b9850c 100644 --- a/src/util/macros.lzz +++ b/src/util/macros.lzz @@ -139,6 +139,17 @@ void SetPrototypeSymbolMethod( v8::FunctionTemplate::New(isolate, func, data, v8::Signature::New(isolate, recv)) ); } + +#hdr +void SetPrototypeGetter( + v8::Isolate* isolate, + v8::Local data, + v8::Local recv, + const char* name, + v8::AccessorGetterCallback func +); +#end +#src void SetPrototypeGetter( v8::Isolate* isolate, v8::Local data, @@ -147,6 +158,8 @@ void SetPrototypeGetter( v8::AccessorGetterCallback func ) { v8::HandleScope scope(isolate); + + #if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 121 recv->InstanceTemplate()->SetAccessor( InternalizedFromLatin1(isolate, name), func, @@ -155,7 +168,16 @@ void SetPrototypeGetter( v8::AccessControl::DEFAULT, v8::PropertyAttribute::None ); + #else + recv->InstanceTemplate()->SetAccessor( + InternalizedFromLatin1(isolate, name), + func, + 0, + data + ); + #endif } +#end #src #ifndef V8_COMPRESS_POINTERS_IN_SHARED_CAGE