11export module napi_js:remote;
22import :environment;
3+ import :lock;
34import :reference;
45import std;
56import util;
@@ -24,14 +25,16 @@ class remote : protected reference_handle {
2425 using unique_remote = std::unique_ptr<remote, util::function_constant<expire>>;
2526
2627 remote () = default ;
27- remote (private_constructor /* private*/ , const environment& env , local_of<Tag> value, napi_scheduler scheduler) :
28- reference_handle{napi_env{env }, napi_value{value}},
28+ remote (private_constructor /* private*/ , environment_lock_witness lock , local_of<Tag> value, napi_scheduler scheduler) :
29+ reference_handle{napi_env{lock }, napi_value{value}},
2930 scheduler_{std::move (scheduler)} {}
3031
31- auto deref (const environment& env ) const -> local_of<Tag>;
32+ auto deref (environment_lock_witness lock ) const -> local_of<Tag>;
3233
33- static auto make_shared (remote_handle_environment auto & env, local_of<Tag> value) -> std::shared_ptr<remote>;
34- static auto make_unique (remote_handle_environment auto & env, local_of<Tag> value) -> unique_remote;
34+ template <remote_handle_environment Environment>
35+ static auto make_shared (const environment_lock_witness_of<Environment>& lock, local_of<Tag> value) -> std::shared_ptr<remote>;
36+ template <remote_handle_environment Environment>
37+ static auto make_unique (const environment_lock_witness_of<Environment>& lock, local_of<Tag> value) -> unique_remote;
3538
3639 private:
3740 napi_scheduler scheduler_;
@@ -44,14 +47,14 @@ using shared_remote = std::shared_ptr<remote<Type>>;
4447export template <class Type >
4548using unique_remote = remote<Type>::unique_remote;
4649
47- export template <class Tag >
48- auto make_shared_remote (remote_handle_environment auto & env , local_of<Tag> value) -> shared_remote<Tag> {
49- return remote<Tag>::make_shared (env , value);
50+ export template <remote_handle_environment Environment, class Tag >
51+ auto make_shared_remote (const environment_lock_witness_of<Environment>& lock , local_of<Tag> value) -> shared_remote<Tag> {
52+ return remote<Tag>::make_shared (lock , value);
5053}
5154
52- export template <class Tag >
53- auto make_unique_remote (remote_handle_environment auto & env , local_of<Tag> value) -> unique_remote<Tag> {
54- return remote<Tag>::make_unique (env , value);
55+ export template <remote_handle_environment Environment, class Tag >
56+ auto make_unique_remote (const environment_lock_witness_of<Environment>& lock , local_of<Tag> value) -> unique_remote<Tag> {
57+ return remote<Tag>::make_unique (lock , value);
5558}
5659
5760// ---
@@ -68,18 +71,20 @@ auto remote<Tag>::expire(remote* ptr) -> void {
6871}
6972
7073template <class Tag >
71- auto remote<Tag>::deref(const environment& env ) const -> local_of<Tag> {
72- return local_of<Tag>::from (get_value (napi_env{env }));
74+ auto remote<Tag>::deref(environment_lock_witness lock ) const -> local_of<Tag> {
75+ return local_of<Tag>::from (get_value (napi_env{lock }));
7376}
7477
7578template <class Tag >
76- auto remote<Tag>::make_shared(remote_handle_environment auto & env, local_of<Tag> value) -> std::shared_ptr<remote> {
77- return std::shared_ptr<remote>{new remote{private_constructor{}, env, value, env.scheduler ()}, expire};
79+ template <remote_handle_environment Environment>
80+ auto remote<Tag>::make_shared(const environment_lock_witness_of<Environment>& lock, local_of<Tag> value) -> std::shared_ptr<remote> {
81+ return std::shared_ptr<remote>{new remote{private_constructor{}, lock, value, lock->scheduler ()}, expire};
7882}
7983
8084template <class Tag >
81- auto remote<Tag>::make_unique(remote_handle_environment auto & env, local_of<Tag> value) -> unique_remote {
82- return unique_remote{new remote{private_constructor{}, env, value, env.scheduler ()}};
85+ template <remote_handle_environment Environment>
86+ auto remote<Tag>::make_unique(const environment_lock_witness_of<Environment>& lock, local_of<Tag> value) -> unique_remote {
87+ return unique_remote{new remote{private_constructor{}, lock, value, lock->scheduler ()}};
8388}
8489
8590} // namespace js::napi
0 commit comments