Skip to content

Commit 9e96632

Browse files
committed
sqlite: store authz error in internal object
1 parent e66a64c commit 9e96632

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/node_sqlite.cc

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,24 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, DatabaseSync* db) {
234234
}
235235

236236
bool DatabaseSync::HasPendingAuthorizerError() const {
237-
return has_pending_authorizer_error_;
237+
Local<Value> error =
238+
object()->GetInternalField(kPendingAuthorizerError).As<Value>();
239+
return !error.IsEmpty() && !error->IsUndefined();
238240
}
239241

240242
void DatabaseSync::StoreAuthorizerError(Local<Value> error) {
241-
if (!has_pending_authorizer_error_) {
242-
pending_authorizer_error_.Reset(env()->isolate(), error);
243-
has_pending_authorizer_error_ = true;
243+
if (!HasPendingAuthorizerError()) {
244+
object()->SetInternalField(kPendingAuthorizerError, error);
244245
}
245246
}
246247

247248
void DatabaseSync::RethrowPendingAuthorizerError() {
248-
if (has_pending_authorizer_error_) {
249-
Isolate* isolate = env()->isolate();
250-
Local<Value> err = pending_authorizer_error_.Get(isolate);
251-
pending_authorizer_error_.Reset();
252-
has_pending_authorizer_error_ = false;
253-
isolate->ThrowException(err);
249+
if (HasPendingAuthorizerError()) {
250+
Local<Value> error =
251+
object()->GetInternalField(kPendingAuthorizerError).As<Value>();
252+
object()->SetInternalField(kPendingAuthorizerError,
253+
Undefined(env()->isolate()));
254+
env()->isolate()->ThrowException(error);
254255
}
255256
}
256257

src/node_sqlite.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class DatabaseSync : public BaseObject {
113113
public:
114114
enum InternalFields {
115115
kAuthorizerCallback = BaseObject::kInternalFieldCount,
116+
kPendingAuthorizerError,
116117
kInternalFieldCount
117118
};
118119

@@ -193,9 +194,6 @@ class DatabaseSync : public BaseObject {
193194
std::set<sqlite3_session*> sessions_;
194195
std::unordered_set<StatementSync*> statements_;
195196

196-
bool has_pending_authorizer_error_ = false;
197-
v8::Global<v8::Value> pending_authorizer_error_;
198-
199197
friend class Session;
200198
friend class SQLTagStore;
201199
friend class StatementExecutionHelper;

0 commit comments

Comments
 (0)