@auto_js/napi 0.0.8 → 0.0.10

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.
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@auto_js/napi",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "author": "https://github.com/laverdet/",
5
5
  "description": "Automatic JavaScript to N-API bindings",
6
6
  "homepage": "https://github.com/laverdet/isolated-vm/tree/experimental/packages/auto_js/napi",
7
7
  "license": "ISC",
8
8
  "dependencies": {
9
- "@auto_js/js": "^0.0.8",
10
- "@auto_js/napi_exports": "^0.0.8",
11
- "@auto_js/v8_exports": "^0.0.6"
9
+ "@auto_js/js": "^0.0.10",
10
+ "@auto_js/v8_exports": "^0.0.8",
11
+ "@auto_js/napi_exports": "^0.0.10"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
@@ -13,7 +13,7 @@ template <class Type>
13
13
  constexpr auto unwrap_member_this = [](auto_environment auto& env, napi_value this_arg) noexcept -> std::optional<tagged_external<Type>> {
14
14
  return napi::invoke_maybe(napi_coerce_to_object, napi_env{env}, this_arg)
15
15
  .and_then([ &env ](napi_value coerced_this_arg) -> std::optional<tagged_external<Type>> {
16
- auto as_object = bound_value{env, value_of<object_tag>::from(coerced_this_arg)};
16
+ auto as_object = value_of{env, local_of<object_tag>::from(coerced_this_arg)};
17
17
  // Technically `try_cast` can throw but it should only be in catastrophic cases.
18
18
  Type* unwrapped = as_object.try_cast(type<Type>);
19
19
  if (unwrapped == nullptr) {
@@ -40,8 +40,8 @@ constexpr auto make_free_function(auto function) {
40
40
  using callback_type = decltype(callback);
41
41
  return util::bind{
42
42
  [](callback_type& callback, Environment& env, const callback_info& info) noexcept(Nx) -> napi_value {
43
- return invoke_internal_error_scope(env, [ & ]() -> napi_value {
44
- auto run = util::regular_return{[ & ]() -> decltype(auto) {
43
+ return invoke_internal_error_scope(env, [ & ] -> napi_value {
44
+ auto run = util::regular_return{[ & ] -> decltype(auto) {
45
45
  return std::apply(
46
46
  callback,
47
47
  std::tuple_cat(
@@ -65,7 +65,7 @@ constexpr auto make_free_function(auto function) {
65
65
  using callback_type = decltype(callback);
66
66
  return util::bind{
67
67
  [](callback_type& callback, Environment& env, const callback_info& /*info*/) noexcept -> napi_value {
68
- auto run = util::regular_return{[ & ]() -> decltype(auto) {
68
+ auto run = util::regular_return{[ & ] -> decltype(auto) {
69
69
  return callback(env);
70
70
  }};
71
71
  return js::transfer_in_strict<napi_value>(run().value_or(std::monostate{}), env);
@@ -112,11 +112,11 @@ constexpr auto make_constructor_function(auto constructor) {
112
112
  using callback_type = decltype(callback);
113
113
  return util::bind{
114
114
  [](callback_type& callback, wrap_type& wrap, Environment& env, const callback_info& info) noexcept(Nx) -> napi_value {
115
- return invoke_internal_error_scope(env, [ & ]() -> napi_value {
115
+ return invoke_internal_error_scope(env, [ & ] -> napi_value {
116
116
  auto instance = std::apply(
117
117
  callback,
118
118
  std::tuple_cat(
119
- std::forward_as_tuple(env, value_of<object_tag>::from(info.this_arg())),
119
+ std::forward_as_tuple(env, local_of<object_tag>::from(info.this_arg())),
120
120
  js::transfer_out<std::tuple<js::functional::parameter_transfer_as_t<Args>...>>(info.arguments(), env)
121
121
  )
122
122
  );
@@ -136,7 +136,7 @@ constexpr auto make_constructor_function(auto constructor) {
136
136
  using callback_type = decltype(callback);
137
137
  return util::bind{
138
138
  [](callback_type& callback, Environment& env, const callback_info& info) noexcept -> napi_value {
139
- return wrap(callback(env, value_of<object_tag>::from(info.this_arg())));
139
+ return wrap(callback(env, local_of<object_tag>::from(info.this_arg())));
140
140
  },
141
141
  std::move(callback),
142
142
  };
@@ -159,7 +159,7 @@ constexpr auto make_constructor_function(auto constructor) {
159
159
  [](runtime_constructor_type& constructor, Environment& env, const callback_info& info) -> napi_value {
160
160
  auto arguments = info.arguments();
161
161
  if (!arguments.empty()) {
162
- auto maybe_constructor = [ & ]() -> std::optional<internal_constructor*> {
162
+ auto maybe_constructor = [ & ] -> std::optional<internal_constructor*> {
163
163
  try {
164
164
  // Check truthiness since null or undefined causes `napi_coerce_to_object` to throw
165
165
  auto* arg0 = util::at(arguments, 0);
@@ -181,7 +181,7 @@ constexpr auto make_constructor_function(auto constructor) {
181
181
  }
182
182
  if (*maybe_constructor != nullptr) {
183
183
  const auto& constructor = **maybe_constructor;
184
- return invoke_internal_error_scope(env, [ & ]() -> napi_value {
184
+ return invoke_internal_error_scope(env, [ & ] -> napi_value {
185
185
  return constructor(info.this_arg());
186
186
  });
187
187
  }
@@ -208,8 +208,8 @@ constexpr auto make_member_function(Method method) {
208
208
  if (!maybe_that) {
209
209
  return nullptr;
210
210
  }
211
- return invoke_internal_error_scope(env, [ & ]() -> napi_value {
212
- auto run = util::regular_return{[ & ]() -> decltype(auto) {
211
+ return invoke_internal_error_scope(env, [ & ] -> napi_value {
212
+ auto run = util::regular_return{[ & ] -> decltype(auto) {
213
213
  return std::apply(
214
214
  callback,
215
215
  std::tuple_cat(
@@ -237,7 +237,7 @@ constexpr auto make_member_function(Method method) {
237
237
  if (!maybe_that) {
238
238
  return nullptr;
239
239
  }
240
- auto run = util::regular_return{[ & ]() -> decltype(auto) {
240
+ auto run = util::regular_return{[ & ] -> decltype(auto) {
241
241
  return callback(**maybe_that, env);
242
242
  }};
243
243
  return js::transfer_in_strict<napi_value>(run().value_or(std::monostate{}), env);
@@ -35,12 +35,12 @@ auto make_callback_storage(Environment& env, std::invocable<Environment&, const
35
35
  // Trivial function type containing less than or equal to a pointer size. `data` is the
36
36
  // function and environment is stored in a thread local.
37
37
  callback_env_local<Environment> = &env;
38
- auto* data = reinterpret_cast<void*&>(function);
38
+ auto* data = util::bit_padding_cast<void*>(function);
39
39
  const auto callback = napi_callback{[](napi_env nenv, napi_callback_info info) -> napi_value {
40
40
  const auto args = callback_info{nenv, info};
41
41
  if (args) {
42
42
  auto* data = args.data();
43
- auto& invoke = reinterpret_cast<function_type&>(data);
43
+ auto invoke = util::bit_truncation_cast<function_type>(data);
44
44
  auto& env = *callback_env_local<Environment>;
45
45
  return invoke(env, args);
46
46
  } else {
@@ -10,7 +10,7 @@ namespace js::napi {
10
10
  // Given a pack of strings it returns a static reference to a `util::sealed_map` of napi object
11
11
  // references.
12
12
  template <const auto& Strings>
13
- constexpr auto class_template_references_of = []() -> auto {
13
+ constexpr auto class_template_references_of = [] consteval -> auto {
14
14
  const auto [... strings ] = Strings;
15
15
  return util::sealed_map{std::type_identity<napi::reference<class_tag>>{}, strings...};
16
16
  }();
@@ -20,7 +20,7 @@ export template <const auto& Strings>
20
20
  class class_template_references {
21
21
  public:
22
22
  template <class Type>
23
- auto class_template(this auto& self, std::type_identity<Type> /*type*/, const auto& class_template) -> value_of<class_tag_of<Type>> {
23
+ auto class_template(this auto& self, std::type_identity<Type> /*type*/, const auto& class_template) -> local_of<class_tag_of<Type>> {
24
24
  constexpr auto name_sv = util::make_consteval_string_view(class_template.constructor.name);
25
25
  constexpr auto index = class_template_references_of<Strings>.lookup(name_sv);
26
26
  if constexpr (!index) {
@@ -33,7 +33,7 @@ class class_template_references {
33
33
  static_assert(index, "Class template '"s + name_sv + "' is missing in storage"s);
34
34
  }
35
35
  auto& reference = self.class_template_references_.at(index).second;
36
- using value_type = js::napi::value_of<class_tag_of<Type>>;
36
+ using value_type = js::napi::local_of<class_tag_of<Type>>;
37
37
  if (reference) {
38
38
  return value_type::from(reference.get(self));
39
39
  } else {
package/support/host.cc CHANGED
@@ -70,15 +70,15 @@ auto fast_is_string(napi_value value) -> bool {
70
70
  }
71
71
 
72
72
  // Bug fixes
73
- auto napi_is_object_array_buffer(napi_env env, value_of<object_tag> value) -> bool {
73
+ auto napi_is_object_array_buffer(napi_env env, local_of<object_tag> value) -> bool {
74
74
  return napi::invoke(napi_is_arraybuffer, env, value);
75
75
  }
76
76
 
77
- auto napi_is_data_block_array_buffer(napi_env env, value_of<data_block_tag> value) -> bool {
77
+ auto napi_is_data_block_array_buffer(napi_env env, local_of<data_block_tag> value) -> bool {
78
78
  return napi_is_object_array_buffer(env, value);
79
79
  }
80
80
 
81
- auto bun_is_data_block_array_buffer(napi_env env, value_of<data_block_tag> value) -> bool {
81
+ auto bun_is_data_block_array_buffer(napi_env env, local_of<data_block_tag> value) -> bool {
82
82
  // https://github.com/oven-sh/bun/issues/32624
83
83
  auto* string = napi::invoke(napi_coerce_to_string, env, value);
84
84
  auto length = napi::invoke(napi_get_value_string_latin1, env, string, nullptr, 0);
@@ -86,30 +86,34 @@ auto bun_is_data_block_array_buffer(napi_env env, value_of<data_block_tag> value
86
86
  return length == 20;
87
87
  }
88
88
 
89
- auto bun_is_object_array_buffer(napi_env env, value_of<object_tag> value) -> bool {
89
+ auto bun_is_object_array_buffer(napi_env env, local_of<object_tag> value) -> bool {
90
90
  if (napi::invoke(napi_is_arraybuffer, env, value)) {
91
- return bun_is_data_block_array_buffer(env, value_of<data_block_tag>::from(value));
91
+ return bun_is_data_block_array_buffer(env, local_of<data_block_tag>::from(value));
92
92
  } else {
93
93
  return false;
94
94
  }
95
95
  }
96
96
 
97
97
  // Optional value inspectors.
98
- auto v8_is_number_int32(value_of<number_tag> value) -> std::optional<bool> {
98
+ auto v8_is_number_int32(local_of<number_tag> value) -> std::optional<bool> {
99
99
  return std::bit_cast<v8::Local<v8::Number>>(value)->IsInt32();
100
100
  };
101
101
 
102
- auto v8_is_string_one_byte(value_of<string_tag> value) -> std::optional<bool> {
102
+ auto v8_is_string_one_byte(local_of<string_tag> value) -> std::optional<bool> {
103
103
  return std::bit_cast<v8::Local<v8::String>>(value)->IsOneByte();
104
104
  }
105
105
 
106
- auto node_api_maybe_is_shared_array_buffer(napi_env env, value_of<object_tag> value) -> std::optional<bool> {
107
- return napi::invoke(node_api_is_sharedarraybuffer, env, value);
106
+ auto node_api_maybe_is_shared_array_buffer(napi_env env, local_of<object_tag> value) -> std::optional<bool> {
107
+ if constexpr (node_api_has_sharedarraybuffer) {
108
+ return napi::invoke(node_api_is_sharedarraybuffer, env, value);
109
+ } else {
110
+ return std::nullopt;
111
+ }
108
112
  }
109
113
 
110
- auto bun_maybe_is_shared_array_buffer(napi_env env, value_of<object_tag> value) -> std::optional<bool> {
114
+ auto bun_maybe_is_shared_array_buffer(napi_env env, local_of<object_tag> value) -> std::optional<bool> {
111
115
  if (napi::invoke(napi_is_arraybuffer, env, value)) {
112
- return !bun_is_data_block_array_buffer(env, value_of<data_block_tag>::from(value));
116
+ return !bun_is_data_block_array_buffer(env, local_of<data_block_tag>::from(value));
113
117
  } else {
114
118
  return std::nullopt;
115
119
  }
@@ -118,8 +122,8 @@ auto bun_maybe_is_shared_array_buffer(napi_env env, value_of<object_tag> value)
118
122
  constexpr auto unknown_maybe_is = [](auto...) -> std::optional<bool> { return std::nullopt; };
119
123
 
120
124
  // 'SharedArrayBuffer' functions
121
- auto v8_make_shared_array_buffer(js::shared_array_buffer::shared_pointer_type data, std::size_t byte_length) -> value_of<shared_array_buffer_tag> {
122
- auto backing_store = [ & ]() -> auto {
125
+ auto v8_make_shared_array_buffer(js::shared_array_buffer::shared_pointer_type data, std::size_t byte_length) -> local_of<shared_array_buffer_tag> {
126
+ auto backing_store = [ & ] -> auto {
123
127
  // v8 does not call the deleter `byte_length` is zero. So the heap-allocated shared_ptr trick
124
128
  // does not work in that case.
125
129
  if (byte_length == 0) {
@@ -139,14 +143,14 @@ auto v8_make_shared_array_buffer(js::shared_array_buffer::shared_pointer_type da
139
143
  }
140
144
  }();
141
145
  auto shared_array_buffer = v8::SharedArrayBuffer::New(v8::Isolate::GetCurrent(), std::move(backing_store));
142
- return value_of<shared_array_buffer_tag>::from(std::bit_cast<napi_value>(shared_array_buffer));
146
+ return local_of<shared_array_buffer_tag>::from(std::bit_cast<napi_value>(shared_array_buffer));
143
147
  };
144
148
 
145
- auto v8_shared_array_buffer_get_byte_length(value_of<shared_array_buffer_tag> buffer) -> std::size_t {
149
+ auto v8_shared_array_buffer_get_byte_length(local_of<shared_array_buffer_tag> buffer) -> std::size_t {
146
150
  return std::bit_cast<v8::Local<v8::SharedArrayBuffer>>(napi_value{buffer})->ByteLength();
147
151
  };
148
152
 
149
- auto v8_shared_array_buffer_get_backing_store(value_of<shared_array_buffer_tag> buffer) -> std::shared_ptr<std::byte[]> {
153
+ auto v8_shared_array_buffer_get_backing_store(local_of<shared_array_buffer_tag> buffer) -> std::shared_ptr<std::byte[]> {
150
154
  auto backing_store = std::bit_cast<v8::Local<v8::SharedArrayBuffer>>(buffer)->GetBackingStore();
151
155
  auto* data = reinterpret_cast<std::byte*>(backing_store->Data());
152
156
  // NOLINTNEXTLINE(modernize-avoid-c-arrays)
@@ -155,15 +159,15 @@ auto v8_shared_array_buffer_get_backing_store(value_of<shared_array_buffer_tag>
155
159
 
156
160
  // 'ArrayBufferView' constructors
157
161
  // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
158
- auto v8_make_sab_data_view(value_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<data_view_tag> {
162
+ auto v8_make_sab_data_view(local_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<data_view_tag> {
159
163
  auto buffer_local = std::bit_cast<v8::Local<v8::SharedArrayBuffer>>(napi_value{buffer});
160
164
  auto view_local = v8::DataView::New(buffer_local, byte_offset, length);
161
- return value_of<data_view_tag>::from(std::bit_cast<napi_value>(view_local));
165
+ return local_of<data_view_tag>::from(std::bit_cast<napi_value>(view_local));
162
166
  };
163
167
 
164
168
  template <class Type>
165
169
  // NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
166
- auto v8_make_sab_typed_array_of(value_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<typed_array_tag_of<Type>> {
170
+ auto v8_make_sab_typed_array_of(local_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<typed_array_tag_of<Type>> {
167
171
  using constructor_type = type_t<util::overloaded{
168
172
  [](std::type_identity<double>) -> std::type_identity<v8::Float64Array> { return {}; },
169
173
  [](std::type_identity<float>) -> std::type_identity<v8::Float32Array> { return {}; },
@@ -180,7 +184,7 @@ auto v8_make_sab_typed_array_of(value_of<shared_array_buffer_tag> buffer, std::s
180
184
  }(type<Type>)>;
181
185
  auto buffer_local = std::bit_cast<v8::Local<v8::SharedArrayBuffer>>(napi_value{buffer});
182
186
  auto view_local = constructor_type::New(buffer_local, byte_offset, length);
183
- return value_of<typed_array_tag_of<Type>>::from(std::bit_cast<napi_value>(view_local));
187
+ return local_of<typed_array_tag_of<Type>>::from(std::bit_cast<napi_value>(view_local));
184
188
  };
185
189
 
186
190
  template <class Type>
@@ -229,7 +233,7 @@ auto initialize_host_environment(napi_env env) -> void {
229
233
  }
230
234
 
231
235
  // Get `globalThis.process`
232
- auto* process_global = [ & ]() -> napi_value {
236
+ auto* process_global = [ & ] -> napi_value {
233
237
  auto* global = napi::invoke(napi_get_global, env);
234
238
  constexpr auto process_cw = util::make_consteval_string_view(util::cw<"process">);
235
239
  auto* process_str = napi::invoke(node_api_create_property_key_latin1, env, process_cw.data(), process_cw.length());
@@ -242,7 +246,7 @@ auto initialize_host_environment(napi_env env) -> void {
242
246
  }();
243
247
 
244
248
  // Detect bun via `process.isBun`
245
- auto is_bun = process_global == nullptr ? false : [ & ]() -> bool {
249
+ auto is_bun = process_global == nullptr ? false : [ & ] -> bool {
246
250
  constexpr auto is_bun_cw = util::make_consteval_string_view(util::cw<"isBun">);
247
251
  auto* is_bun_str = napi::invoke(node_api_create_property_key_latin1, env, is_bun_cw.data(), is_bun_cw.length());
248
252
  auto* is_bun = napi::invoke(napi_get_property, env, process_global, is_bun_str);
@@ -251,7 +255,7 @@ auto initialize_host_environment(napi_env env) -> void {
251
255
  }();
252
256
 
253
257
  // Detect deno via `process.versions.deno`
254
- auto is_deno = process_global == nullptr ? false : [ & ]() -> bool {
258
+ auto is_deno = process_global == nullptr ? false : [ & ] -> bool {
255
259
  constexpr auto versions_cw = util::make_consteval_string_view(util::cw<"versions">);
256
260
  auto* versions_str = napi::invoke(node_api_create_property_key_latin1, env, versions_cw.data(), versions_cw.length());
257
261
  auto* versions = napi::invoke(napi_get_property, env, process_global, versions_str);
@@ -302,20 +306,20 @@ auto initialize_host_environment(napi_env env) -> void {
302
306
  host_uv_dlclose = unknown_uv_dlclose;
303
307
  host_uv_dlerror = unknown_uv_dlerror;
304
308
  host_uv_dlopen = unknown_uv_dlopen;
305
- make_sab_data_view = unknown_sab_throw<value_of<data_view_tag>>;
306
- make_sab_typed_array_of<double> = unknown_sab_throw<value_of<typed_array_tag_of<double>>>;
307
- make_sab_typed_array_of<float> = unknown_sab_throw<value_of<typed_array_tag_of<float>>>;
308
- make_sab_typed_array_of<js::float16_t> = unknown_sab_throw<value_of<typed_array_tag_of<js::float16_t>>>;
309
- make_sab_typed_array_of<js::uint8_clamped_t> = unknown_sab_throw<value_of<typed_array_tag_of<js::uint8_clamped_t>>>;
310
- make_sab_typed_array_of<std::int16_t> = unknown_sab_throw<value_of<typed_array_tag_of<std::int16_t>>>;
311
- make_sab_typed_array_of<std::int32_t> = unknown_sab_throw<value_of<typed_array_tag_of<std::int32_t>>>;
312
- make_sab_typed_array_of<std::int64_t> = unknown_sab_throw<value_of<typed_array_tag_of<std::int64_t>>>;
313
- make_sab_typed_array_of<std::int8_t> = unknown_sab_throw<value_of<typed_array_tag_of<std::int8_t>>>;
314
- make_sab_typed_array_of<std::uint16_t> = unknown_sab_throw<value_of<typed_array_tag_of<std::uint16_t>>>;
315
- make_sab_typed_array_of<std::uint32_t> = unknown_sab_throw<value_of<typed_array_tag_of<std::uint32_t>>>;
316
- make_sab_typed_array_of<std::uint64_t> = unknown_sab_throw<value_of<typed_array_tag_of<std::uint64_t>>>;
317
- make_sab_typed_array_of<std::uint8_t> = unknown_sab_throw<value_of<typed_array_tag_of<std::uint8_t>>>;
318
- make_shared_array_buffer = unknown_sab_throw<value_of<shared_array_buffer_tag>>;
309
+ make_sab_data_view = unknown_sab_throw<local_of<data_view_tag>>;
310
+ make_sab_typed_array_of<double> = unknown_sab_throw<local_of<typed_array_tag_of<double>>>;
311
+ make_sab_typed_array_of<float> = unknown_sab_throw<local_of<typed_array_tag_of<float>>>;
312
+ make_sab_typed_array_of<js::float16_t> = unknown_sab_throw<local_of<typed_array_tag_of<js::float16_t>>>;
313
+ make_sab_typed_array_of<js::uint8_clamped_t> = unknown_sab_throw<local_of<typed_array_tag_of<js::uint8_clamped_t>>>;
314
+ make_sab_typed_array_of<std::int16_t> = unknown_sab_throw<local_of<typed_array_tag_of<std::int16_t>>>;
315
+ make_sab_typed_array_of<std::int32_t> = unknown_sab_throw<local_of<typed_array_tag_of<std::int32_t>>>;
316
+ make_sab_typed_array_of<std::int64_t> = unknown_sab_throw<local_of<typed_array_tag_of<std::int64_t>>>;
317
+ make_sab_typed_array_of<std::int8_t> = unknown_sab_throw<local_of<typed_array_tag_of<std::int8_t>>>;
318
+ make_sab_typed_array_of<std::uint16_t> = unknown_sab_throw<local_of<typed_array_tag_of<std::uint16_t>>>;
319
+ make_sab_typed_array_of<std::uint32_t> = unknown_sab_throw<local_of<typed_array_tag_of<std::uint32_t>>>;
320
+ make_sab_typed_array_of<std::uint64_t> = unknown_sab_throw<local_of<typed_array_tag_of<std::uint64_t>>>;
321
+ make_sab_typed_array_of<std::uint8_t> = unknown_sab_throw<local_of<typed_array_tag_of<std::uint8_t>>>;
322
+ make_shared_array_buffer = unknown_sab_throw<local_of<shared_array_buffer_tag>>;
319
323
  maybe_is_number_int32 = unknown_maybe_is;
320
324
  maybe_is_shared_array_buffer = unknown_maybe_is;
321
325
  maybe_is_string_latin1 = unknown_maybe_is;
package/support/host.h.cc CHANGED
@@ -1,5 +1,5 @@
1
1
  export module napi_js:support.host;
2
- import :value_handle;
2
+ import :handle.local_of;
3
3
  import std;
4
4
 
5
5
  namespace js::napi {
@@ -23,27 +23,27 @@ auto fast_is_object(napi_value value) -> bool;
23
23
  auto fast_is_string(napi_value value) -> bool;
24
24
 
25
25
  // Bug fixes
26
- auto (*is_object_array_buffer)(napi_env env, value_of<object_tag> value) -> bool = nullptr;
27
- auto (*is_data_block_array_buffer)(napi_env env, value_of<data_block_tag> value) -> bool = nullptr;
26
+ auto (*is_object_array_buffer)(napi_env env, local_of<object_tag> value) -> bool = nullptr;
27
+ auto (*is_data_block_array_buffer)(napi_env env, local_of<data_block_tag> value) -> bool = nullptr;
28
28
 
29
29
  // Optional value inspectors. int32 & latin1 will select optimized representations, and
30
30
  // shared_array_buffer is required for support of that value type.
31
- auto (*maybe_is_number_int32)(value_of<number_tag> value) -> std::optional<bool> = nullptr;
32
- auto (*maybe_is_string_latin1)(value_of<string_tag> value) -> std::optional<bool> = nullptr;
33
- auto (*maybe_is_shared_array_buffer)(napi_env env, value_of<object_tag> value) -> std::optional<bool> = nullptr;
31
+ auto (*maybe_is_number_int32)(local_of<number_tag> value) -> std::optional<bool> = nullptr;
32
+ auto (*maybe_is_string_latin1)(local_of<string_tag> value) -> std::optional<bool> = nullptr;
33
+ auto (*maybe_is_shared_array_buffer)(napi_env env, local_of<object_tag> value) -> std::optional<bool> = nullptr;
34
34
 
35
35
  // 'SharedArrayBuffer' functions
36
- auto (*make_shared_array_buffer)(js::shared_array_buffer::shared_pointer_type data, std::size_t byte_length) -> value_of<shared_array_buffer_tag> = nullptr;
37
- auto (*shared_array_buffer_get_byte_length)(value_of<shared_array_buffer_tag> buffer) -> std::size_t = nullptr;
36
+ auto (*make_shared_array_buffer)(js::shared_array_buffer::shared_pointer_type data, std::size_t byte_length) -> local_of<shared_array_buffer_tag> = nullptr;
37
+ auto (*shared_array_buffer_get_byte_length)(local_of<shared_array_buffer_tag> buffer) -> std::size_t = nullptr;
38
38
  // NOLINTNEXTLINE(modernize-avoid-c-arrays)
39
- auto (*shared_array_buffer_get_backing_store)(value_of<shared_array_buffer_tag> buffer) -> std::shared_ptr<std::byte[]> = nullptr;
39
+ auto (*shared_array_buffer_get_backing_store)(local_of<shared_array_buffer_tag> buffer) -> std::shared_ptr<std::byte[]> = nullptr;
40
40
 
41
41
  // 'ArrayBufferView' constructors
42
- auto (*make_sab_data_view)(value_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<data_view_tag> = nullptr;
42
+ auto (*make_sab_data_view)(local_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<data_view_tag> = nullptr;
43
43
 
44
44
  template <class Type>
45
45
  using make_sab_typed_array_constructor =
46
- auto(value_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<typed_array_tag_of<Type>>;
46
+ auto(local_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<typed_array_tag_of<Type>>;
47
47
 
48
48
  template <class Type>
49
49
  make_sab_typed_array_constructor<Type>* make_sab_typed_array_of;
@@ -31,11 +31,11 @@ class napi_js_module final : private detail::initialize_require {
31
31
  private:
32
32
  auto operator()(napi_env env, napi_value exports) -> void override {
33
33
  // construct environment, set napi instance data w/ finalizer
34
- const auto [... indices ] = util::sequence<sizeof...(Args)>;
34
+ constexpr auto [... indices ] = util::sequence<sizeof...(Args)>;
35
35
  auto& client_environment = environment::make_and_set_environment<Environment>(env, std::get<indices>(std::move(args_))...);
36
36
  // assign export descriptor to napi-constructor namespace object
37
- auto exports_local = value_of<dictionary_tag>::from(exports);
38
- exports_local.assign(client_environment, std::move(make_exports_)(client_environment));
37
+ auto exports_local = local_of<dictionary_tag>::from(exports);
38
+ exports_local->assign(client_environment, std::move(make_exports_)(client_environment));
39
39
  }
40
40
 
41
41
  Make make_exports_;
@@ -19,7 +19,7 @@ class resolver {
19
19
  resolver(resolver&&) = default;
20
20
  ~resolver() {
21
21
  if (scheduler_) {
22
- resolve(std::monostate{});
22
+ resolve(nullptr);
23
23
  }
24
24
  }
25
25
 
@@ -117,7 +117,7 @@ auto make_promise(Environment& env, auto... dispatch) {
117
117
  auto resolve = resolver{env, deferred, std::move(dispatch)...};
118
118
 
119
119
  // `[ promise, resolver ]`
120
- return std::tuple{value_of<promise_tag>::from(promise), std::move(resolve)};
120
+ return std::tuple{local_of<promise_tag>::from(promise), std::move(resolve)};
121
121
  }
122
122
 
123
123
  } // namespace js::napi
@@ -10,7 +10,7 @@ namespace js::napi {
10
10
  // Given a pack of strings it returns a static reference to a `util::sealed_map` of napi string
11
11
  // references.
12
12
  template <const auto& Strings>
13
- constexpr auto string_table_of = []() -> auto {
13
+ constexpr auto string_table_of = [] consteval -> auto {
14
14
  const auto [... strings ] = Strings;
15
15
  return util::sealed_map{std::type_identity<napi::reference<string_tag>>{}, strings...};
16
16
  }();
@@ -4,87 +4,87 @@ import std;
4
4
  namespace js::napi {
5
5
 
6
6
  // undefined & null
7
- auto accept_basic_napi_value::operator()(undefined_tag /*tag*/, visit_holder /*visit*/, std::monostate /*subject*/) const -> value_of<undefined_tag> {
8
- return value_of<undefined_tag>::from(napi::invoke(napi_get_undefined, napi_env{*this}));
7
+ auto accept_basic_napi_value::operator()(undefined_tag /*tag*/, visit_holder /*visit*/, std::monostate /*subject*/) const -> local_of<undefined_tag> {
8
+ return local_of<undefined_tag>::from(napi::invoke(napi_get_undefined, napi_env{*this}));
9
9
  }
10
10
 
11
- auto accept_basic_napi_value::operator()(null_tag /*tag*/, visit_holder /*visit*/, std::nullptr_t /*subject*/) const -> value_of<null_tag> {
12
- return value_of<null_tag>::from(napi::invoke(napi_get_null, napi_env{*this}));
11
+ auto accept_basic_napi_value::operator()(null_tag /*tag*/, visit_holder /*visit*/, std::nullptr_t /*subject*/) const -> local_of<null_tag> {
12
+ return local_of<null_tag>::from(napi::invoke(napi_get_null, napi_env{*this}));
13
13
  }
14
14
 
15
15
  // boolean
16
- auto accept_basic_napi_value::operator()(boolean_tag /*tag*/, visit_holder /*visit*/, bool subject) const -> value_of<boolean_tag> {
17
- return value_of<boolean_tag>::from(napi::invoke(napi_get_boolean, napi_env{*this}, subject));
16
+ auto accept_basic_napi_value::operator()(boolean_tag /*tag*/, visit_holder /*visit*/, bool subject) const -> local_of<boolean_tag> {
17
+ return local_of<boolean_tag>::from(napi::invoke(napi_get_boolean, napi_env{*this}, subject));
18
18
  }
19
19
 
20
20
  // number
21
- auto accept_basic_napi_value::operator()(number_tag_of<double> /*tag*/, visit_holder /*visit*/, double subject) const -> value_of<number_tag_of<double>> {
22
- return value_of<number_tag_of<double>>::from(napi::invoke(napi_create_double, napi_env{*this}, subject));
21
+ auto accept_basic_napi_value::operator()(number_tag_of<double> /*tag*/, visit_holder /*visit*/, double subject) const -> local_of<number_tag_of<double>> {
22
+ return local_of<number_tag_of<double>>::from(napi::invoke(napi_create_double, napi_env{*this}, subject));
23
23
  }
24
24
 
25
- auto accept_basic_napi_value::operator()(number_tag_of<std::int32_t> /*tag*/, visit_holder /*visit*/, std::int32_t subject) const -> value_of<number_tag_of<std::int32_t>> {
26
- return value_of<number_tag_of<std::int32_t>>::from(napi::invoke(napi_create_int32, napi_env{*this}, subject));
25
+ auto accept_basic_napi_value::operator()(number_tag_of<std::int32_t> /*tag*/, visit_holder /*visit*/, std::int32_t subject) const -> local_of<number_tag_of<std::int32_t>> {
26
+ return local_of<number_tag_of<std::int32_t>>::from(napi::invoke(napi_create_int32, napi_env{*this}, subject));
27
27
  }
28
28
 
29
- auto accept_basic_napi_value::operator()(number_tag_of<std::uint32_t> /*tag*/, visit_holder /*visit*/, std::uint32_t subject) const -> value_of<number_tag_of<std::uint32_t>> {
30
- return value_of<number_tag_of<std::uint32_t>>::from(napi::invoke(napi_create_uint32, napi_env{*this}, subject));
29
+ auto accept_basic_napi_value::operator()(number_tag_of<std::uint32_t> /*tag*/, visit_holder /*visit*/, std::uint32_t subject) const -> local_of<number_tag_of<std::uint32_t>> {
30
+ return local_of<number_tag_of<std::uint32_t>>::from(napi::invoke(napi_create_uint32, napi_env{*this}, subject));
31
31
  }
32
32
 
33
33
  // string
34
34
  auto accept_basic_napi_value::operator()(string_tag_of<char> /*tag*/, visit_holder /*visit*/, std::string_view subject) const
35
- -> js::referenceable_value<value_of<string_tag_of<char>>> {
35
+ -> js::referenceable_value<local_of<string_tag_of<char>>> {
36
36
  auto* value = napi::invoke(napi_create_string_latin1, napi_env{*this}, subject.data(), subject.length());
37
- return js::referenceable_value{value_of<string_tag_of<char>>::from(value)};
37
+ return js::referenceable_value{local_of<string_tag_of<char>>::from(value)};
38
38
  }
39
39
 
40
40
  auto accept_basic_napi_value::operator()(string_tag_of<char8_t> /*tag*/, visit_holder /*visit*/, std::u8string_view subject) const
41
- -> js::referenceable_value<value_of<string_tag_of<char8_t>>> {
41
+ -> js::referenceable_value<local_of<string_tag_of<char8_t>>> {
42
42
  auto* value = napi::invoke(napi_create_string_utf8, napi_env{*this}, reinterpret_cast<const char*>(subject.data()), subject.length());
43
- return js::referenceable_value{value_of<string_tag_of<char8_t>>::from(value)};
43
+ return js::referenceable_value{local_of<string_tag_of<char8_t>>::from(value)};
44
44
  }
45
45
 
46
46
  auto accept_basic_napi_value::operator()(string_tag_of<char16_t> /*tag*/, visit_holder /*visit*/, std::u16string_view subject) const
47
- -> js::referenceable_value<value_of<string_tag_of<char16_t>>> {
47
+ -> js::referenceable_value<local_of<string_tag_of<char16_t>>> {
48
48
  auto* value = napi::invoke(napi_create_string_utf16, napi_env{*this}, subject.data(), subject.length());
49
- return js::referenceable_value{value_of<string_tag_of<char16_t>>::from(value)};
49
+ return js::referenceable_value{local_of<string_tag_of<char16_t>>::from(value)};
50
50
  }
51
51
 
52
52
  // bigint
53
53
  auto accept_basic_napi_value::operator()(bigint_tag_of<std::int64_t> /*tag*/, visit_holder /*visit*/, std::int64_t subject) const
54
- -> js::referenceable_value<value_of<bigint_tag_of<std::int64_t>>> {
54
+ -> js::referenceable_value<local_of<bigint_tag_of<std::int64_t>>> {
55
55
  auto* value = napi::invoke(napi_create_bigint_int64, napi_env{*this}, subject);
56
- return js::referenceable_value{value_of<bigint_tag_of<std::int64_t>>::from(value)};
56
+ return js::referenceable_value{local_of<bigint_tag_of<std::int64_t>>::from(value)};
57
57
  }
58
58
 
59
59
  auto accept_basic_napi_value::operator()(bigint_tag_of<std::uint64_t> /*tag*/, visit_holder /*visit*/, std::uint64_t subject) const
60
- -> js::referenceable_value<value_of<bigint_tag_of<std::uint64_t>>> {
60
+ -> js::referenceable_value<local_of<bigint_tag_of<std::uint64_t>>> {
61
61
  auto* value = napi::invoke(napi_create_bigint_uint64, napi_env{*this}, subject);
62
- return js::referenceable_value{value_of<bigint_tag_of<std::uint64_t>>::from(value)};
62
+ return js::referenceable_value{local_of<bigint_tag_of<std::uint64_t>>::from(value)};
63
63
  }
64
64
 
65
65
  auto accept_basic_napi_value::operator()(bigint_tag_of<js::bigint> /*tag*/, visit_holder /*visit*/, const js::bigint& subject) const
66
- -> js::referenceable_value<value_of<bigint_tag_of<js::bigint>>> {
66
+ -> js::referenceable_value<local_of<bigint_tag_of<js::bigint>>> {
67
67
  auto* value = napi::invoke(napi_create_bigint_words, napi_env{*this}, subject.sign_bit(), subject.size(), subject.data());
68
- return js::referenceable_value{value_of<bigint_tag_of<js::bigint>>::from(value)};
68
+ return js::referenceable_value{local_of<bigint_tag_of<js::bigint>>::from(value)};
69
69
  }
70
70
 
71
71
  // NOLINTNEXTLINE(cppcoreguidelines-rvalue-reference-param-not-moved)
72
72
  auto accept_basic_napi_value::operator()(bigint_tag_of<js::bigint> tag, visit_holder visit, js::bigint&& subject) const
73
- -> js::referenceable_value<value_of<bigint_tag_of<js::bigint>>> {
73
+ -> js::referenceable_value<local_of<bigint_tag_of<js::bigint>>> {
74
74
  return (*this)(tag, visit, static_cast<const js::bigint&>(subject));
75
75
  }
76
76
 
77
77
  // date
78
78
  auto accept_basic_napi_value::operator()(date_tag /*tag*/, visit_holder /*visit*/, js_clock::time_point subject) const
79
- -> js::referenceable_value<value_of<date_tag>> {
80
- auto value = value_of<date_tag>::from(napi::invoke(napi_create_date, napi_env{*this}, subject.time_since_epoch().count()));
79
+ -> js::referenceable_value<local_of<date_tag>> {
80
+ auto value = local_of<date_tag>::from(napi::invoke(napi_create_date, napi_env{*this}, subject.time_since_epoch().count()));
81
81
  return js::referenceable_value{value};
82
82
  }
83
83
 
84
84
  // error
85
85
  auto accept_basic_napi_value::operator()(error_tag /*tag*/, visit_holder visit, const js::error_value& subject) const
86
- -> js::referenceable_value<value_of<error_tag>> {
87
- auto* message = napi_value{js::transfer_in<value_of<string_tag>>(subject.message(), environment())};
86
+ -> js::referenceable_value<local_of<error_tag>> {
87
+ auto* message = napi_value{js::transfer_in<local_of<string_tag>>(subject.message(), environment())};
88
88
  auto* error = [ & ] -> napi_value {
89
89
  switch (subject.name()) {
90
90
  default:
@@ -99,12 +99,12 @@ auto accept_basic_napi_value::operator()(error_tag /*tag*/, visit_holder visit,
99
99
  }();
100
100
  auto stack = (*this)(string_tag{}, visit, subject.stack());
101
101
  napi::invoke0(napi_set_named_property, napi_env{*this}, error, "stack", *std::move(stack));
102
- return js::referenceable_value{value_of<error_tag>::from(error)};
102
+ return js::referenceable_value{local_of<error_tag>::from(error)};
103
103
  }
104
104
 
105
105
  // data blocks (array buffer, shared array buffer)
106
106
  auto accept_basic_napi_value::operator()(array_buffer_tag /*tag*/, visit_holder /*visit*/, const js::array_buffer& subject) const
107
- -> js::referenceable_value<value_of<array_buffer_tag>> {
107
+ -> js::referenceable_value<local_of<array_buffer_tag>> {
108
108
  auto view = std::span<const std::byte>{subject};
109
109
  // You could avoid the extra copy for `js::data_block&&` here w/ v8 API. Napi requires the copy
110
110
  // though.
@@ -115,18 +115,18 @@ auto accept_basic_napi_value::operator()(array_buffer_tag /*tag*/, visit_holder
115
115
  // (and also) it maybe causes an infinite loop with musl
116
116
  // https://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
117
117
  std::ranges::copy(view, static_cast<std::byte*>(bytes));
118
- auto value = value_of<array_buffer_tag>::from(result);
118
+ auto value = local_of<array_buffer_tag>::from(result);
119
119
  return js::referenceable_value{value};
120
120
  }
121
121
 
122
122
  auto accept_basic_napi_value::operator()(shared_array_buffer_tag /*tag*/, visit_holder /*visit*/, js::shared_array_buffer&& subject) const
123
- -> js::referenceable_value<value_of<shared_array_buffer_tag>> {
123
+ -> js::referenceable_value<local_of<shared_array_buffer_tag>> {
124
124
  auto value = make_shared_array_buffer(std::move(subject).acquire_ownership(), subject.byte_length());
125
125
  return js::referenceable_value{value};
126
126
  }
127
127
 
128
128
  auto accept_basic_napi_value::operator()(shared_array_buffer_tag tag, visit_holder visit, const js::shared_array_buffer& subject) const
129
- -> js::referenceable_value<value_of<shared_array_buffer_tag>> {
129
+ -> js::referenceable_value<local_of<shared_array_buffer_tag>> {
130
130
  return (*this)(tag, visit, js::shared_array_buffer{subject});
131
131
  }
132
132