Skip to content

Commit d2bcc03

Browse files
committed
test: napi v4,v5 all tests pass
1 parent 89d2dea commit d2bcc03

File tree

8 files changed

+328
-197
lines changed

8 files changed

+328
-197
lines changed

napi-inl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,7 +4551,7 @@ ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New(
45514551
return tsfn;
45524552
}
45534553

4554-
// static, with Callback [x] Resource [x] Finalizer [missing]
4554+
// static, with Callback [passed] Resource [passed] Finalizer [missing]
45554555
template <typename ContextType, typename DataType,
45564556
void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)>
45574557
template <typename ResourceString>
@@ -4574,7 +4574,7 @@ ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New(
45744574
return tsfn;
45754575
}
45764576

4577-
// static, with Callback [x] Resource [missing ] Finalizer [x]
4577+
// static, with Callback [passed] Resource [missing] Finalizer [passed]
45784578
template <typename ContextType, typename DataType,
45794579
void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)>
45804580
template <typename ResourceString, typename Finalizer,
@@ -4604,7 +4604,7 @@ ThreadSafeFunctionEx<ContextType, DataType, CallJs>::New(
46044604
return tsfn;
46054605
}
46064606

4607-
// static, with: Callback [x] Resource [x] Finalizer [x]
4607+
// static, with: Callback [passed] Resource [passed] Finalizer [passed]
46084608
template <typename ContextType, typename DataType,
46094609
void (*CallJs)(Napi::Env, Napi::Function, ContextType *, DataType *)>
46104610
template <typename ResourceString, typename Finalizer,

napi.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,9 @@ namespace Napi {
20432043
};
20442044

20452045
#if (NAPI_VERSION > 3)
2046-
template <typename ContextType = void, typename DataType = void,
2046+
// A ThreadSafeFunctionEx by default has no context (nullptr) and can accept
2047+
// any type (void) to its CallJs.
2048+
template <typename ContextType = std::nullptr_t, typename DataType = void,
20472049
void (*CallJs)(Napi::Env, Napi::Function, ContextType *,
20482050
DataType *) = nullptr>
20492051
class ThreadSafeFunctionEx {
@@ -2058,7 +2060,8 @@ namespace Napi {
20582060
// This API may only be called from the main thread.
20592061
// Helper function that returns nullptr if running N-API 5+, otherwise a
20602062
// non-empty, no-op Function. This provides the ability to specify at
2061-
// compile-time a callback parameter to `New` that safely does no action.
2063+
// compile-time a callback parameter to `New` that safely does no action
2064+
// when targeting _any_ N-API version.
20622065
static DefaultFunctionType DefaultFunctionFactory(Napi::Env env);
20632066

20642067
#if NAPI_VERSION > 4

test/threadsafe_function_ex/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
const tests = [
2+
// 'threadsafe',
3+
'basic',
4+
'example'
5+
];
6+
7+
// Threadsafe tests must run synchronously. If two threaded-tests are running
8+
// and one fails, Node may exit while `std::thread`s are running.
19
module.exports = (async () => {
2-
await require('./test/threadsafe')
3-
await require('./test/basic');
4-
await require('./test/example');
5-
})();
10+
for (const test of tests) {
11+
await require(`./test/${test}`);
12+
}
13+
})();

0 commit comments

Comments
 (0)