From 8db30d30ac0bc79433cc8637e51300a5fe1fa3a1 Mon Sep 17 00:00:00 2001 From: Keunwoo Lee Date: Thu, 18 Jul 2024 11:47:46 -0700 Subject: [PATCH] Check that exports succeeded The `exports->Set` call here returns a `Maybe` indicating whether it succeeded. Before this change, we ignored this result. This effectively never fails, but the unused result triggers a warning in some compilers. This change adds a Check() to this site to assert that the export succeeded. Note that this crashes the process on failure, but as noted this failure shouldn't happen, and it's unlikely that clients can usefully recover in any case. --- src/cursor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cursor.cpp b/src/cursor.cpp index 2658188df7..db428b41f9 100644 --- a/src/cursor.cpp +++ b/src/cursor.cpp @@ -378,5 +378,10 @@ void CursorWrap::setupExports(Local exports) { cursorTpl->PrototypeTemplate()->Set(Nan::New("del").ToLocalChecked(), Nan::New(CursorWrap::del)); // Set exports - exports->Set(Nan::GetCurrentContext(), Nan::New("Cursor").ToLocalChecked(), cursorTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); + Maybe exportResult = exports->Set(Nan::GetCurrentContext(), Nan::New("Cursor").ToLocalChecked(), cursorTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked()); + // Assert that the export succeeded. + // Note the comment here about the return value of V8Object::Set: + // > Set only return[s] Just(true) or Empty(), so if it should never fail, use result.Check(). + // https://github.com/nodejs/node/blob/cafd44dc7eff20cfa6c36b289e24efd793d4422a/deps/v8/include/v8-object.h#L236-L244 + exportResult.Check(); }