@@ -4085,8 +4085,8 @@ inline AsyncWorker::AsyncWorker(const Object& receiver,
4085
4085
_env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
4086
4086
NAPI_THROW_IF_FAILED_VOID (_env, status);
4087
4087
4088
- status = napi_create_async_work (_env, resource, resource_id, OnExecute ,
4089
- OnWorkComplete , this , &_work);
4088
+ status = napi_create_async_work (_env, resource, resource_id, OnAsyncWorkExecute ,
4089
+ OnAsyncWorkComplete , this , &_work);
4090
4090
NAPI_THROW_IF_FAILED_VOID (_env, status);
4091
4091
}
4092
4092
@@ -4111,8 +4111,8 @@ inline AsyncWorker::AsyncWorker(Napi::Env env,
4111
4111
_env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
4112
4112
NAPI_THROW_IF_FAILED_VOID (_env, status);
4113
4113
4114
- status = napi_create_async_work (_env, resource, resource_id, OnExecute ,
4115
- OnWorkComplete , this , &_work);
4114
+ status = napi_create_async_work (_env, resource, resource_id, OnAsyncWorkExecute ,
4115
+ OnAsyncWorkComplete , this , &_work);
4116
4116
NAPI_THROW_IF_FAILED_VOID (_env, status);
4117
4117
}
4118
4118
@@ -4199,40 +4199,51 @@ inline void AsyncWorker::SetError(const std::string& error) {
4199
4199
inline std::vector<napi_value> AsyncWorker::GetResult (Napi::Env /* env*/ ) {
4200
4200
return {};
4201
4201
}
4202
+ // The OnAsyncWorkExecute method receives an napi_env argument. However, do NOT
4203
+ // use it within this method, as it does not run on the main thread and must
4204
+ // not run any method that would cause JavaScript to run. In practice, this
4205
+ // means that almost any use of napi_env will be incorrect.
4206
+ inline void AsyncWorker::OnAsyncWorkExecute (napi_env env, void * asyncworker) {
4207
+ AsyncWorker* self = static_cast <AsyncWorker*>(asyncworker);
4208
+ self->OnExecute (env);
4209
+ }
4202
4210
// The OnExecute method receives an napi_env argument. However, do NOT
4203
4211
// use it within this method, as it does not run on the main thread and must
4204
4212
// not run any method that would cause JavaScript to run. In practice, this
4205
4213
// means that almost any use of napi_env will be incorrect.
4206
- inline void AsyncWorker::OnExecute (napi_env /* DO_NOT_USE*/ , void * this_pointer) {
4207
- AsyncWorker* self = static_cast <AsyncWorker*>(this_pointer);
4214
+ inline void AsyncWorker::OnExecute (Napi::Env /* DO_NOT_USE*/ ) {
4208
4215
#ifdef NAPI_CPP_EXCEPTIONS
4209
4216
try {
4210
- self ->Execute ();
4217
+ this ->Execute ();
4211
4218
} catch (const std::exception& e) {
4212
- self ->SetError (e.what ());
4219
+ this ->SetError (e.what ());
4213
4220
}
4214
4221
#else // NAPI_CPP_EXCEPTIONS
4215
- self ->Execute ();
4222
+ this ->Execute ();
4216
4223
#endif // NAPI_CPP_EXCEPTIONS
4217
4224
}
4218
4225
4219
- inline void AsyncWorker::OnWorkComplete (
4220
- napi_env /* env*/ , napi_status status, void * this_pointer) {
4221
- AsyncWorker* self = static_cast <AsyncWorker*>(this_pointer);
4226
+ inline void AsyncWorker::OnAsyncWorkComplete (napi_env env,
4227
+ napi_status status,
4228
+ void * asyncworker) {
4229
+ AsyncWorker* self = static_cast <AsyncWorker*>(asyncworker);
4230
+ self->OnWorkComplete (env, status);
4231
+ }
4232
+ inline void AsyncWorker::OnWorkComplete (Napi::Env /* env*/ , napi_status status) {
4222
4233
if (status != napi_cancelled) {
4223
- HandleScope scope (self ->_env );
4234
+ HandleScope scope (this ->_env );
4224
4235
details::WrapCallback ([&] {
4225
- if (self ->_error .size () == 0 ) {
4226
- self ->OnOK ();
4236
+ if (this ->_error .size () == 0 ) {
4237
+ this ->OnOK ();
4227
4238
}
4228
4239
else {
4229
- self ->OnError (Error::New (self ->_env , self ->_error ));
4240
+ this ->OnError (Error::New (this ->_env , this ->_error ));
4230
4241
}
4231
4242
return nullptr ;
4232
4243
});
4233
4244
}
4234
- if (!self ->_suppress_destruct ) {
4235
- self ->Destroy ();
4245
+ if (!this ->_suppress_destruct ) {
4246
+ this ->Destroy ();
4236
4247
}
4237
4248
}
4238
4249
@@ -4597,14 +4608,14 @@ inline AsyncProgressWorker<T>::AsyncProgressWorker(const Function& callback,
4597
4608
4598
4609
template <class T >
4599
4610
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
4600
- const Function& callback)
4611
+ const Function& callback)
4601
4612
: AsyncProgressWorker(receiver, callback, " generic" ) {
4602
4613
}
4603
4614
4604
4615
template <class T >
4605
4616
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
4606
- const Function& callback,
4607
- const char * resource_name)
4617
+ const Function& callback,
4618
+ const char * resource_name)
4608
4619
: AsyncProgressWorker(receiver,
4609
4620
callback,
4610
4621
resource_name,
@@ -4630,14 +4641,14 @@ inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env)
4630
4641
4631
4642
template <class T >
4632
4643
inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env,
4633
- const char * resource_name)
4644
+ const char * resource_name)
4634
4645
: AsyncProgressWorker(env, resource_name, Object::New(env)) {
4635
4646
}
4636
4647
4637
4648
template <class T >
4638
4649
inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env,
4639
- const char * resource_name,
4640
- const Object& resource)
4650
+ const char * resource_name,
4651
+ const Object& resource)
4641
4652
: AsyncWorker(env, resource_name, resource),
4642
4653
_asyncdata (nullptr ),
4643
4654
_asyncsize(0 ) {
@@ -4716,7 +4727,6 @@ template<class T>
4716
4727
inline void AsyncProgressWorker<T>::ExecutionProgress::Send(const T* data, size_t count) const {
4717
4728
_worker->SendProgress_ (data, count);
4718
4729
}
4719
-
4720
4730
#endif
4721
4731
4722
4732
// //////////////////////////////////////////////////////////////////////////////
0 commit comments