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: #28423
Fixes: nodejs/help#1998
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
  • Loading branch information
addaleax authored and targos committed Jul 2, 2019
1 parent 68b29ac commit 007965c
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 007965c

Please sign in to comment.