Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conditional support for C++ exceptions (#52)
Enable using the N-API C++ wrapper classes with or without C++ exceptions. See the updated `Napi::Error` class documentation for an overview of the developer experience. - Add a `NAPI_CPP_EXCEPTIONS` preprocessor symbol that is defined when C++ exceptions are enabled. - Add `Env::GetAndClearPendingException()` method. - Add `Value::IsEmpty()` method. - Update documentation on Error class to provide parallel explanation and examples for error-handling without C++ exceptions. - Update README to mention optional C++ exception support. - Define a `NAPI_THROW_IF_FAILED()` macro that throws either a C++ or JS exception depending on whether `NAPI_CPP_EXCEPTIONS` is defined. - Define a `details::WrapCallback()` helper function that catches C++ exceptions thrown from callbacks, only if `NAPI_CPP_EXCEPTIONS` is defined. - Update implementation of all methods to use `NAPI_THROW_IF_FAILED()` and `details::WrapCallback()` as appropriate. - Fix a bug in `Error::New()` when there was a pending exception but some different error status was reported by the last error info. - Update `test/binding.gyp` to build two separate modules, with and without C++ exceptions enabled. - Update test JS code to run the same tests against both modules. - Update test C++ code to throw JS exceptions (to be compatible with both modes). - Add some additional test cases to verify expected exceptions are observed from JS regardless of whether C++ exceptions are enabled or not. - Change CI config to ignore failures on nightly builds.
- Loading branch information