Skip to content

Commit 7382f64

Browse files
committed
Remove un-necessary comment/iostream and updated docs to reflect on limitations with this impl
1 parent 9afa9d5 commit 7382f64

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

doc/error_handling.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ If C++ exceptions are enabled (for more info see: [Setup](setup.md)), then the
1414
`Napi::Error` class extends `std::exception` and enables integrated
1515
error-handling for C++ exceptions and JavaScript exceptions.
1616

17+
Note, that due to limitations of the N-API, if one attempt to cast the error object thrown as a primitive, an
18+
wrapped object will be received instead. (With properties ```isWrapObject``` and ```errorVal``` containing the primitive value thrown)
19+
20+
1721
The following sections explain the approach for each case:
1822

1923
- [Handling Errors With C++ Exceptions](#exceptions)

napi-inl.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,13 +2531,12 @@ inline Object Error::Value() const {
25312531
if (_ref == nullptr) {
25322532
return Object(_env, nullptr);
25332533
}
2534-
// Most likely will mess up thread execution
25352534

25362535
napi_value refValue;
25372536
napi_status status = napi_get_reference_value(_env, _ref, &refValue);
25382537
NAPI_THROW_IF_FAILED(_env, status, Object());
25392538

2540-
// We are wrapping this object
2539+
// We are checking if the object is wrapped
25412540
bool isWrappedObject = false;
25422541
napi_has_property(
25432542
_env, refValue, String::From(_env, "isWrapObject"), &isWrappedObject);
@@ -2553,17 +2552,6 @@ inline Object Error::Value() const {
25532552

25542553
return Object(_env, refValue);
25552554
}
2556-
// template<typename T>
2557-
// inline T Error::Value() const {
2558-
// // if (_ref == nullptr) {
2559-
// // return T(_env, nullptr);
2560-
// // }
2561-
2562-
// // napi_value value;
2563-
// // napi_status status = napi_get_reference_value(_env, _ref, &value);
2564-
// // NAPI_THROW_IF_FAILED(_env, status, T());
2565-
// return nullptr;
2566-
// }
25672555

25682556
inline Error::Error(Error&& other) : ObjectReference(std::move(other)) {
25692557
}

napi.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <node_api.h>
55
#include <functional>
66
#include <initializer_list>
7-
#include <iostream>
87
#include <memory>
98
#include <mutex>
109
#include <string>

0 commit comments

Comments
 (0)