| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ee7bf09 commit ca88587
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,59 +170,49 @@ static constexpr const LimitInfo* GetLimitInfoFromName(std::string_view name) { | |||
| 170 | 170 | return nullptr; | |
| 171 | 171 | } | |
| 172 | 172 | ||
| 173 | - inline MaybeLocal<Object> CreateSQLiteError(Isolate* isolate, | ||
| 174 | - const char* message) { | ||
| 173 | + namespace { | ||
| 174 | + MaybeLocal<Object> CreateSQLiteErrorImpl(Isolate* isolate, | ||
| 175 | + const char* message, | ||
| 176 | + const char* errstr, | ||
| 177 | + int errcode) { | ||
| 178 | + Environment* env = Environment::GetCurrent(isolate); | ||
| 179 | + Local<Context> context = isolate->GetCurrentContext(); | ||
| 175 | 180 | Local<String> js_msg; | |
| 176 | 181 | Local<Object> e; | |
| 177 | - Environment* env = Environment::GetCurrent(isolate); | ||
| 178 | 182 | if (!String::NewFromUtf8(isolate, message).ToLocal(&js_msg) || | |
| 179 | - !Exception::Error(js_msg) | ||
| 180 | - ->ToObject(isolate->GetCurrentContext()) | ||
| 181 | - .ToLocal(&e) || | ||
| 182 | - e->Set(isolate->GetCurrentContext(), | ||
| 183 | - env->code_string(), | ||
| 184 | - env->err_sqlite_error_string()) | ||
| 183 | + !Exception::Error(js_msg)->ToObject(context).ToLocal(&e) || | ||
| 184 | + e->Set(context, env->code_string(), env->err_sqlite_error_string()) | ||
| 185 | 185 | .IsNothing()) { | |
| 186 | 186 | return MaybeLocal<Object>(); | |
| 187 | 187 | } | |
| 188 | + | ||
| 189 | + if (errstr != nullptr) { | ||
| 190 | + Local<String> js_errstr; | ||
| 191 | + if (!String::NewFromUtf8(isolate, errstr).ToLocal(&js_errstr) || | ||
| 192 | + e->Set(context, env->errcode_string(), Integer::New(isolate, errcode)) | ||
| 193 | + .IsNothing() || | ||
| 194 | + e->Set(context, env->errstr_string(), js_errstr).IsNothing()) { | ||
| 195 | + return MaybeLocal<Object>(); | ||
| 196 | + } | ||
| 197 | + } | ||
| 188 | 198 | return e; | |
| 189 | 199 | } | |
| 200 | + } // namespace | ||
| 201 | + | ||
| 202 | + inline MaybeLocal<Object> CreateSQLiteError(Isolate* isolate, | ||
| 203 | + const char* message) { | ||
| 204 | + return CreateSQLiteErrorImpl(isolate, message, nullptr, 0); | ||
| 205 | + } | ||
| 190 | 206 | ||
| 191 | 207 | inline MaybeLocal<Object> CreateSQLiteError(Isolate* isolate, int errcode) { | |
| 192 | 208 | const char* errstr = sqlite3_errstr(errcode); | |
| 193 | - Local<String> js_errmsg; | ||
| 194 | - Local<Object> e; | ||
| 195 | - Environment* env = Environment::GetCurrent(isolate); | ||
| 196 | - if (!String::NewFromUtf8(isolate, errstr).ToLocal(&js_errmsg) || | ||
| 197 | - !CreateSQLiteError(isolate, errstr).ToLocal(&e) || | ||
| 198 | - e->Set(env->context(), | ||
| 199 | - env->errcode_string(), | ||
| 200 | - Integer::New(isolate, errcode)) | ||
| 201 | - .IsNothing() || | ||
| 202 | - e->Set(env->context(), env->errstr_string(), js_errmsg).IsNothing()) { | ||
| 203 | - return MaybeLocal<Object>(); | ||
| 204 | - } | ||
| 205 | - return e; | ||
| 209 | + return CreateSQLiteErrorImpl(isolate, errstr, errstr, errcode); | ||
| 206 | 210 | } | |
| 207 | 211 | ||
| 208 | 212 | inline MaybeLocal<Object> CreateSQLiteError(Isolate* isolate, sqlite3* db) { | |
| 209 | 213 | int errcode = sqlite3_extended_errcode(db); | |
| 210 | - const char* errstr = sqlite3_errstr(errcode); | ||
| 211 | - const char* errmsg = sqlite3_errmsg(db); | ||
| 212 | - Local<String> js_errmsg; | ||
| 213 | - Local<Object> e; | ||
| 214 | - Environment* env = Environment::GetCurrent(isolate); | ||
| 215 | - if (!String::NewFromUtf8(isolate, errstr).ToLocal(&js_errmsg) || | ||
| 216 | - !CreateSQLiteError(isolate, errmsg).ToLocal(&e) || | ||
| 217 | - e->Set(isolate->GetCurrentContext(), | ||
| 218 | - env->errcode_string(), | ||
| 219 | - Integer::New(isolate, errcode)) | ||
| 220 | - .IsNothing() || | ||
| 221 | - e->Set(isolate->GetCurrentContext(), env->errstr_string(), js_errmsg) | ||
| 222 | - .IsNothing()) { | ||
| 223 | - return MaybeLocal<Object>(); | ||
| 224 | - } | ||
| 225 | - return e; | ||
| 214 | + return CreateSQLiteErrorImpl( | ||
| 215 | + isolate, sqlite3_errmsg(db), sqlite3_errstr(errcode), errcode); | ||
| 226 | 216 | } | |
| 227 | 217 | ||
| 228 | 218 | void JSValueToSQLiteResult(Isolate* isolate, | |
@@ -307,14 +297,14 @@ inline MaybeLocal<Value> NullableSQLiteStringToValue(Isolate* isolate, | |||
| 307 | 297 | class CustomAggregate { | |
| 308 | 298 | public: | |
| 309 | 299 | explicit CustomAggregate(Environment* env, | |
| 310 | - DatabaseSync* db, | ||
| 300 | + BaseObjectWeakPtr<DatabaseSync> db, | ||
| 311 | 301 | bool use_bigint_args, | |
| 312 | 302 | Local<Value> start, | |
| 313 | 303 | Local<Function> step_fn, | |
| 314 | 304 | Local<Function> inverse_fn, | |
| 315 | 305 | Local<Function> result_fn) | |
| 316 | 306 | : env_(env), | |
| 317 | - db_(db), | ||
| 307 | + db_(std::move(db)), | ||
| 318 | 308 | use_bigint_args_(use_bigint_args), | |
| 319 | 309 | start_(env->isolate(), start), | |
| 320 | 310 | step_fn_(env->isolate(), step_fn), | |
@@ -350,7 +340,7 @@ class CustomAggregate { | |||
| 350 | 340 | Global<Function> CustomAggregate::*mptr) { | |
| 351 | 341 | CustomAggregate* self = | |
| 352 | 342 | static_cast<CustomAggregate*>(sqlite3_user_data(ctx)); | |
| 353 | - CallbackDepthGuard guard(self->db_); | ||
| 343 | + CallbackDepthGuard guard(self->db_.get()); | ||
| 354 | 344 | Environment* env = self->env_; | |
| 355 | 345 | Isolate* isolate = env->isolate(); | |
| 356 | 346 | auto agg = self->GetAggregate(ctx); | |
@@ -408,7 +398,7 @@ class CustomAggregate { | |||
| 408 | 398 | static inline void xValueBase(sqlite3_context* ctx, bool is_final) { | |
| 409 | 399 | CustomAggregate* self = | |
| 410 | 400 | static_cast<CustomAggregate*>(sqlite3_user_data(ctx)); | |
| 411 | - CallbackDepthGuard guard(self->db_); | ||
| 401 | + CallbackDepthGuard guard(self->db_.get()); | ||
| 412 | 402 | Environment* env = self->env_; | |
| 413 | 403 | Isolate* isolate = env->isolate(); | |
| 414 | 404 | auto agg = self->GetAggregate(ctx); | |
@@ -487,7 +477,7 @@ class CustomAggregate { | |||
| 487 | 477 | } | |
| 488 | 478 | ||
| 489 | 479 | Environment* env_; | |
| 490 | - DatabaseSync* db_; | ||
| 480 | + BaseObjectWeakPtr<DatabaseSync> db_; | ||
| 491 | 481 | bool use_bigint_args_; | |
| 492 | 482 | Global<Value> start_; | |
| 493 | 483 | Global<Function> step_fn_; | |
@@ -670,11 +660,11 @@ class BackupJob : public ThreadPoolWork { | |||
| 670 | 660 | ||
| 671 | 661 | UserDefinedFunction::UserDefinedFunction(Environment* env, | |
| 672 | 662 | Local<Function> fn, | |
| 673 | - DatabaseSync* db, | ||
| 663 | + BaseObjectWeakPtr<DatabaseSync> db, | ||
| 674 | 664 | bool use_bigint_args) | |
| 675 | 665 | : env_(env), | |
| 676 | 666 | fn_(env->isolate(), fn), | |
| 677 | - db_(db), | ||
| 667 | + db_(std::move(db)), | ||
| 678 | 668 | use_bigint_args_(use_bigint_args) {} | |
| 679 | 669 | ||
| 680 | 670 | UserDefinedFunction::~UserDefinedFunction() {} | |
@@ -684,7 +674,7 @@ void UserDefinedFunction::xFunc(sqlite3_context* ctx, | |||
| 684 | 674 | sqlite3_value** argv) { | |
| 685 | 675 | UserDefinedFunction* self = | |
| 686 | 676 | static_cast<UserDefinedFunction*>(sqlite3_user_data(ctx)); | |
| 687 | - CallbackDepthGuard guard(self->db_); | ||
| 677 | + CallbackDepthGuard guard(self->db_.get()); | ||
| 688 | 678 | Environment* env = self->env_; | |
| 689 | 679 | Isolate* isolate = env->isolate(); | |
| 690 | 680 | auto recv = Undefined(isolate); | |
@@ -1735,8 +1725,8 @@ void DatabaseSync::CustomFunction(const FunctionCallbackInfo<Value>& args) { | |||
| 1735 | 1725 | argc = js_len.As<Int32>()->Value(); | |
| 1736 | 1726 | } | |
| 1737 | 1727 | ||
| 1738 | - UserDefinedFunction* user_data = | ||
| 1739 | - new UserDefinedFunction(env, fn, db, use_bigint_args); | ||
| 1728 | + UserDefinedFunction* user_data = new UserDefinedFunction( | ||
| 1729 | + env, fn, BaseObjectWeakPtr<DatabaseSync>(db), use_bigint_args); | ||
| 1740 | 1730 | int text_rep = SQLITE_UTF8; | |
| 1741 | 1731 | ||
| 1742 | 1732 | if (deterministic) { | |
@@ -2057,22 +2047,23 @@ void DatabaseSync::AggregateFunction(const FunctionCallbackInfo<Value>& args) { | |||
| 2057 | 2047 | ||
| 2058 | 2048 | auto xInverse = !inverseFunc.IsEmpty() ? CustomAggregate::xInverse : nullptr; | |
| 2059 | 2049 | auto xValue = xInverse ? CustomAggregate::xValue : nullptr; | |
| 2060 | - int r = sqlite3_create_window_function(db->connection_, | ||
| 2061 | - *name, | ||
| 2062 | - argc, | ||
| 2063 | - text_rep, | ||
| 2064 | - new CustomAggregate(env, | ||
| 2065 | - db, | ||
| 2066 | - use_bigint_args, | ||
| 2067 | - start_v, | ||
| 2068 | - stepFunction, | ||
| 2069 | - inverseFunc, | ||
| 2070 | - resultFunction), | ||
| 2071 | - CustomAggregate::xStep, | ||
| 2072 | - CustomAggregate::xFinal, | ||
| 2073 | - xValue, | ||
| 2074 | - xInverse, | ||
| 2075 | - CustomAggregate::xDestroy); | ||
| 2050 | + int r = sqlite3_create_window_function( | ||
| 2051 | + db->connection_, | ||
| 2052 | + *name, | ||
| 2053 | + argc, | ||
| 2054 | + text_rep, | ||
| 2055 | + new CustomAggregate(env, | ||
| 2056 | + BaseObjectWeakPtr<DatabaseSync>(db), | ||
| 2057 | + use_bigint_args, | ||
| 2058 | + start_v, | ||
| 2059 | + stepFunction, | ||
| 2060 | + inverseFunc, | ||
| 2061 | + resultFunction), | ||
| 2062 | + CustomAggregate::xStep, | ||
| 2063 | + CustomAggregate::xFinal, | ||
| 2064 | + xValue, | ||
| 2065 | + xInverse, | ||
| 2066 | + CustomAggregate::xDestroy); | ||
| 2076 | 2067 | CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void()); | |
| 2077 | 2068 | } | |
| 2078 | 2069 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -430,7 +430,7 @@ class UserDefinedFunction { | |||
| 430 | 430 | public: | |
| 431 | 431 | UserDefinedFunction(Environment* env, | |
| 432 | 432 | v8::Local<v8::Function> fn, | |
| 433 | - DatabaseSync* db, | ||
| 433 | + BaseObjectWeakPtr<DatabaseSync> db, | ||
| 434 | 434 | bool use_bigint_args); | |
| 435 | 435 | ~UserDefinedFunction(); | |
| 436 | 436 | static void xFunc(sqlite3_context* ctx, int argc, sqlite3_value** argv); | |
@@ -439,7 +439,7 @@ class UserDefinedFunction { | |||
| 439 | 439 | private: | |
| 440 | 440 | Environment* env_; | |
| 441 | 441 | v8::Global<v8::Function> fn_; | |
| 442 | - DatabaseSync* db_; | ||
| 442 | + BaseObjectWeakPtr<DatabaseSync> db_; | ||
| 443 | 443 | bool use_bigint_args_; | |
| 444 | 444 | }; | |
| 445 | 445 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments