@@ -1763,21 +1763,25 @@ void DatabaseSync::ApplyChangeset(const FunctionCallbackInfo<Value>& args) {
17631763
17641764 Local<Function> filterFunc = filterValue.As <Function>();
17651765
1766- context.filterCallback = [env,
1767- filterFunc](std::string_view item) -> bool {
1768- // TODO(@jasnell): The use of ToLocalChecked here means that if
1769- // the filter function throws an error the process will crash.
1770- // The filterCallback should be updated to avoid the check and
1771- // propagate the error correctly.
1772- Local<Value> argv[] = {
1773- String::NewFromUtf8 (env->isolate (),
1774- item.data (),
1775- NewStringType::kNormal ,
1776- static_cast <int >(item.size ()))
1777- .ToLocalChecked ()};
1778- Local<Value> result =
1779- filterFunc->Call (env->context (), Null (env->isolate ()), 1 , argv)
1780- .ToLocalChecked ();
1766+ context.filterCallback =
1767+ [db, env, filterFunc](std::string_view item) -> bool {
1768+ Local<Value> argv[1 ];
1769+ if (!String::NewFromUtf8 (env->isolate (),
1770+ item.data (),
1771+ NewStringType::kNormal ,
1772+ static_cast <int >(item.size ()))
1773+ .ToLocal (&argv[0 ])) {
1774+ db->SetIgnoreNextSQLiteError (true );
1775+ return false ;
1776+ }
1777+
1778+ Local<Value> result;
1779+ if (!filterFunc->Call (env->context (), Null (env->isolate ()), 1 , argv)
1780+ .ToLocal (&result)) {
1781+ db->SetIgnoreNextSQLiteError (true );
1782+ return false ;
1783+ }
1784+
17811785 return result->BooleanValue (env->isolate ());
17821786 };
17831787 }
@@ -2239,9 +2243,11 @@ Local<Value> StatementExecutionHelper::Get(Environment* env,
22392243 LocalVector<Name> keys (isolate);
22402244 keys.reserve (num_cols);
22412245 for (int i = 0 ; i < num_cols; ++i) {
2242- MaybeLocal<Name> key = ColumnNameToName (env, stmt, i);
2243- if (key.IsEmpty ()) return Undefined (isolate);
2244- keys.emplace_back (key.ToLocalChecked ());
2246+ Local<Name> key;
2247+ if (!ColumnNameToName (env, stmt, i).ToLocal (&key)) {
2248+ return Undefined (isolate);
2249+ }
2250+ keys.emplace_back (key);
22452251 }
22462252
22472253 DCHECK_EQ (keys.size (), row_values.size ());
@@ -2755,12 +2761,8 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
27552761
27562762 if (stmt == nullptr ) {
27572763 sqlite3_stmt* s = nullptr ;
2758- Local<String> sql_str =
2759- String::NewFromUtf8 (isolate, sql.c_str ()).ToLocalChecked ();
2760- Utf8Value sql_utf8 (isolate, sql_str);
2761-
27622764 int r = sqlite3_prepare_v2 (
2763- session->database_ ->connection_ , *sql_utf8 , -1 , &s, 0 );
2765+ session->database_ ->connection_ , sql. c_str () , -1 , &s, 0 );
27642766
27652767 if (r != SQLITE_OK) {
27662768 THROW_ERR_SQLITE_ERROR (isolate, " Failed to prepare statement" );
0 commit comments