Skip to content

Commit

Permalink
cleaned up poorly named template
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaWise committed Jun 11, 2024
1 parent 5ae61c3 commit 7ee4464
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 127 deletions.
34 changes: 17 additions & 17 deletions src/better_sqlite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//

#include "better_sqlite3.hpp"
#line 153 "./src/util/macros.lzz"
#line 150 "./src/util/macros.lzz"
void SetPrototypeGetter(
v8::Isolate* isolate,
v8::Local<v8::External> data,
Expand All @@ -11,7 +11,7 @@ void SetPrototypeGetter(
v8::AccessorGetterCallback func
) {
v8::HandleScope scope(isolate);

#if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 121
recv->InstanceTemplate()->SetAccessor(
InternalizedFromLatin1(isolate, name),
Expand All @@ -30,7 +30,7 @@ void SetPrototypeGetter(
);
#endif
}
#line 183 "./src/util/macros.lzz"
#line 180 "./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
Expand Down Expand Up @@ -103,43 +103,43 @@ namespace Data
#line 70 "./src/util/data.lzz"
static char const RAW = 3;
}
#line 37 "./src/util/macros.lzz"
#line 34 "./src/util/macros.lzz"
void ThrowError (char const * message)
#line 37 "./src/util/macros.lzz"
#line 34 "./src/util/macros.lzz"
{ v8 :: Isolate * isolate = v8 :: Isolate :: GetCurrent ( ) ; isolate->ThrowException(v8::Exception::Error(StringFromUtf8(isolate, message, -1)));
}
#line 38 "./src/util/macros.lzz"
#line 35 "./src/util/macros.lzz"
void ThrowTypeError (char const * message)
#line 38 "./src/util/macros.lzz"
#line 35 "./src/util/macros.lzz"
{ v8 :: Isolate * isolate = v8 :: Isolate :: GetCurrent ( ) ; isolate->ThrowException(v8::Exception::TypeError(StringFromUtf8(isolate, message, -1)));
}
#line 39 "./src/util/macros.lzz"
#line 36 "./src/util/macros.lzz"
void ThrowRangeError (char const * message)
#line 39 "./src/util/macros.lzz"
#line 36 "./src/util/macros.lzz"
{ v8 :: Isolate * isolate = v8 :: Isolate :: GetCurrent ( ) ; isolate->ThrowException(v8::Exception::RangeError(StringFromUtf8(isolate, message, -1)));
}
#line 105 "./src/util/macros.lzz"
#line 102 "./src/util/macros.lzz"
v8::Local <v8::FunctionTemplate> NewConstructorTemplate (v8::Isolate * isolate, v8::Local <v8::External> data, v8::FunctionCallback func, char const * name)
#line 110 "./src/util/macros.lzz"
#line 107 "./src/util/macros.lzz"
{
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate, func, data);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(InternalizedFromLatin1(isolate, name));
return t;
}
#line 116 "./src/util/macros.lzz"
#line 113 "./src/util/macros.lzz"
void SetPrototypeMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, char const * name, v8::FunctionCallback func)
#line 122 "./src/util/macros.lzz"
#line 119 "./src/util/macros.lzz"
{
v8::HandleScope scope(isolate);
recv->PrototypeTemplate()->Set(
InternalizedFromLatin1(isolate, name),
v8::FunctionTemplate::New(isolate, func, data, v8::Signature::New(isolate, recv))
);
}
#line 129 "./src/util/macros.lzz"
#line 126 "./src/util/macros.lzz"
void SetPrototypeSymbolMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, v8::Local <v8::Symbol> symbol, v8::FunctionCallback func)
#line 135 "./src/util/macros.lzz"
#line 132 "./src/util/macros.lzz"
{
v8::HandleScope scope(isolate);
recv->PrototypeTemplate()->Set(
Expand Down Expand Up @@ -267,9 +267,9 @@ CS::CS (v8::Isolate * isolate)
SetCode(isolate, SQLITE_OK_LOAD_PERMANENTLY, "SQLITE_OK_LOAD_PERMANENTLY");
}
#line 140 "./src/util/constants.lzz"
void CS::SetString (v8::Isolate * isolate, CopyablePersistent <v8::String> & constant, char const * str)
void CS::SetString (v8::Isolate * isolate, v8::Global <v8::String> & constant, char const * str)
#line 140 "./src/util/constants.lzz"
{
{
constant.Reset(isolate, InternalizedFromLatin1(isolate, str));
}
#line 144 "./src/util/constants.lzz"
Expand Down
132 changes: 65 additions & 67 deletions src/better_sqlite3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include <node.h>
#include <node_object_wrap.h>
#include <node_buffer.h>
#line 31 "./src/util/macros.lzz"
template <class T> using CopyablePersistent = v8::Global<T>;
#line 144 "./src/util/macros.lzz"
#line 141 "./src/util/macros.lzz"
void SetPrototypeGetter(
v8::Isolate* isolate,
v8::Local<v8::External> data,
Expand All @@ -37,29 +35,29 @@ v8::Local <v8::String> InternalizedFromUtf8 (v8::Isolate * isolate, char const *
v8::Local <v8::Value> InternalizedFromUtf8OrNull (v8::Isolate * isolate, char const * data, int length);
#line 26 "./src/util/macros.lzz"
v8::Local <v8::String> InternalizedFromLatin1 (v8::Isolate * isolate, char const * str);
#line 33 "./src/util/macros.lzz"
void SetFrozen (v8::Isolate * isolate, v8::Local <v8::Context> ctx, v8::Local <v8::Object> obj, CopyablePersistent <v8::String> & key, v8::Local <v8::Value> value);
#line 37 "./src/util/macros.lzz"
#line 30 "./src/util/macros.lzz"
void SetFrozen (v8::Isolate * isolate, v8::Local <v8::Context> ctx, v8::Local <v8::Object> obj, v8::Global <v8::String> & key, v8::Local <v8::Value> value);
#line 34 "./src/util/macros.lzz"
void ThrowError (char const * message);
#line 38 "./src/util/macros.lzz"
#line 35 "./src/util/macros.lzz"
void ThrowTypeError (char const * message);
#line 39 "./src/util/macros.lzz"
#line 36 "./src/util/macros.lzz"
void ThrowRangeError (char const * message);
#line 91 "./src/util/macros.lzz"
#line 88 "./src/util/macros.lzz"
bool IS_SKIPPED (char c);
#line 96 "./src/util/macros.lzz"
#line 93 "./src/util/macros.lzz"
template <typename T>
#line 96 "./src/util/macros.lzz"
#line 93 "./src/util/macros.lzz"
T * ALLOC_ARRAY (size_t count);
#line 101 "./src/util/macros.lzz"
#line 98 "./src/util/macros.lzz"
template <typename T>
#line 101 "./src/util/macros.lzz"
#line 98 "./src/util/macros.lzz"
void FREE_ARRAY (T * array_pointer);
#line 105 "./src/util/macros.lzz"
#line 102 "./src/util/macros.lzz"
v8::Local <v8::FunctionTemplate> NewConstructorTemplate (v8::Isolate * isolate, v8::Local <v8::External> data, v8::FunctionCallback func, char const * name);
#line 116 "./src/util/macros.lzz"
#line 113 "./src/util/macros.lzz"
void SetPrototypeMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, char const * name, v8::FunctionCallback func);
#line 129 "./src/util/macros.lzz"
#line 126 "./src/util/macros.lzz"
void SetPrototypeSymbolMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, v8::Local <v8::Symbol> symbol, v8::FunctionCallback func);
#line 1 "./src/util/constants.lzz"
class CS
Expand All @@ -71,49 +69,49 @@ class CS
#line 10 "./src/util/constants.lzz"
explicit CS (v8::Isolate * isolate);
#line 119 "./src/util/constants.lzz"
CopyablePersistent <v8::String> database;
v8::Global <v8::String> database;
#line 120 "./src/util/constants.lzz"
CopyablePersistent <v8::String> reader;
v8::Global <v8::String> reader;
#line 121 "./src/util/constants.lzz"
CopyablePersistent <v8::String> source;
v8::Global <v8::String> source;
#line 122 "./src/util/constants.lzz"
CopyablePersistent <v8::String> memory;
v8::Global <v8::String> memory;
#line 123 "./src/util/constants.lzz"
CopyablePersistent <v8::String> readonly;
v8::Global <v8::String> readonly;
#line 124 "./src/util/constants.lzz"
CopyablePersistent <v8::String> name;
v8::Global <v8::String> name;
#line 125 "./src/util/constants.lzz"
CopyablePersistent <v8::String> next;
v8::Global <v8::String> next;
#line 126 "./src/util/constants.lzz"
CopyablePersistent <v8::String> length;
v8::Global <v8::String> length;
#line 127 "./src/util/constants.lzz"
CopyablePersistent <v8::String> done;
v8::Global <v8::String> done;
#line 128 "./src/util/constants.lzz"
CopyablePersistent <v8::String> value;
v8::Global <v8::String> value;
#line 129 "./src/util/constants.lzz"
CopyablePersistent <v8::String> changes;
v8::Global <v8::String> changes;
#line 130 "./src/util/constants.lzz"
CopyablePersistent <v8::String> lastInsertRowid;
v8::Global <v8::String> lastInsertRowid;
#line 131 "./src/util/constants.lzz"
CopyablePersistent <v8::String> statement;
v8::Global <v8::String> statement;
#line 132 "./src/util/constants.lzz"
CopyablePersistent <v8::String> column;
v8::Global <v8::String> column;
#line 133 "./src/util/constants.lzz"
CopyablePersistent <v8::String> table;
v8::Global <v8::String> table;
#line 134 "./src/util/constants.lzz"
CopyablePersistent <v8::String> type;
v8::Global <v8::String> type;
#line 135 "./src/util/constants.lzz"
CopyablePersistent <v8::String> totalPages;
v8::Global <v8::String> totalPages;
#line 136 "./src/util/constants.lzz"
CopyablePersistent <v8::String> remainingPages;
v8::Global <v8::String> remainingPages;
#line 138 "./src/util/constants.lzz"
private:
#line 140 "./src/util/constants.lzz"
static void SetString (v8::Isolate * isolate, CopyablePersistent <v8::String> & constant, char const * str);
static void SetString (v8::Isolate * isolate, v8::Global <v8::String> & constant, char const * str);
#line 144 "./src/util/constants.lzz"
void SetCode (v8::Isolate * isolate, int code, char const * str);
#line 150 "./src/util/constants.lzz"
std::unordered_map <int, CopyablePersistent<v8::String> > codes;
std::unordered_map <int, v8::Global<v8::String> > codes;
};
#line 1 "./src/util/bind-map.lzz"
class BindMap
Expand All @@ -138,7 +136,7 @@ class BindMap
#line 22 "./src/util/bind-map.lzz"
explicit Pair (v8::Isolate * isolate, Pair * pair);
#line 25 "./src/util/bind-map.lzz"
CopyablePersistent <v8::String> const name;
v8::Global <v8::String> const name;
#line 26 "./src/util/bind-map.lzz"
int const index;
};
Expand Down Expand Up @@ -305,7 +303,7 @@ class Database : public node::ObjectWrap
#line 464 "./src/objects/database.lzz"
Addon * const addon;
#line 465 "./src/objects/database.lzz"
CopyablePersistent <v8::Value> const logger;
v8::Global <v8::Value> const logger;
#line 466 "./src/objects/database.lzz"
std::set <Statement*, CompareStatement> stmts;
#line 467 "./src/objects/database.lzz"
Expand Down Expand Up @@ -519,7 +517,7 @@ class CustomFunction : protected DataConverter
#line 56 "./src/util/custom-function.lzz"
v8::Isolate * const isolate;
#line 57 "./src/util/custom-function.lzz"
CopyablePersistent <v8::Function> const fn;
v8::Global <v8::Function> const fn;
#line 58 "./src/util/custom-function.lzz"
bool const safe_ints;
};
Expand All @@ -541,7 +539,7 @@ class CustomAggregate : public CustomFunction
#line 37 "./src/util/custom-aggregate.lzz"
private:
#line 39 "./src/util/custom-aggregate.lzz"
static void xStepBase (sqlite3_context * invocation, int argc, sqlite3_value * * argv, CopyablePersistent <v8::Function> const CustomAggregate::* ptrtm);
static void xStepBase (sqlite3_context * invocation, int argc, sqlite3_value * * argv, v8::Global <v8::Function> const CustomAggregate::* ptrtm);
#line 58 "./src/util/custom-aggregate.lzz"
static void xValueBase (sqlite3_context * invocation, bool is_final);
#line 82 "./src/util/custom-aggregate.lzz"
Expand All @@ -550,7 +548,7 @@ class CustomAggregate : public CustomFunction
#line 82 "./src/util/custom-aggregate.lzz"
public:
#line 83 "./src/util/custom-aggregate.lzz"
CopyablePersistent <v8::Value> value;
v8::Global <v8::Value> value;
#line 84 "./src/util/custom-aggregate.lzz"
bool initialized;
#line 85 "./src/util/custom-aggregate.lzz"
Expand All @@ -567,11 +565,11 @@ class CustomAggregate : public CustomFunction
#line 117 "./src/util/custom-aggregate.lzz"
bool const invoke_start;
#line 118 "./src/util/custom-aggregate.lzz"
CopyablePersistent <v8::Function> const inverse;
v8::Global <v8::Function> const inverse;
#line 119 "./src/util/custom-aggregate.lzz"
CopyablePersistent <v8::Function> const result;
v8::Global <v8::Function> const result;
#line 120 "./src/util/custom-aggregate.lzz"
CopyablePersistent <v8::Value> const start;
v8::Global <v8::Value> const start;
};
#line 1 "./src/util/custom-table.lzz"
class CustomTable
Expand Down Expand Up @@ -608,7 +606,7 @@ class CustomTable
#line 103 "./src/util/custom-table.lzz"
bool const safe_ints;
#line 104 "./src/util/custom-table.lzz"
CopyablePersistent <v8::Function> const generator;
v8::Global <v8::Function> const generator;
#line 105 "./src/util/custom-table.lzz"
std::vector <std::string> const parameter_names;
};
Expand All @@ -626,11 +624,11 @@ class CustomTable
#line 122 "./src/util/custom-table.lzz"
sqlite3_vtab_cursor base;
#line 123 "./src/util/custom-table.lzz"
CopyablePersistent <v8::Object> iterator;
v8::Global <v8::Object> iterator;
#line 124 "./src/util/custom-table.lzz"
CopyablePersistent <v8::Function> next;
v8::Global <v8::Function> next;
#line 125 "./src/util/custom-table.lzz"
CopyablePersistent <v8::Array> row;
v8::Global <v8::Array> row;
#line 126 "./src/util/custom-table.lzz"
bool done;
#line 127 "./src/util/custom-table.lzz"
Expand Down Expand Up @@ -685,7 +683,7 @@ class CustomTable
#line 402 "./src/util/custom-table.lzz"
std::string const name;
#line 403 "./src/util/custom-table.lzz"
CopyablePersistent <v8::Function> const factory;
v8::Global <v8::Function> const factory;
};
#line 65 "./src/util/data.lzz"
namespace Data
Expand Down Expand Up @@ -793,13 +791,13 @@ struct Addon
#line 52 "./src/better_sqlite3.lzz"
sqlite3_uint64 NextId ();
#line 56 "./src/better_sqlite3.lzz"
CopyablePersistent <v8::Function> Statement;
v8::Global <v8::Function> Statement;
#line 57 "./src/better_sqlite3.lzz"
CopyablePersistent <v8::Function> StatementIterator;
v8::Global <v8::Function> StatementIterator;
#line 58 "./src/better_sqlite3.lzz"
CopyablePersistent <v8::Function> Backup;
v8::Global <v8::Function> Backup;
#line 59 "./src/better_sqlite3.lzz"
CopyablePersistent <v8::Function> SqliteError;
v8::Global <v8::Function> SqliteError;
#line 60 "./src/better_sqlite3.lzz"
v8::FunctionCallbackInfo <v8 :: Value> const * privileged_info;
#line 61 "./src/better_sqlite3.lzz"
Expand Down Expand Up @@ -834,31 +832,31 @@ LZZ_INLINE v8::Local <v8::String> InternalizedFromLatin1 (v8::Isolate * isolate,
{
return v8::String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(str), v8::NewStringType::kInternalized).ToLocalChecked();
}
#line 33 "./src/util/macros.lzz"
LZZ_INLINE void SetFrozen (v8::Isolate * isolate, v8::Local <v8::Context> ctx, v8::Local <v8::Object> obj, CopyablePersistent <v8::String> & key, v8::Local <v8::Value> value)
#line 33 "./src/util/macros.lzz"
{
#line 30 "./src/util/macros.lzz"
LZZ_INLINE void SetFrozen (v8::Isolate * isolate, v8::Local <v8::Context> ctx, v8::Local <v8::Object> obj, v8::Global <v8::String> & key, v8::Local <v8::Value> value)
#line 30 "./src/util/macros.lzz"
{
obj->DefineOwnProperty(ctx, key.Get(isolate), value, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly)).FromJust();
}
#line 91 "./src/util/macros.lzz"
#line 88 "./src/util/macros.lzz"
LZZ_INLINE bool IS_SKIPPED (char c)
#line 91 "./src/util/macros.lzz"
#line 88 "./src/util/macros.lzz"
{
return c == ' ' || c == ';' || (c >= '\t' && c <= '\r');
}
#line 96 "./src/util/macros.lzz"
#line 93 "./src/util/macros.lzz"
template <typename T>
#line 96 "./src/util/macros.lzz"
#line 93 "./src/util/macros.lzz"
LZZ_INLINE T * ALLOC_ARRAY (size_t count)
#line 96 "./src/util/macros.lzz"
#line 93 "./src/util/macros.lzz"
{
return static_cast<T*>(::operator new[](count * sizeof(T)));
}
#line 101 "./src/util/macros.lzz"
#line 98 "./src/util/macros.lzz"
template <typename T>
#line 101 "./src/util/macros.lzz"
#line 98 "./src/util/macros.lzz"
LZZ_INLINE void FREE_ARRAY (T * array_pointer)
#line 101 "./src/util/macros.lzz"
#line 98 "./src/util/macros.lzz"
{
::operator delete[](array_pointer);
}
Expand Down Expand Up @@ -952,9 +950,9 @@ LZZ_INLINE bool Backup::Compare (Backup const * const a, Backup const * const b)
return a->id < b->id;
}
#line 39 "./src/util/custom-aggregate.lzz"
LZZ_INLINE void CustomAggregate::xStepBase (sqlite3_context * invocation, int argc, sqlite3_value * * argv, CopyablePersistent <v8::Function> const CustomAggregate::* ptrtm)
LZZ_INLINE void CustomAggregate::xStepBase (sqlite3_context * invocation, int argc, sqlite3_value * * argv, v8::Global <v8::Function> const CustomAggregate::* ptrtm)
#line 39 "./src/util/custom-aggregate.lzz"
{
{
CustomAggregate * self = static_cast < CustomAggregate * > ( sqlite3_user_data ( invocation ) ) ; v8 :: Isolate * isolate = self -> isolate ; v8 :: HandleScope scope ( isolate ) ; Accumulator * acc = self -> GetAccumulator ( invocation ) ; if ( acc -> value . IsEmpty ( ) ) return ;

v8::Local<v8::Value> args_fast[5];
Expand Down
Loading

0 comments on commit 7ee4464

Please sign in to comment.