5
5
#include " env-inl.h"
6
6
#include " memory_tracker-inl.h"
7
7
#include " node.h"
8
+ #include " node_debug.h"
8
9
#include " node_errors.h"
9
10
#include " node_mem-inl.h"
10
11
#include " node_url.h"
11
12
#include " sqlite3.h"
12
13
#include " threadpoolwork-inl.h"
13
14
#include " util-inl.h"
15
+ #include " v8-fast-api-calls.h"
14
16
15
17
#include < cinttypes>
16
18
@@ -21,10 +23,12 @@ using v8::Array;
21
23
using v8::ArrayBuffer;
22
24
using v8::BigInt;
23
25
using v8::Boolean;
26
+ using v8::CFunction;
24
27
using v8::ConstructorBehavior;
25
28
using v8::Context;
26
29
using v8::DontDelete;
27
30
using v8::Exception;
31
+ using v8::FastApiCallbackOptions;
28
32
using v8::Function;
29
33
using v8::FunctionCallback;
30
34
using v8::FunctionCallbackInfo;
@@ -58,11 +62,11 @@ using v8::Value;
58
62
} \
59
63
} while (0 )
60
64
61
- #define THROW_AND_RETURN_ON_BAD_STATE (env, condition, msg ) \
65
+ #define THROW_AND_RETURN_ON_BAD_STATE (env, condition, msg, ...) \
62
66
do { \
63
67
if ((condition)) { \
64
68
THROW_ERR_INVALID_STATE ((env), (msg)); \
65
- return ; \
69
+ return __VA_ARGS__; \
66
70
} \
67
71
} while (0 )
68
72
@@ -979,7 +983,7 @@ void DatabaseSync::IsOpenGetter(const FunctionCallbackInfo<Value>& args) {
979
983
args.GetReturnValue ().Set (db->IsOpen ());
980
984
}
981
985
982
- void DatabaseSync::IsTransactionGetter (
986
+ void DatabaseSync::IsTransactionGetterSlow (
983
987
const FunctionCallbackInfo<Value>& args) {
984
988
DatabaseSync* db;
985
989
ASSIGN_OR_RETURN_UNWRAP (&db, args.This ());
@@ -988,6 +992,23 @@ void DatabaseSync::IsTransactionGetter(
988
992
args.GetReturnValue ().Set (sqlite3_get_autocommit (db->connection_ ) == 0 );
989
993
}
990
994
995
+ bool DatabaseSync::IsTransactionGetterFast (
996
+ Local<Value> receiver,
997
+ Local<Object> holder,
998
+ // NOLINTNEXTLINE(runtime/references) This is V8 api.
999
+ FastApiCallbackOptions& options) {
1000
+ TRACK_V8_FAST_API_CALL (" DatabaseSync.isTransaction" );
1001
+ DatabaseSync* db;
1002
+ ASSIGN_OR_RETURN_UNWRAP (&db, holder, false );
1003
+ Environment* env = Environment::GetCurrent (options.isolate );
1004
+ THROW_AND_RETURN_ON_BAD_STATE (
1005
+ env, !db->IsOpen (), " database is not open" , false );
1006
+ return sqlite3_get_autocommit (db->connection_ ) == 0 ;
1007
+ }
1008
+
1009
+ CFunction DatabaseSync::is_transaction_getter_methods[] = {
1010
+ CFunction::Make (IsTransactionGetterFast)};
1011
+
991
1012
void DatabaseSync::Close (const FunctionCallbackInfo<Value>& args) {
992
1013
DatabaseSync* db;
993
1014
ASSIGN_OR_RETURN_UNWRAP (&db, args.This ());
@@ -2343,6 +2364,23 @@ static inline void SetSideEffectFreeGetter(
2343
2364
name, getter, Local<FunctionTemplate>(), DontDelete);
2344
2365
}
2345
2366
2367
+ static inline void SetSideEffectFreeFastGetter (
2368
+ Isolate* isolate,
2369
+ Local<FunctionTemplate> class_template,
2370
+ Local<String> name,
2371
+ v8::FunctionCallback slow_callback,
2372
+ const v8::CFunction* c_function) {
2373
+ Local<v8::FunctionTemplate> getter =
2374
+ NewFunctionTemplate (isolate,
2375
+ slow_callback,
2376
+ v8::Signature::New (isolate, class_template),
2377
+ v8::ConstructorBehavior::kThrow ,
2378
+ v8::SideEffectType::kHasSideEffect ,
2379
+ c_function);
2380
+ class_template->InstanceTemplate ()->SetAccessorProperty (
2381
+ name, getter, Local<FunctionTemplate>(), DontDelete);
2382
+ }
2383
+
2346
2384
Local<FunctionTemplate> StatementSync::GetConstructorTemplate (
2347
2385
Environment* env) {
2348
2386
Local<FunctionTemplate> tmpl =
@@ -2672,10 +2710,11 @@ static void Initialize(Local<Object> target,
2672
2710
db_tmpl,
2673
2711
FIXED_ONE_BYTE_STRING (isolate, " isOpen" ),
2674
2712
DatabaseSync::IsOpenGetter);
2675
- SetSideEffectFreeGetter (isolate,
2676
- db_tmpl,
2677
- FIXED_ONE_BYTE_STRING (isolate, " isTransaction" ),
2678
- DatabaseSync::IsTransactionGetter);
2713
+ SetSideEffectFreeFastGetter (isolate,
2714
+ db_tmpl,
2715
+ FIXED_ONE_BYTE_STRING (isolate, " isTransaction" ),
2716
+ DatabaseSync::IsTransactionGetterSlow,
2717
+ DatabaseSync::is_transaction_getter_methods);
2679
2718
SetConstructorFunction (context, target, " DatabaseSync" , db_tmpl);
2680
2719
SetConstructorFunction (context,
2681
2720
target,
0 commit comments