Methods not returning after throwing Javascript exception
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 38/100
Research direction
Start in 6_object_wrap_example/node-addon-api/myobject.cc, especially the constructor path around line 28, and reproduce the no-argument call. Check the node-addon-api exception-handling guidance, then ensure the example stops after ThrowAsJavaScriptException so the documented error is preserved and the unwrapping case does not continue into a segmentation fault.
Written by the indexing model from the issue text.
Description
In the "6_object_wrap_example/node-addon-api", I tried to test what would happen when calling the constructor without arguments and I noticed that the actual exception thrown ("A number was expected") is different from the one in the code ("Number expected").
According to node-addon-api docs, when C++ exceptions are disabled you need to return immediately after calling ThrowAsJavaScriptException. So I would expect something like:
if (length <= 0 || !info[0].IsNumber()) {
Napi::TypeError::New(env, "Number expected").ThrowAsJavaScriptException();
return;
}
I think that the exception thrown is not the one from line 28 of myobject.cc, but another one thrown automatically when trying to convert the parameter to a number.
I tried to move one step further (following this tutorial) and unwrapping a Javascript object, and I get a segmentation fault when using the constructor without arguments because the code is not stopping after reaching the line with ThrowAsJavaScriptException.
- Dominant language
- C++
- Stars
- 2.6k
- Forks
- 602
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nodejs/node-addon-examples
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 38/100
nodejs/node-addon-examples#585 · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
nodejs/node-addon-examples#530 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
nodejs/node-addon-examples#445 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 32/100
nodejs/node-addon-examples#444 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
nodejs/node-addon-examples#381 ·
All issues in nodejs/node-addon-examples
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Sensor initialization takes very long when `--initial-sim-time` is set to current UNIX timestamp Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gazebosim/gz-sensors#662 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LadybirdBrowser/ladybird#12123 ·