Skip to content

Commit 305cfa5

Browse files
committed
Fix optional args macro
1 parent eeea36b commit 305cfa5

File tree

3 files changed

+33
-35
lines changed

3 files changed

+33
-35
lines changed

src/better_sqlite3.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33

44
#include "better_sqlite3.hpp"
5-
#line 167 "./src/util/macros.lzz"
5+
#line 165 "./src/util/macros.lzz"
66
void SetPrototypeGetter(
77
v8::Isolate* isolate,
88
v8::Local<v8::External> data,
@@ -30,7 +30,7 @@ void SetPrototypeGetter(
3030
);
3131
#endif
3232
}
33-
#line 197 "./src/util/macros.lzz"
33+
#line 195 "./src/util/macros.lzz"
3434
#ifndef V8_COMPRESS_POINTERS_IN_SHARED_CAGE
3535
#define SAFE_NEW_BUFFER(env, data, length, finalizeCallback, finalizeHint) node::Buffer::New(env, data, length, finalizeCallback, finalizeHint)
3636
#else
@@ -118,28 +118,28 @@ void ThrowRangeError (char const * message)
118118
#line 40 "./src/util/macros.lzz"
119119
{ v8 :: Isolate * isolate = v8 :: Isolate :: GetCurrent ( ) ; isolate->ThrowException(v8::Exception::RangeError(StringFromUtf8(isolate, message, -1)));
120120
}
121-
#line 119 "./src/util/macros.lzz"
121+
#line 117 "./src/util/macros.lzz"
122122
v8::Local <v8::FunctionTemplate> NewConstructorTemplate (v8::Isolate * isolate, v8::Local <v8::External> data, v8::FunctionCallback func, char const * name)
123-
#line 124 "./src/util/macros.lzz"
123+
#line 122 "./src/util/macros.lzz"
124124
{
125125
v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(isolate, func, data);
126126
t->InstanceTemplate()->SetInternalFieldCount(1);
127127
t->SetClassName(InternalizedFromLatin1(isolate, name));
128128
return t;
129129
}
130-
#line 130 "./src/util/macros.lzz"
130+
#line 128 "./src/util/macros.lzz"
131131
void SetPrototypeMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, char const * name, v8::FunctionCallback func)
132-
#line 136 "./src/util/macros.lzz"
132+
#line 134 "./src/util/macros.lzz"
133133
{
134134
v8::HandleScope scope(isolate);
135135
recv->PrototypeTemplate()->Set(
136136
InternalizedFromLatin1(isolate, name),
137137
v8::FunctionTemplate::New(isolate, func, data, v8::Signature::New(isolate, recv))
138138
);
139139
}
140-
#line 143 "./src/util/macros.lzz"
140+
#line 141 "./src/util/macros.lzz"
141141
void SetPrototypeSymbolMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, v8::Local <v8::Symbol> symbol, v8::FunctionCallback func)
142-
#line 149 "./src/util/macros.lzz"
142+
#line 147 "./src/util/macros.lzz"
143143
{
144144
v8::HandleScope scope(isolate);
145145
recv->PrototypeTemplate()->Set(
@@ -827,7 +827,7 @@ void Database::JS_loadExtension (v8::FunctionCallbackInfo <v8 :: Value> const &
827827
{
828828
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
829829
if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsString ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a string" ) ; v8 :: Local < v8 :: String > filename = ( info [ 0 ] . As < v8 :: String > ( ) ) ;
830-
v8 :: MaybeLocal < v8 :: String > entryPoint = ( { bool isSupplied = info . Length ( ) > ( 1 ) && ! info [ 1 ] -> IsUndefined ( ) ; if ( isSupplied && ! info [ 1 ] -> IsString ( ) ) return ThrowTypeError ( "Expected " "second" " argument to be " "a string" " or undefined" ) ; ( isSupplied ? info [ 1 ] . As < v8 :: String > ( ) : v8 :: MaybeLocal < v8 :: String > ( ) ) ; } ) ;
830+
bool isSupplied = info . Length ( ) > ( 1 ) && ! info [ 1 ] -> IsUndefined ( ) ; if ( isSupplied && ! info [ 1 ] -> IsString ( ) ) return ThrowTypeError ( "Expected " "second" " argument to be " "a string" " or undefined" ) ; v8 :: MaybeLocal < v8 :: String > entryPoint = ( isSupplied ? info [ 1 ] . As < v8 :: String > ( ) : v8 :: MaybeLocal < v8 :: String > ( ) ) ; ;
831831
if ( ! db -> open ) return ThrowTypeError ( "The database connection is not open" ) ;
832832
if ( db -> busy ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;
833833
if ( db -> iterators ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;
@@ -849,7 +849,7 @@ void Database::JS_updateHook (v8::FunctionCallbackInfo <v8 :: Value> const & inf
849849
#line 523 "./src/objects/database.lzz"
850850
{
851851
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
852-
v8 :: MaybeLocal < v8 :: Function > fn = ( { bool isSupplied = info . Length ( ) > ( 0 ) && ! info [ 0 ] -> IsUndefined ( ) ; if ( isSupplied && ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" " or undefined" ) ; ( isSupplied ? info [ 0 ] . As < v8 :: Function > ( ) : v8 :: MaybeLocal < v8 :: Function > ( ) ) ; } ) ;
852+
bool isSupplied = info . Length ( ) > ( 0 ) && ! info [ 0 ] -> IsUndefined ( ) ; if ( isSupplied && ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" " or undefined" ) ; v8 :: MaybeLocal < v8 :: Function > fn = ( isSupplied ? info [ 0 ] . As < v8 :: Function > ( ) : v8 :: MaybeLocal < v8 :: Function > ( ) ) ; ;
853853
if ( ! db -> open ) return ThrowTypeError ( "The database connection is not open" ) ;
854854
if ( db -> busy ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;
855855
if ( db -> iterators ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;
@@ -873,7 +873,7 @@ void Database::JS_commitHook (v8::FunctionCallbackInfo <v8 :: Value> const & inf
873873
#line 545 "./src/objects/database.lzz"
874874
{
875875
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
876-
v8 :: MaybeLocal < v8 :: Function > fn = ( { bool isSupplied = info . Length ( ) > ( 0 ) && ! info [ 0 ] -> IsUndefined ( ) ; if ( isSupplied && ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" " or undefined" ) ; ( isSupplied ? info [ 0 ] . As < v8 :: Function > ( ) : v8 :: MaybeLocal < v8 :: Function > ( ) ) ; } ) ;
876+
bool isSupplied = info . Length ( ) > ( 0 ) && ! info [ 0 ] -> IsUndefined ( ) ; if ( isSupplied && ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" " or undefined" ) ; v8 :: MaybeLocal < v8 :: Function > fn = ( isSupplied ? info [ 0 ] . As < v8 :: Function > ( ) : v8 :: MaybeLocal < v8 :: Function > ( ) ) ; ;
877877
if ( ! db -> open ) return ThrowTypeError ( "The database connection is not open" ) ;
878878
if ( db -> busy ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;
879879
if ( db -> iterators ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;
@@ -896,7 +896,7 @@ void Database::JS_rollbackHook (v8::FunctionCallbackInfo <v8 :: Value> const & i
896896
#line 566 "./src/objects/database.lzz"
897897
{
898898
Database* db = node :: ObjectWrap :: Unwrap <Database>(info.This());
899-
v8 :: MaybeLocal < v8 :: Function > fn = ( { bool isSupplied = info . Length ( ) > ( 0 ) && ! info [ 0 ] -> IsUndefined ( ) ; if ( isSupplied && ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" " or undefined" ) ; ( isSupplied ? info [ 0 ] . As < v8 :: Function > ( ) : v8 :: MaybeLocal < v8 :: Function > ( ) ) ; } ) ;
899+
bool isSupplied = info . Length ( ) > ( 0 ) && ! info [ 0 ] -> IsUndefined ( ) ; if ( isSupplied && ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" " or undefined" ) ; v8 :: MaybeLocal < v8 :: Function > fn = ( isSupplied ? info [ 0 ] . As < v8 :: Function > ( ) : v8 :: MaybeLocal < v8 :: Function > ( ) ) ; ;
900900
if ( ! db -> open ) return ThrowTypeError ( "The database connection is not open" ) ;
901901
if ( db -> busy ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;
902902
if ( db -> iterators ) return ThrowTypeError ( "This database connection is busy executing a query" ) ;

src/better_sqlite3.hpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <node.h>
1717
#include <node_object_wrap.h>
1818
#include <node_buffer.h>
19-
#line 158 "./src/util/macros.lzz"
19+
#line 156 "./src/util/macros.lzz"
2020
void SetPrototypeGetter(
2121
v8::Isolate* isolate,
2222
v8::Local<v8::External> data,
@@ -43,21 +43,21 @@ void ThrowError (char const * message);
4343
void ThrowTypeError (char const * message);
4444
#line 40 "./src/util/macros.lzz"
4545
void ThrowRangeError (char const * message);
46-
#line 105 "./src/util/macros.lzz"
46+
#line 103 "./src/util/macros.lzz"
4747
bool IS_SKIPPED (char c);
48-
#line 110 "./src/util/macros.lzz"
48+
#line 108 "./src/util/macros.lzz"
4949
template <typename T>
50-
#line 110 "./src/util/macros.lzz"
50+
#line 108 "./src/util/macros.lzz"
5151
T * ALLOC_ARRAY (size_t count);
52-
#line 115 "./src/util/macros.lzz"
52+
#line 113 "./src/util/macros.lzz"
5353
template <typename T>
54-
#line 115 "./src/util/macros.lzz"
54+
#line 113 "./src/util/macros.lzz"
5555
void FREE_ARRAY (T * array_pointer);
56-
#line 119 "./src/util/macros.lzz"
56+
#line 117 "./src/util/macros.lzz"
5757
v8::Local <v8::FunctionTemplate> NewConstructorTemplate (v8::Isolate * isolate, v8::Local <v8::External> data, v8::FunctionCallback func, char const * name);
58-
#line 130 "./src/util/macros.lzz"
58+
#line 128 "./src/util/macros.lzz"
5959
void SetPrototypeMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, char const * name, v8::FunctionCallback func);
60-
#line 143 "./src/util/macros.lzz"
60+
#line 141 "./src/util/macros.lzz"
6161
void SetPrototypeSymbolMethod (v8::Isolate * isolate, v8::Local <v8::External> data, v8::Local <v8::FunctionTemplate> recv, v8::Local <v8::Symbol> symbol, v8::FunctionCallback func);
6262
#line 1 "./src/util/constants.lzz"
6363
class CS
@@ -906,25 +906,25 @@ LZZ_INLINE void SetFrozen (v8::Isolate * isolate, v8::Local <v8::Context> ctx, v
906906
{
907907
obj->DefineOwnProperty(ctx, key.Get(isolate), value, static_cast<v8::PropertyAttribute>(v8::DontDelete | v8::ReadOnly)).FromJust();
908908
}
909-
#line 105 "./src/util/macros.lzz"
909+
#line 103 "./src/util/macros.lzz"
910910
LZZ_INLINE bool IS_SKIPPED (char c)
911-
#line 105 "./src/util/macros.lzz"
911+
#line 103 "./src/util/macros.lzz"
912912
{
913913
return c == ' ' || c == ';' || (c >= '\t' && c <= '\r');
914914
}
915-
#line 110 "./src/util/macros.lzz"
915+
#line 108 "./src/util/macros.lzz"
916916
template <typename T>
917-
#line 110 "./src/util/macros.lzz"
917+
#line 108 "./src/util/macros.lzz"
918918
LZZ_INLINE T * ALLOC_ARRAY (size_t count)
919-
#line 110 "./src/util/macros.lzz"
919+
#line 108 "./src/util/macros.lzz"
920920
{
921921
return static_cast<T*>(::operator new[](count * sizeof(T)));
922922
}
923-
#line 115 "./src/util/macros.lzz"
923+
#line 113 "./src/util/macros.lzz"
924924
template <typename T>
925-
#line 115 "./src/util/macros.lzz"
925+
#line 113 "./src/util/macros.lzz"
926926
LZZ_INLINE void FREE_ARRAY (T * array_pointer)
927-
#line 115 "./src/util/macros.lzz"
927+
#line 113 "./src/util/macros.lzz"
928928
{
929929
::operator delete[](array_pointer);
930930
}

src/util/macros.lzz

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ void ThrowRangeError(const char* message) { EasyIsolate; isolate->ThrowException
5050
var = (info[at()].As<v8::Type>())__VA_ARGS__
5151

5252
#define _REQUIRE_OPTIONAL_ARGUMENT(at, var, Type, message, ...) \
53-
var = ({ \
54-
bool isSupplied = info.Length() > (at()) && !info[at()]->IsUndefined(); \
55-
if (isSupplied && !info[at()]->Is##Type()) \
56-
return ThrowTypeError("Expected "#at" argument to be "#message" or undefined"); \
57-
(isSupplied ? info[at()].As<v8::Type>()__VA_ARGS__ : v8::MaybeLocal<v8::Type>()); \
58-
})
53+
bool isSupplied = info.Length() > (at()) && !info[at()]->IsUndefined(); \
54+
if (isSupplied && !info[at()]->Is##Type()) \
55+
return ThrowTypeError("Expected "#at" argument to be "#message" or undefined"); \
56+
var = (isSupplied ? info[at()].As<v8::Type>()__VA_ARGS__ : v8::MaybeLocal<v8::Type>()); \
5957

6058
#define REQUIRE_ARGUMENT_INT32(at, var) \
6159
_REQUIRE_ARGUMENT(at, var, Int32, a 32-bit signed integer, ->Value())

0 commit comments

Comments
 (0)