@auto_js/napi 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,8 +15,8 @@ struct reaccept_napi_value {
15
15
  }
16
16
 
17
17
  template <class Tag>
18
- constexpr auto operator()(std::type_identity<value_of<Tag>> /*type*/, napi_value value) const -> value_of<Tag> {
19
- return value_of<Tag>::from(value);
18
+ constexpr auto operator()(std::type_identity<local_of<Tag>> /*type*/, napi_value value) const -> local_of<Tag> {
19
+ return local_of<Tag>::from(value);
20
20
  }
21
21
  };
22
22
 
@@ -29,112 +29,112 @@ struct accept_basic_napi_value {
29
29
  using accept_reference_type = reaccept_napi_value;
30
30
 
31
31
  // undefined & null
32
- auto operator()(undefined_tag tag, visit_holder visit, std::monostate subject) const -> value_of<undefined_tag>;
33
- auto operator()(undefined_tag tag, visit_holder visit, const auto& /*subject*/) const -> value_of<undefined_tag> {
32
+ auto operator()(undefined_tag tag, visit_holder visit, std::monostate subject) const -> local_of<undefined_tag>;
33
+ auto operator()(undefined_tag tag, visit_holder visit, const auto& /*subject*/) const -> local_of<undefined_tag> {
34
34
  return (*this)(tag, visit, std::monostate{});
35
35
  }
36
36
 
37
- auto operator()(null_tag tag, visit_holder visit, std::nullptr_t subject) const -> value_of<null_tag>;
38
- auto operator()(null_tag tag, visit_holder visit, const auto& /*subject*/) const -> value_of<null_tag> {
37
+ auto operator()(null_tag tag, visit_holder visit, std::nullptr_t subject) const -> local_of<null_tag>;
38
+ auto operator()(null_tag tag, visit_holder visit, const auto& /*subject*/) const -> local_of<null_tag> {
39
39
  return (*this)(tag, visit, nullptr);
40
40
  }
41
41
 
42
42
  // boolean
43
- auto operator()(boolean_tag tag, visit_holder visit, bool subject) const -> value_of<boolean_tag>;
43
+ auto operator()(boolean_tag tag, visit_holder visit, bool subject) const -> local_of<boolean_tag>;
44
44
 
45
45
  // number
46
- auto operator()(number_tag_of<double> tag, visit_holder visit, double subject) const -> value_of<number_tag_of<double>>;
47
- auto operator()(number_tag_of<std::int32_t> tag, visit_holder visit, std::int32_t subject) const -> value_of<number_tag_of<std::int32_t>>;
48
- auto operator()(number_tag_of<std::uint32_t> tag, visit_holder visit, std::uint32_t subject) const -> value_of<number_tag_of<std::uint32_t>>;
46
+ auto operator()(number_tag_of<double> tag, visit_holder visit, double subject) const -> local_of<number_tag_of<double>>;
47
+ auto operator()(number_tag_of<std::int32_t> tag, visit_holder visit, std::int32_t subject) const -> local_of<number_tag_of<std::int32_t>>;
48
+ auto operator()(number_tag_of<std::uint32_t> tag, visit_holder visit, std::uint32_t subject) const -> local_of<number_tag_of<std::uint32_t>>;
49
49
 
50
- auto operator()(number_tag /*tag*/, visit_holder visit, auto&& subject) const -> value_of<number_tag> {
50
+ auto operator()(number_tag /*tag*/, visit_holder visit, auto&& subject) const -> local_of<number_tag> {
51
51
  return (*this)(number_tag_of<double>{}, visit, double{std::forward<decltype(subject)>(subject)});
52
52
  }
53
53
 
54
54
  template <class Type>
55
- auto operator()(number_tag_of<Type> tag, visit_holder visit, auto&& subject) const -> value_of<number_tag_of<Type>> {
55
+ auto operator()(number_tag_of<Type> tag, visit_holder visit, auto&& subject) const -> local_of<number_tag_of<Type>> {
56
56
  return (*this)(tag, visit, Type{std::forward<decltype(subject)>(subject)});
57
57
  }
58
58
 
59
59
  // string
60
60
  auto operator()(string_tag_of<char> tag, visit_holder visit, std::string_view subject) const
61
- -> js::referenceable_value<value_of<string_tag_of<char>>>;
61
+ -> js::referenceable_value<local_of<string_tag_of<char>>>;
62
62
  auto operator()(string_tag_of<char8_t> tag, visit_holder visit, std::u8string_view subject) const
63
- -> js::referenceable_value<value_of<string_tag_of<char8_t>>>;
63
+ -> js::referenceable_value<local_of<string_tag_of<char8_t>>>;
64
64
  auto operator()(string_tag_of<char16_t> tag, visit_holder visit, std::u16string_view subject) const
65
- -> js::referenceable_value<value_of<string_tag_of<char16_t>>>;
65
+ -> js::referenceable_value<local_of<string_tag_of<char16_t>>>;
66
66
 
67
67
  auto operator()(string_tag /*tag*/, visit_holder visit, auto&& subject) const
68
- -> js::referenceable_value<value_of<string_tag>> {
68
+ -> js::referenceable_value<local_of<string_tag>> {
69
69
  auto value = (*this)(string_tag_of<char16_t>{}, visit, std::u16string_view{std::forward<decltype(subject)>(subject)});
70
- return js::referenceable_value{value_of<string_tag>{*value}};
70
+ return js::referenceable_value{local_of<string_tag>{*value}};
71
71
  }
72
72
 
73
73
  template <class Char>
74
74
  auto operator()(string_tag_of<Char> tag, visit_holder visit, std::convertible_to<std::basic_string_view<Char>> auto&& subject) const
75
- -> js::referenceable_value<value_of<string_tag_of<Char>>> {
75
+ -> js::referenceable_value<local_of<string_tag_of<Char>>> {
76
76
  return (*this)(tag, visit, std::basic_string_view<Char>{std::forward<decltype(subject)>(subject)});
77
77
  }
78
78
 
79
79
  template <class Char>
80
80
  auto operator()(string_tag_of<Char> tag, visit_holder visit, auto&& subject) const
81
- -> js::referenceable_value<value_of<string_tag_of<Char>>> {
81
+ -> js::referenceable_value<local_of<string_tag_of<Char>>> {
82
82
  return (*this)(tag, visit, std::basic_string<Char>{std::forward<decltype(subject)>(subject)});
83
83
  }
84
84
 
85
85
  // bigint
86
86
  auto operator()(bigint_tag_of<std::int64_t> tag, visit_holder visit, std::int64_t subject) const
87
- -> js::referenceable_value<value_of<bigint_tag_of<std::int64_t>>>;
87
+ -> js::referenceable_value<local_of<bigint_tag_of<std::int64_t>>>;
88
88
  auto operator()(bigint_tag_of<std::uint64_t> tag, visit_holder visit, std::uint64_t subject) const
89
- -> js::referenceable_value<value_of<bigint_tag_of<std::uint64_t>>>;
89
+ -> js::referenceable_value<local_of<bigint_tag_of<std::uint64_t>>>;
90
90
  auto operator()(bigint_tag_of<js::bigint> tag, visit_holder visit, const js::bigint& subject) const
91
- -> js::referenceable_value<value_of<bigint_tag_of<js::bigint>>>;
91
+ -> js::referenceable_value<local_of<bigint_tag_of<js::bigint>>>;
92
92
  auto operator()(bigint_tag_of<js::bigint> tag, visit_holder visit, js::bigint&& subject) const
93
- -> js::referenceable_value<value_of<bigint_tag_of<js::bigint>>>;
93
+ -> js::referenceable_value<local_of<bigint_tag_of<js::bigint>>>;
94
94
 
95
95
  auto operator()(bigint_tag /*tag*/, visit_holder visit, auto&& subject) const
96
- -> js::referenceable_value<value_of<bigint_tag>> {
96
+ -> js::referenceable_value<local_of<bigint_tag>> {
97
97
  auto value = (*this)(bigint_tag_of<js::bigint>{}, visit, js::bigint{std::forward<decltype(subject)>(subject)});
98
- return js::referenceable_value{value_of<bigint_tag>{*value}};
98
+ return js::referenceable_value{local_of<bigint_tag>{*value}};
99
99
  }
100
100
 
101
101
  template <class Type>
102
102
  auto operator()(bigint_tag_of<Type> tag, visit_holder visit, auto&& subject) const
103
- -> js::referenceable_value<value_of<bigint_tag_of<Type>>> {
103
+ -> js::referenceable_value<local_of<bigint_tag_of<Type>>> {
104
104
  return (*this)(tag, visit, Type{std::forward<decltype(subject)>(subject)});
105
105
  }
106
106
 
107
107
  // date
108
108
  auto operator()(date_tag tag, visit_holder /*visit*/, js_clock::time_point subject) const
109
- -> js::referenceable_value<value_of<date_tag>>;
109
+ -> js::referenceable_value<local_of<date_tag>>;
110
110
 
111
111
  // error
112
112
  auto operator()(error_tag /*tag*/, visit_holder visit, const js::error_value& subject) const
113
- -> js::referenceable_value<value_of<error_tag>>;
113
+ -> js::referenceable_value<local_of<error_tag>>;
114
114
 
115
115
  auto operator()(error_tag tag, visit_holder visit, const auto& subject) const
116
- -> js::referenceable_value<value_of<error_tag>> {
116
+ -> js::referenceable_value<local_of<error_tag>> {
117
117
  return (*this)(tag, visit, js::error_value{subject});
118
118
  }
119
119
 
120
120
  // data blocks (array buffer, shared array buffer)
121
121
  auto operator()(array_buffer_tag tag, visit_holder visit, const js::array_buffer& subject) const
122
- -> js::referenceable_value<value_of<array_buffer_tag>>;
122
+ -> js::referenceable_value<local_of<array_buffer_tag>>;
123
123
  auto operator()(shared_array_buffer_tag tag, visit_holder visit, js::shared_array_buffer&& subject) const
124
- -> js::referenceable_value<value_of<shared_array_buffer_tag>>;
124
+ -> js::referenceable_value<local_of<shared_array_buffer_tag>>;
125
125
  auto operator()(shared_array_buffer_tag tag, visit_holder visit, const js::shared_array_buffer& subject) const
126
- -> js::referenceable_value<value_of<shared_array_buffer_tag>>;
126
+ -> js::referenceable_value<local_of<shared_array_buffer_tag>>;
127
127
 
128
128
  // typed arrays & data view
129
129
  template <std::convertible_to<array_buffer_view_tag> Tag>
130
130
  auto operator()(this const auto& self, Tag /*tag*/, auto& visit, auto&& subject)
131
- -> js::referenceable_value<value_of<Tag>> {
131
+ -> js::referenceable_value<local_of<Tag>> {
132
132
  auto byte_offset = subject.byte_offset();
133
133
  auto length = subject.size();
134
134
  // TODO: We accept the nested `buffer` property as a `data_block` which means `make` needs to
135
135
  // invoke `is_arraybuffer` on it again even though we knew what it was a moment ago.
136
- auto buffer = value_of<data_block_tag>::from(visit(std::forward<decltype(subject)>(subject).buffer(), self));
137
- return js::referenceable_value{value_of<Tag>::make(self.environment(), buffer, byte_offset, length)};
136
+ auto buffer = local_of<data_block_tag>::from(visit(std::forward<decltype(subject)>(subject).buffer(), self));
137
+ return js::referenceable_value{local_of<Tag>::make(self.environment(), buffer, byte_offset, length)};
138
138
  }
139
139
 
140
140
  // extras
@@ -161,18 +161,18 @@ struct accept_napi_value : accept_basic_napi_value {
161
161
 
162
162
  // function
163
163
  template <class Callback>
164
- auto operator()(function_prototype_tag /*tag*/, visit_holder /*visit*/, js::free_function<Callback> subject) const -> value_of<function_tag> {
165
- return value_of<function_tag>::make(environment(), std::forward<decltype(subject)>(subject));
164
+ auto operator()(function_prototype_tag /*tag*/, visit_holder /*visit*/, js::free_function<Callback> subject) const -> local_of<function_tag> {
165
+ return local_of<function_tag>::make(environment(), std::forward<decltype(subject)>(subject));
166
166
  }
167
167
 
168
168
  // vectors
169
169
  auto operator()(this const auto& self, vector_tag /*tag*/, auto& visit, auto&& subject)
170
- -> js::deferred_receiver<value_of<vector_tag>, decltype(self), decltype(visit), decltype(subject)> {
170
+ -> js::deferred_receiver<local_of<vector_tag>, decltype(self), decltype(visit), decltype(subject)> {
171
171
  auto [... size ] = util::maybe_range_size(subject, 0);
172
172
  return {
173
- value_of<vector_tag>::from(napi::invoke(napi_create_array_with_length, napi_env{self}, size...)),
173
+ local_of<vector_tag>::from(napi::invoke(napi_create_array_with_length, napi_env{self}, size...)),
174
174
  std::forward_as_tuple(self, visit, std::forward<decltype(subject)>(subject)),
175
- [](value_of<vector_tag> array, auto& self, auto& visit, auto /*&&*/ subject) -> void {
175
+ [](local_of<vector_tag> array, auto& self, auto& visit, auto /*&&*/ subject) -> void {
176
176
  int ii = 0;
177
177
  auto&& range = util::into_range(std::forward<decltype(subject)>(subject));
178
178
  for (auto&& element : util::forward_range(std::forward<decltype(range)>(range))) {
@@ -185,11 +185,11 @@ struct accept_napi_value : accept_basic_napi_value {
185
185
 
186
186
  template <std::size_t Size>
187
187
  auto operator()(this const auto& self, tuple_tag<Size> /*tag*/, auto& visit, auto&& subject)
188
- -> js::deferred_receiver<value_of<vector_tag>, decltype(self), decltype(visit), decltype(subject)> {
188
+ -> js::deferred_receiver<local_of<vector_tag>, decltype(self), decltype(visit), decltype(subject)> {
189
189
  return {
190
- value_of<vector_tag>::from(napi::invoke(napi_create_array_with_length, napi_env{self}, Size)),
190
+ local_of<vector_tag>::from(napi::invoke(napi_create_array_with_length, napi_env{self}, Size)),
191
191
  std::forward_as_tuple(self, visit, std::forward<decltype(subject)>(subject)),
192
- [](value_of<vector_tag> array, auto& self, auto& visit, auto /*&&*/ tuple) -> void {
192
+ [](local_of<vector_tag> array, auto& self, auto& visit, auto /*&&*/ tuple) -> void {
193
193
  const auto [... indices ] = util::sequence<Size>;
194
194
  (..., [ & ]() -> void {
195
195
  // nb: This is forwarded to *each* visitor. The visitor should be aware and only lvalue
@@ -203,28 +203,28 @@ struct accept_napi_value : accept_basic_napi_value {
203
203
 
204
204
  // arrays & dictionaries
205
205
  auto operator()(this const auto& self, list_tag /*tag*/, auto& visit, auto&& subject)
206
- -> js::deferred_receiver<value_of<list_tag>, decltype(self), decltype(visit), decltype(subject)> {
206
+ -> js::deferred_receiver<local_of<list_tag>, decltype(self), decltype(visit), decltype(subject)> {
207
207
  return {
208
- value_of<list_tag>::from(napi::invoke(napi_create_array, napi_env{self})),
208
+ local_of<list_tag>::from(napi::invoke(napi_create_array, napi_env{self})),
209
209
  std::forward_as_tuple(self, visit, std::forward<decltype(subject)>(subject)),
210
- [](value_of<list_tag> array, auto& self, auto& visit, auto /*&&*/ subject) -> void {
210
+ [](local_of<list_tag> array, auto& self, auto& visit, auto /*&&*/ subject) -> void {
211
211
  self.accept_entry_pair_vector(visit, array, std::forward<decltype(subject)>(subject));
212
212
  }
213
213
  };
214
214
  }
215
215
 
216
216
  auto operator()(this const auto& self, dictionary_tag /*tag*/, auto& visit, auto&& subject)
217
- -> js::deferred_receiver<value_of<dictionary_tag>, decltype(self), decltype(visit), decltype(subject)> {
217
+ -> js::deferred_receiver<local_of<dictionary_tag>, decltype(self), decltype(visit), decltype(subject)> {
218
218
  return {
219
- value_of<dictionary_tag>::from(napi::invoke(napi_create_object, napi_env{self})),
219
+ local_of<dictionary_tag>::from(napi::invoke(napi_create_object, napi_env{self})),
220
220
  std::forward_as_tuple(self, visit, std::forward<decltype(subject)>(subject)),
221
- [](value_of<dictionary_tag> object, auto& self, auto& visit, auto /*&&*/ subject) -> void {
221
+ [](local_of<dictionary_tag> object, auto& self, auto& visit, auto /*&&*/ subject) -> void {
222
222
  self.accept_entry_pair_vector(visit, object, std::forward<decltype(subject)>(subject));
223
223
  }
224
224
  };
225
225
  }
226
226
 
227
- auto accept_entry_pair_vector(this const auto& self, auto& visit, value_of<object_tag> target, auto&& subject) -> void {
227
+ auto accept_entry_pair_vector(this const auto& self, auto& visit, local_of<object_tag> target, auto&& subject) -> void {
228
228
  std::vector<napi_property_descriptor> properties;
229
229
  auto&& range = util::into_range(std::forward<decltype(subject)>(subject));
230
230
  properties.reserve(std::size(range));
@@ -234,7 +234,7 @@ struct accept_napi_value : accept_basic_napi_value {
234
234
  .utf8name{},
235
235
  // TODO: `napi_define_properties` only works with string keys but the nested acceptor will
236
236
  // accept indexed properties as numeric napi values. `visit.first` should be invoked
237
- // against something that maybe resolves to `std::variant<int32_t, value_of<name_tag>>`.
237
+ // against something that maybe resolves to `std::variant<int32_t, local_of<name_tag>>`.
238
238
  .name = napi::invoke(napi_coerce_to_string, napi_env{self}, name),
239
239
 
240
240
  .method{},
@@ -253,18 +253,18 @@ struct accept_napi_value : accept_basic_napi_value {
253
253
  // structs
254
254
  template <std::size_t Size>
255
255
  auto operator()(this const auto& self, struct_tag<Size> /*tag*/, auto& visit, auto&& subject)
256
- -> js::deferred_receiver<value_of<dictionary_tag>, decltype(self), decltype(visit), decltype(subject)> {
256
+ -> js::deferred_receiver<local_of<dictionary_tag>, decltype(self), decltype(visit), decltype(subject)> {
257
257
  return {
258
- value_of<dictionary_tag>::from(napi::invoke(napi_create_object, napi_env{self})),
258
+ local_of<dictionary_tag>::from(napi::invoke(napi_create_object, napi_env{self})),
259
259
  std::forward_as_tuple(self, visit, std::forward<decltype(subject)>(subject)),
260
- [](value_of<dictionary_tag> object, auto& self, auto& visit, auto /*&&*/ subject) -> void {
260
+ [](local_of<dictionary_tag> object, auto& self, auto& visit, auto /*&&*/ subject) -> void {
261
261
  self.template accept_entry_pair_struct<Size>(visit, object, std::forward<decltype(subject)>(subject));
262
262
  }
263
263
  };
264
264
  }
265
265
 
266
266
  template <std::size_t Size>
267
- auto accept_entry_pair_struct(this const auto& self, auto& visit, value_of<object_tag> target, auto&& subject) -> void {
267
+ auto accept_entry_pair_struct(this const auto& self, auto& visit, local_of<object_tag> target, auto&& subject) -> void {
268
268
  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
269
269
  std::array<napi_property_descriptor, Size> properties;
270
270
  const auto [... indices ] = util::sequence<Size>;
@@ -299,18 +299,32 @@ struct accept_napi_value : accept_basic_napi_value {
299
299
  consteval static auto types(auto /*recursive*/) { return util::type_pack{}; }
300
300
  };
301
301
 
302
- // `value_of<object_tag>{}.assign(...)` implementation
302
+ // Forward `value_of<T>`
303
+ template <class Tag>
304
+ struct accept_napi_value_of {
305
+ public:
306
+ explicit accept_napi_value_of(auto* /*transfer*/) {}
307
+
308
+ auto operator()(Tag /*tag*/, visit_holder /*visit*/, value_of<Tag> subject) const -> value_of<Tag> {
309
+ return subject;
310
+ }
311
+
312
+ consteval static auto accept_tags_of() { return std::tuple{Tag{}}; }
313
+ consteval static auto types(auto /*recursive*/) { return util::type_pack{}; }
314
+ };
315
+
316
+ // `local_of<object_tag>{}->assign(...)` implementation
303
317
  struct object_assign_delegate {
304
318
  public:
305
- explicit object_assign_delegate(value_of<object_tag> object) : object_{object} {}
319
+ explicit object_assign_delegate(local_of<object_tag> object) : object_{object} {}
306
320
  auto operator*() const { return object_; }
307
321
 
308
322
  private:
309
- value_of<object_tag> object_;
323
+ local_of<object_tag> object_;
310
324
  };
311
325
 
312
- auto value_for_object::assign(this value_of<object_tag> self, auto_environment auto& env, auto source) -> void {
313
- js::transfer_in<object_assign_delegate>(std::move(source), env, object_assign_delegate{self});
326
+ auto local_for_object::assign(auto_environment auto& env, auto source) const -> void {
327
+ js::transfer_in<object_assign_delegate>(std::move(source), env, object_assign_delegate{local_of{*this}});
314
328
  }
315
329
 
316
330
  } // namespace js::napi
@@ -327,24 +341,20 @@ struct accept<Meta, napi_value> : napi::accept_napi_value_with<Meta> {
327
341
  using accept_type::accept_type;
328
342
  };
329
343
 
330
- // Tagged `value_of<T>` acceptor
344
+ // Tagged `local_of<T>` acceptor
331
345
  template <>
332
- struct accept_property_subject<napi::value_of<value_tag>> : std::type_identity<napi_value> {};
346
+ struct accept_property_subject<napi::local_of<value_tag>> : std::type_identity<napi_value> {};
333
347
 
334
348
  template <class Meta, class Tag>
335
- struct accept<Meta, napi::value_of<Tag>> : napi::accept_napi_value_with<Meta> {
349
+ struct accept<Meta, napi::local_of<Tag>> : napi::accept_napi_value_with<Meta> {
336
350
  using accept_type = napi::accept_napi_value_with<Meta>;
337
351
  using accept_type::accept_type;
338
352
  };
339
353
 
340
- // Forwarded `value_of<T>` acceptor
341
- template <class Tag>
342
- struct accept<void, js::forward<napi::value_of<Tag>, Tag>> {
343
- auto operator()(Tag /*tag*/, visit_holder /*visit*/, napi::value_of<Tag> subject) const -> js::forward<napi::value_of<Tag>, Tag> {
344
- return js::forward{napi::value_of<Tag>{subject}, Tag{}};
345
- }
346
-
347
- consteval static auto types(auto /*recursive*/) { return util::type_pack{}; }
354
+ // Forward `value_of<T>`
355
+ template <class Meta, class Tag>
356
+ struct accept<Meta, napi::value_of<Tag>> : napi::accept_napi_value_of<Tag> {
357
+ using napi::accept_napi_value_of<Tag>::accept_napi_value_of;
348
358
  };
349
359
 
350
360
  // Object key lookup via napi