-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: return Maybe<> on pending exception when cpp exception disabled #927
Conversation
019adad
to
2b40b49
Compare
This comment has been minimized.
This comment has been minimized.
96baadc
to
7d933d0
Compare
This comment has been minimized.
This comment has been minimized.
d75115a
to
e42a1b9
Compare
eb8980e
to
9684123
Compare
@nodejs/node-api hi, team, I believe this PR is ready and may take some reviews. Thanks a lot! |
A few questions that we might discuss more in the nest team meeting
|
test/README.md
Outdated
|
||
Value fn(const CallbackInfo& info) { | ||
Object obj = info[0].As<Object>(); | ||
Value value = MaybeUnwrap(obj->Get("foobar")); // <- `obj->Get` may throws |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in a return or is it that we need to use the helpers for more than returns as well?
test/README.md
Outdated
are defined as `Napi::MaybeOrValue<>` to prevent from duplicating most of the | ||
code base. | ||
|
||
To properly test these build flavors, we should take care of the return value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be something like.
To properly test these build flavors, all values returned by a function defined/used within the
node-addon-api test suite, should use one of helpers to ....
napi-inl.h
Outdated
napi_value result; | ||
napi_status status = napi_coerce_to_number(_env, _value, &result); | ||
NAPI_THROW_IF_FAILED(_env, status, Number()); | ||
return Number(_env, result); | ||
NAPI_MAYBE_RETURN_OR_THROW_IF_FAILED( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe this should just be called:
NAPI_RETURN_OR_THROW_IF_FAILED
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds much simpler. Renamed.
napi-inl.h
Outdated
} | ||
|
||
inline bool Object::InstanceOf(const Function& constructor) const { | ||
inline MaybeOrValue<bool> Object::InstanceOf(const Function& constructor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remain const
based on our discussion about #992.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gabrielschulhof thanks for catching that, not sure why I did not find it on my second look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching it, fixed.
@legendecas looks like this needs to be rebased. |
# Conflicts: # napi-inl.h # test/binding.gyp
test/README.md
Outdated
```cpp | ||
#include "napi.h" | ||
#include "test_helper.h" | ||
|
||
using namespace Napi; | ||
|
||
void fn(const CallbackInfo& info) { | ||
Object obj = info[0].As<Object>(); | ||
Value value = MaybeUnwrap(obj->Get("foobar")); // <- `obj->Get` is calling | ||
// into JavaScript and may throw JavaScript Exceptions. Here we just assert | ||
// getting the parameter must not fail for convenience. | ||
|
||
// ... do works with the value. | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be better after the three examples or maybe it could just be removed if we had examples in each of the sections for the helpers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@gabrielschulhof 👋 may I have your review on this again? thanks a lot! |
@@ -115,64 +120,120 @@ class Test : public Napi::ObjectWrap<Test> { | |||
Napi::Symbol kTestMethodTInternal = Napi::Symbol::New(env, "kTestMethodTInternal"); | |||
Napi::Symbol kTestVoidMethodTInternal = Napi::Symbol::New(env, "kTestVoidMethodTInternal"); | |||
|
|||
exports.Set("Test", DefineClass(env, "Test", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one and many lines below look like pure whitespace changes. Are they necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two new elements at the bottom of the block. git-clang-format will check with blocks as minimum units.
@gabrielschulhof hi, PR updated with suggestion applied. PTAL, thanks a lot! |
@gabrielschulhof I'll plan to land end of this week unless you have objections/additional comments before then. |
@mhdawson @gabrielschulhof 👋 should we land this PR now? |
@legendecas could you squash into 1 commit? I tried landing and I ended up with conflicts. |
@mhdawson used the GitHub interface to squash merging. It seems no conflicts at all.. |
PR-URL: nodejs#927 Reviewed-By: Michael Dawson <[email protected]>
PR-URL: nodejs#927 Reviewed-By: Michael Dawson <[email protected]>
PR-URL: nodejs/node-addon-api#927 Reviewed-By: Michael Dawson <[email protected]>
PR-URL: nodejs/node-addon-api#927 Reviewed-By: Michael Dawson <[email protected]>
PR-URL: nodejs/node-addon-api#927 Reviewed-By: Michael Dawson <[email protected]>
PR-URL: nodejs/node-addon-api#927 Reviewed-By: Michael Dawson <[email protected]>
Fixes: #690
This PR introduced a Maybe type to enforce value existence check when CPP exceptions disabled and there is a pending JavaScript exception so that the operation can not be performed.
The
Maybe
returning behavior requires a predefined macroNODE_ADDON_API_ENABLE_MAYBE
to enable.