@@ -1103,6 +1103,14 @@ void DatabaseSync::Close(const FunctionCallbackInfo<Value>& args) {
11031103 db->connection_ = nullptr ;
11041104}
11051105
1106+ void DatabaseSync::Dispose (const v8::FunctionCallbackInfo<v8::Value>& args) {
1107+ v8::TryCatch try_catch (args.GetIsolate ());
1108+ Close (args);
1109+ if (try_catch.HasCaught ()) {
1110+ CHECK (try_catch.CanContinue ());
1111+ }
1112+ }
1113+
11061114void DatabaseSync::Prepare (const FunctionCallbackInfo<Value>& args) {
11071115 DatabaseSync* db;
11081116 ASSIGN_OR_RETURN_UNWRAP (&db, args.This ());
@@ -3015,6 +3023,7 @@ Local<FunctionTemplate> Session::GetConstructorTemplate(Environment* env) {
30153023 SetProtoMethod (
30163024 isolate, tmpl, " patchset" , Session::Changeset<sqlite3session_patchset>);
30173025 SetProtoMethod (isolate, tmpl, " close" , Session::Close);
3026+ SetProtoDispose (isolate, tmpl, Session::Dispose);
30183027 env->set_sqlite_session_constructor_template (tmpl);
30193028 }
30203029 return tmpl;
@@ -3059,6 +3068,14 @@ void Session::Close(const FunctionCallbackInfo<Value>& args) {
30593068 session->Delete ();
30603069}
30613070
3071+ void Session::Dispose (const v8::FunctionCallbackInfo<v8::Value>& args) {
3072+ v8::TryCatch try_catch (args.GetIsolate ());
3073+ Close (args);
3074+ if (try_catch.HasCaught ()) {
3075+ CHECK (try_catch.CanContinue ());
3076+ }
3077+ }
3078+
30623079void Session::Delete () {
30633080 if (!database_ || !database_->connection_ || session_ == nullptr ) return ;
30643081 sqlite3session_delete (session_);
@@ -3094,6 +3111,7 @@ static void Initialize(Local<Object> target,
30943111
30953112 SetProtoMethod (isolate, db_tmpl, " open" , DatabaseSync::Open);
30963113 SetProtoMethod (isolate, db_tmpl, " close" , DatabaseSync::Close);
3114+ SetProtoDispose (isolate, db_tmpl, DatabaseSync::Dispose);
30973115 SetProtoMethod (isolate, db_tmpl, " prepare" , DatabaseSync::Prepare);
30983116 SetProtoMethod (isolate, db_tmpl, " exec" , DatabaseSync::Exec);
30993117 SetProtoMethod (isolate, db_tmpl, " function" , DatabaseSync::CustomFunction);
@@ -3133,6 +3151,8 @@ static void Initialize(Local<Object> target,
31333151 target,
31343152 " StatementSync" ,
31353153 StatementSync::GetConstructorTemplate (env));
3154+ SetConstructorFunction (
3155+ context, target, " Session" , Session::GetConstructorTemplate (env));
31363156
31373157 target->Set (context, env->constants_string (), constants).Check ();
31383158
0 commit comments