Skip to content

Commit

Permalink
test: use assert() in N-API async test
Browse files Browse the repository at this point in the history
The `Execute()` callback is not allowed to call into JS, so
we should use `assert()` instead of potentially throwing JS errors.

PR-URL: nodejs#28423
Fixes: nodejs/help#1998
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gabriel Schulhof <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
  • Loading branch information
addaleax authored and danbev committed Jun 28, 2019
1 parent 6045fbb commit d11b538
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions test/node-api/test_async/test_async.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <assert.h>
#include <stdio.h>
#include <node_api.h>
#include "../../js-native-api/common.h"
Expand Down Expand Up @@ -29,10 +30,7 @@ void Execute(napi_env env, void* data) {
#endif
carrier* c = static_cast<carrier*>(data);

if (c != &the_carrier) {
napi_throw_type_error(env, nullptr, "Wrong data parameter to Execute.");
return;
}
assert(c == &the_carrier);

c->_output = c->_input * 2;
}
Expand Down

0 comments on commit d11b538

Please sign in to comment.