Skip to content

Commit

Permalink
Remove un-necessary comment/iostream and updated docs to reflect on l…
Browse files Browse the repository at this point in the history
…imitations with this impl
  • Loading branch information
JckXia committed Oct 23, 2021
1 parent ed4d1c5 commit c89f0bf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
4 changes: 4 additions & 0 deletions doc/error_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ If C++ exceptions are enabled (for more info see: [Setup](setup.md)), then the
`Napi::Error` class extends `std::exception` and enables integrated
error-handling for C++ exceptions and JavaScript exceptions.

Note, that due to limitations of the N-API, if one attempt to cast the error object thrown as a primitive, an
wrapped object will be received instead. (With properties ```isWrapObject``` and ```errorVal``` containing the primitive value thrown)


The following sections explain the approach for each case:

- [Handling Errors With C++ Exceptions](#exceptions)
Expand Down
14 changes: 1 addition & 13 deletions napi-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2628,13 +2628,12 @@ inline Object Error::Value() const {
if (_ref == nullptr) {
return Object(_env, nullptr);
}
// Most likely will mess up thread execution

napi_value refValue;
napi_status status = napi_get_reference_value(_env, _ref, &refValue);
NAPI_THROW_IF_FAILED(_env, status, Object());

// We are wrapping this object
// We are checking if the object is wrapped
bool isWrappedObject = false;
napi_has_property(
_env, refValue, String::From(_env, "isWrapObject"), &isWrappedObject);
Expand All @@ -2650,17 +2649,6 @@ inline Object Error::Value() const {

return Object(_env, refValue);
}
// template<typename T>
// inline T Error::Value() const {
// // if (_ref == nullptr) {
// // return T(_env, nullptr);
// // }

// // napi_value value;
// // napi_status status = napi_get_reference_value(_env, _ref, &value);
// // NAPI_THROW_IF_FAILED(_env, status, T());
// return nullptr;
// }

inline Error::Error(Error&& other) : ObjectReference(std::move(other)) {
}
Expand Down
1 change: 0 additions & 1 deletion napi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <node_api.h>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <memory>
#include <mutex>
#include <string>
Expand Down

0 comments on commit c89f0bf

Please sign in to comment.