@@ -56,40 +56,56 @@ using v8::Value;
5656 } \
5757 } while (0)
5858
59- inline Local<Object> CreateSQLiteError(Isolate* isolate, const char* message) {
60- Local<String> js_msg = String::NewFromUtf8(isolate, message).ToLocalChecked();
61- Local<Object> e = Exception::Error(js_msg)
62- ->ToObject(isolate->GetCurrentContext())
63- .ToLocalChecked();
64- e->Set(isolate->GetCurrentContext(),
65- OneByteString(isolate, "code"),
66- OneByteString(isolate, "ERR_SQLITE_ERROR"))
67- .Check();
59+ inline MaybeLocal<Object> CreateSQLiteError(Isolate* isolate,
60+ const char* message) {
61+ Local<String> js_msg;
62+ Local<Object> e;
63+ if (!String::NewFromUtf8(isolate, message).ToLocal(&js_msg) ||
64+ !Exception::Error(js_msg)
65+ ->ToObject(isolate->GetCurrentContext())
66+ .ToLocal(&e) ||
67+ e->Set(isolate->GetCurrentContext(),
68+ OneByteString(isolate, "code"),
69+ OneByteString(isolate, "ERR_SQLITE_ERROR"))
70+ .IsNothing()) {
71+ return MaybeLocal<Object>();
72+ }
6873 return e;
6974}
7075
71- inline Local <Object> CreateSQLiteError(Isolate* isolate, sqlite3* db) {
76+ inline MaybeLocal <Object> CreateSQLiteError(Isolate* isolate, sqlite3* db) {
7277 int errcode = sqlite3_extended_errcode(db);
7378 const char* errstr = sqlite3_errstr(errcode);
7479 const char* errmsg = sqlite3_errmsg(db);
75- Local<Object> e = CreateSQLiteError(isolate, errmsg);
76- e->Set(isolate->GetCurrentContext(),
77- OneByteString(isolate, "errcode"),
78- Integer::New(isolate, errcode))
79- .Check();
80- e->Set(isolate->GetCurrentContext(),
81- OneByteString(isolate, "errstr"),
82- String::NewFromUtf8(isolate, errstr).ToLocalChecked())
83- .Check();
80+ Local<String> js_errmsg;
81+ Local<Object> e;
82+ if (!String::NewFromUtf8(isolate, errstr).ToLocal(&js_errmsg) ||
83+ !CreateSQLiteError(isolate, errmsg).ToLocal(&e) ||
84+ e->Set(isolate->GetCurrentContext(),
85+ OneByteString(isolate, "errcode"),
86+ Integer::New(isolate, errcode))
87+ .IsNothing() ||
88+ e->Set(isolate->GetCurrentContext(),
89+ OneByteString(isolate, "errstr"),
90+ js_errmsg)
91+ .IsNothing()) {
92+ return MaybeLocal<Object>();
93+ }
8494 return e;
8595}
8696
8797inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, sqlite3* db) {
88- isolate->ThrowException(CreateSQLiteError(isolate, db));
98+ Local<Object> e;
99+ if (CreateSQLiteError(isolate, db).ToLocal(&e)) {
100+ isolate->ThrowException(e);
101+ }
89102}
90103
91104inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, const char* message) {
92- isolate->ThrowException(CreateSQLiteError(isolate, message));
105+ Local<Object> e;
106+ if (CreateSQLiteError(isolate, message).ToLocal(&e)) {
107+ isolate->ThrowException(e);
108+ }
93109}
94110
95111DatabaseSync::DatabaseSync(Environment* env,
0 commit comments