Skip to content

Commit

Permalink
general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaWise committed Sep 2, 2023
1 parent 3400cb0 commit f11c36c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 52 deletions.
16 changes: 7 additions & 9 deletions deps/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ if (process.argv[3]) {
}

for (const { filename, optional } of files) {
if (optional && !fs.existsSync(path.join(source, filename))) {
const sourceFilepath = path.join(source, filename);
const destFilepath = path.join(dest, filename);

if (optional && !fs.existsSync(sourceFilepath)) {
continue;
}

fs.accessSync(path.join(source, filename));

// Ensure destination folder exists
const destFolder = path.dirname(path.join(dest, filename));
fs.mkdirSync(destFolder, { recursive: true });

// Copy file over
fs.copyFileSync(path.join(source, filename), path.join(dest, filename));
fs.accessSync(sourceFilepath);
fs.mkdirSync(path.dirname(destFilepath), { recursive: true });
fs.copyFileSync(sourceFilepath, destFilepath);
}
37 changes: 10 additions & 27 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,17 @@ function Database(filenameGiven, options) {

// Load the native addon
let addon;
switch(true) {
case nativeBinding == null: {
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require('bindings')('better_sqlite3.node'));
break;
}

case typeof nativeBinding === 'string': {
// If webpack is used to build the application, we must use `__non_webpack_require__`.
// See <https://webpack.js.org/api/module-variables/#__non_webpack_require__-webpack-specific>
const requireFunc =
typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;

addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, '.node'));
break;
}

case typeof nativeBinding === 'object': {
// If `nativeBinding` is addon object.
// See <https://github.com/WiseLibs/better-sqlite3/issues/972>
addon = nativeBinding;
break;
}

default: {
throw new TypeError('nativeBinding has an invalid value passed');
}
if (nativeBinding == null) {
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require('bindings')('better_sqlite3.node'));
} else if (typeof nativeBinding === 'string') {
// See <https://webpack.js.org/api/module-variables/#__non_webpack_require__-webpack-specific>
const requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;
addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, '.node'));
} else {
// See <https://github.com/WiseLibs/better-sqlite3/issues/972>
addon = nativeBinding;
}

if (!addon.isInitialized) {
addon.setErrorConstructor(SqliteError);
addon.isInitialized = true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"window functions",
"database"
]
}
}
14 changes: 7 additions & 7 deletions src/better_sqlite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
#include "better_sqlite3.hpp"
#line 161 "./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)
#define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) node::Buffer::New(env, data, length, finalizeCallback, finalizeHint)
#else
static inline v8::MaybeLocal<v8::Object> BufferSandboxNew(v8::Isolate* isolate, char* data, size_t length, void (*finalizeCallback)(char*, void*), void* finalizeHint) {
v8::MaybeLocal<v8::Object> buffer = node::Buffer::Copy(isolate, data, length);
finalizeCallback(data, finalizeHint);
return buffer;
}
# define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) BufferSandboxNew(env, data, length, finalizeCallback, finalizeHint)
static inline v8::MaybeLocal<v8::Object> BufferSandboxNew(v8::Isolate* isolate, char* data, size_t length, void (*finalizeCallback)(char*, void*), void* finalizeHint) {
v8::MaybeLocal<v8::Object> buffer = node::Buffer::Copy(isolate, data, length);
finalizeCallback(data, finalizeHint);
return buffer;
}
#define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) BufferSandboxNew(env, data, length, finalizeCallback, finalizeHint)
#endif
#line 39 "./src/util/binder.lzz"
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
Expand Down
16 changes: 8 additions & 8 deletions src/util/macros.lzz
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ void SetPrototypeGetter(

#src
#ifndef V8_COMPRESS_POINTERS_IN_SHARED_CAGE
# define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) node::Buffer::New(env, data, length, finalizeCallback, finalizeHint)
#define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) node::Buffer::New(env, data, length, finalizeCallback, finalizeHint)
#else
static inline v8::MaybeLocal<v8::Object> BufferSandboxNew(v8::Isolate* isolate, char* data, size_t length, void (*finalizeCallback)(char*, void*), void* finalizeHint) {
v8::MaybeLocal<v8::Object> buffer = node::Buffer::Copy(isolate, data, length);
finalizeCallback(data, finalizeHint);
return buffer;
}
# define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) BufferSandboxNew(env, data, length, finalizeCallback, finalizeHint)
static inline v8::MaybeLocal<v8::Object> BufferSandboxNew(v8::Isolate* isolate, char* data, size_t length, void (*finalizeCallback)(char*, void*), void* finalizeHint) {
v8::MaybeLocal<v8::Object> buffer = node::Buffer::Copy(isolate, data, length);
finalizeCallback(data, finalizeHint);
return buffer;
}
#define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) BufferSandboxNew(env, data, length, finalizeCallback, finalizeHint)
#endif
#end
#end

0 comments on commit f11c36c

Please sign in to comment.