Skip to content

Commit 8db30d3

Browse files
committed
Check that exports succeeded
The `exports->Set` call here returns a `Maybe<bool>` 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.
1 parent ef1c424 commit 8db30d3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/cursor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,10 @@ void CursorWrap::setupExports(Local<Object> exports) {
378378
cursorTpl->PrototypeTemplate()->Set(Nan::New<String>("del").ToLocalChecked(), Nan::New<FunctionTemplate>(CursorWrap::del));
379379

380380
// Set exports
381-
exports->Set(Nan::GetCurrentContext(), Nan::New<String>("Cursor").ToLocalChecked(), cursorTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
381+
Maybe<bool> exportResult = exports->Set(Nan::GetCurrentContext(), Nan::New<String>("Cursor").ToLocalChecked(), cursorTpl->GetFunction(Nan::GetCurrentContext()).ToLocalChecked());
382+
// Assert that the export succeeded.
383+
// Note the comment here about the return value of V8Object::Set:
384+
// > Set only return[s] Just(true) or Empty(), so if it should never fail, use result.Check().
385+
// https://github.com/nodejs/node/blob/cafd44dc7eff20cfa6c36b289e24efd793d4422a/deps/v8/include/v8-object.h#L236-L244
386+
exportResult.Check();
382387
}

0 commit comments

Comments
 (0)