test: use assert() in N-API async test

The `Execute()` callback is not allowed to call into JS, so
we should use `assert()` instead of potentially throwing JS errors.

PR-URL: https://github.com/nodejs/node/pull/28423
Fixes: https://github.com/nodejs/help/issues/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>
This commit is contained in:
Anna Henningsen 2019-06-25 16:25:48 +02:00 committed by Daniel Bevenius
parent 6045fbbb5e
commit d11b5382d6

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include <stdio.h>
#include <node_api.h>
#include "../../js-native-api/common.h"
@ -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;
}