@@ -4120,8 +4120,8 @@ inline AsyncWorker::AsyncWorker(const Object& receiver,
4120
4120
_env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
4121
4121
NAPI_THROW_IF_FAILED_VOID (_env, status);
4122
4122
4123
- status = napi_create_async_work (_env, resource, resource_id, OnExecute ,
4124
- OnWorkComplete , this , &_work);
4123
+ status = napi_create_async_work (_env, resource, resource_id, OnAsyncWorkExecute ,
4124
+ OnAsyncWorkComplete , this , &_work);
4125
4125
NAPI_THROW_IF_FAILED_VOID (_env, status);
4126
4126
}
4127
4127
@@ -4146,8 +4146,8 @@ inline AsyncWorker::AsyncWorker(Napi::Env env,
4146
4146
_env, resource_name, NAPI_AUTO_LENGTH, &resource_id);
4147
4147
NAPI_THROW_IF_FAILED_VOID (_env, status);
4148
4148
4149
- status = napi_create_async_work (_env, resource, resource_id, OnExecute ,
4150
- OnWorkComplete , this , &_work);
4149
+ status = napi_create_async_work (_env, resource, resource_id, OnAsyncWorkExecute ,
4150
+ OnAsyncWorkComplete , this , &_work);
4151
4151
NAPI_THROW_IF_FAILED_VOID (_env, status);
4152
4152
}
4153
4153
@@ -4234,40 +4234,51 @@ inline void AsyncWorker::SetError(const std::string& error) {
4234
4234
inline std::vector<napi_value> AsyncWorker::GetResult (Napi::Env /* env*/ ) {
4235
4235
return {};
4236
4236
}
4237
+ // The OnAsyncWorkExecute method receives an napi_env argument. However, do NOT
4238
+ // use it within this method, as it does not run on the JavaScript thread and
4239
+ // must not run any method that would cause JavaScript to run. In practice,
4240
+ // this means that almost any use of napi_env will be incorrect.
4241
+ inline void AsyncWorker::OnAsyncWorkExecute (napi_env env, void * asyncworker) {
4242
+ AsyncWorker* self = static_cast <AsyncWorker*>(asyncworker);
4243
+ self->OnExecute (env);
4244
+ }
4237
4245
// The OnExecute method receives an napi_env argument. However, do NOT
4238
- // use it within this method, as it does not run on the main thread and must
4239
- // not run any method that would cause JavaScript to run. In practice, this
4240
- // means that almost any use of napi_env will be incorrect.
4241
- inline void AsyncWorker::OnExecute (napi_env /* DO_NOT_USE*/ , void * this_pointer) {
4242
- AsyncWorker* self = static_cast <AsyncWorker*>(this_pointer);
4246
+ // use it within this method, as it does not run on the JavaScript thread and
4247
+ // must not run any method that would cause JavaScript to run. In practice,
4248
+ // this means that almost any use of napi_env will be incorrect.
4249
+ inline void AsyncWorker::OnExecute (Napi::Env /* DO_NOT_USE*/ ) {
4243
4250
#ifdef NAPI_CPP_EXCEPTIONS
4244
4251
try {
4245
- self-> Execute ();
4252
+ Execute ();
4246
4253
} catch (const std::exception& e) {
4247
- self-> SetError (e.what ());
4254
+ SetError (e.what ());
4248
4255
}
4249
4256
#else // NAPI_CPP_EXCEPTIONS
4250
- self-> Execute ();
4257
+ Execute ();
4251
4258
#endif // NAPI_CPP_EXCEPTIONS
4252
4259
}
4253
4260
4254
- inline void AsyncWorker::OnWorkComplete (
4255
- napi_env /* env*/ , napi_status status, void * this_pointer) {
4256
- AsyncWorker* self = static_cast <AsyncWorker*>(this_pointer);
4261
+ inline void AsyncWorker::OnAsyncWorkComplete (napi_env env,
4262
+ napi_status status,
4263
+ void * asyncworker) {
4264
+ AsyncWorker* self = static_cast <AsyncWorker*>(asyncworker);
4265
+ self->OnWorkComplete (env, status);
4266
+ }
4267
+ inline void AsyncWorker::OnWorkComplete (Napi::Env /* env*/ , napi_status status) {
4257
4268
if (status != napi_cancelled) {
4258
- HandleScope scope (self-> _env );
4269
+ HandleScope scope (_env);
4259
4270
details::WrapCallback ([&] {
4260
- if (self-> _error .size () == 0 ) {
4261
- self-> OnOK ();
4271
+ if (_error.size () == 0 ) {
4272
+ OnOK ();
4262
4273
}
4263
4274
else {
4264
- self-> OnError (Error::New (self-> _env , self-> _error ));
4275
+ OnError (Error::New (_env, _error));
4265
4276
}
4266
4277
return nullptr ;
4267
4278
});
4268
4279
}
4269
- if (!self-> _suppress_destruct ) {
4270
- self-> Destroy ();
4280
+ if (!_suppress_destruct) {
4281
+ Destroy ();
4271
4282
}
4272
4283
}
4273
4284
@@ -4632,14 +4643,14 @@ inline AsyncProgressWorker<T>::AsyncProgressWorker(const Function& callback,
4632
4643
4633
4644
template <class T >
4634
4645
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
4635
- const Function& callback)
4646
+ const Function& callback)
4636
4647
: AsyncProgressWorker(receiver, callback, " generic" ) {
4637
4648
}
4638
4649
4639
4650
template <class T >
4640
4651
inline AsyncProgressWorker<T>::AsyncProgressWorker(const Object& receiver,
4641
- const Function& callback,
4642
- const char * resource_name)
4652
+ const Function& callback,
4653
+ const char * resource_name)
4643
4654
: AsyncProgressWorker(receiver,
4644
4655
callback,
4645
4656
resource_name,
@@ -4665,14 +4676,14 @@ inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env)
4665
4676
4666
4677
template <class T >
4667
4678
inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env,
4668
- const char * resource_name)
4679
+ const char * resource_name)
4669
4680
: AsyncProgressWorker(env, resource_name, Object::New(env)) {
4670
4681
}
4671
4682
4672
4683
template <class T >
4673
4684
inline AsyncProgressWorker<T>::AsyncProgressWorker(Napi::Env env,
4674
- const char * resource_name,
4675
- const Object& resource)
4685
+ const char * resource_name,
4686
+ const Object& resource)
4676
4687
: AsyncWorker(env, resource_name, resource),
4677
4688
_asyncdata (nullptr ),
4678
4689
_asyncsize(0 ) {
@@ -4751,7 +4762,6 @@ template<class T>
4751
4762
inline void AsyncProgressWorker<T>::ExecutionProgress::Send(const T* data, size_t count) const {
4752
4763
_worker->SendProgress_ (data, count);
4753
4764
}
4754
-
4755
4765
#endif
4756
4766
4757
4767
// //////////////////////////////////////////////////////////////////////////////
0 commit comments