@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.
@@ -1,6 +1,4 @@
1
1
  export module napi_js:array_buffer;
2
- import :bound_value;
3
- import :environment;
4
2
  import :object;
5
3
  import std;
6
4
  import v8;
@@ -8,93 +6,93 @@ import v8;
8
6
  namespace js::napi {
9
7
 
10
8
  // Data blocks
11
- class bound_value_for_data_block : public bound_value_next<data_block_tag> {
9
+ class value_for_data_block : public value_next<data_block_tag> {
12
10
  public:
13
- using bound_value_next<data_block_tag>::bound_value_next;
11
+ using value_next<data_block_tag>::value_next;
14
12
  [[nodiscard]] constexpr auto byte_length() const -> std::size_t { return std::span<std::byte>{*this}.size(); }
15
13
  [[nodiscard]] constexpr auto data() const -> const std::byte* { return std::span<std::byte>{*this}.data(); }
16
14
  explicit operator std::span<std::byte>() const;
17
15
  };
18
16
 
19
17
  // `ArrayBuffer`
20
- class bound_value_for_array_buffer : public bound_value_next<array_buffer_tag> {
18
+ class value_for_array_buffer : public value_next<array_buffer_tag> {
21
19
  public:
22
- using bound_value_next<array_buffer_tag>::bound_value_next;
20
+ using value_next<array_buffer_tag>::value_next;
23
21
  explicit operator js::array_buffer() const;
24
22
  };
25
23
 
26
24
  // `SharedArrayBuffer`
27
- class bound_value_for_shared_array_buffer : public bound_value_next<shared_array_buffer_tag> {
25
+ class value_for_shared_array_buffer : public value_next<shared_array_buffer_tag> {
28
26
  public:
29
- using bound_value_next<shared_array_buffer_tag>::bound_value_next;
27
+ using value_next<shared_array_buffer_tag>::value_next;
30
28
  explicit operator js::shared_array_buffer() const;
31
29
  };
32
30
 
33
31
  // `ArrayBufferView` (hidden superclass of `TypedArray` and `DataView`)
34
- class bound_value_for_array_buffer_view : public bound_value_next<array_buffer_view_tag> {
32
+ class value_for_array_buffer_view : public value_next<array_buffer_view_tag> {
35
33
  protected:
36
- bound_value_for_array_buffer_view(
34
+ value_for_array_buffer_view(
37
35
  napi_env env,
38
- value_of<array_buffer_view_tag> typed_array,
39
- std::tuple<value_of<data_block_tag>, std::size_t, std::size_t> array_buffer_info
36
+ local_of<array_buffer_view_tag> typed_array,
37
+ std::tuple<local_of<data_block_tag>, std::size_t, std::size_t> array_buffer_info
40
38
  ) :
41
- bound_value_next<array_buffer_view_tag>{env, typed_array},
39
+ value_next<array_buffer_view_tag>{env, typed_array},
42
40
  array_buffer_{std::get<0>(array_buffer_info)},
43
41
  byte_offset_{std::get<1>(array_buffer_info)},
44
42
  length_{std::get<2>(array_buffer_info)} {}
45
43
 
46
44
  public:
47
- [[nodiscard]] auto buffer() const -> value_of<data_block_tag> { return array_buffer_; }
45
+ [[nodiscard]] auto buffer() const -> local_of<data_block_tag> { return array_buffer_; }
48
46
  [[nodiscard]] auto byte_offset() const -> std::size_t { return byte_offset_; }
49
47
  [[nodiscard]] auto size() const -> std::size_t { return length_; }
50
48
 
51
49
  private:
52
- value_of<data_block_tag> array_buffer_;
50
+ local_of<data_block_tag> array_buffer_;
53
51
  std::size_t byte_offset_;
54
52
  std::size_t length_;
55
53
  };
56
54
 
57
55
  // `TypedArray`
58
- class value_for_typed_array : public value_next<typed_array_tag> {
56
+ class local_for_typed_array : public local_next<typed_array_tag> {
59
57
  protected:
60
- static auto make(const environment& env, napi_typedarray_type type, value_of<array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<typed_array_tag>;
61
- static auto make(const environment& env, napi_typedarray_type type, value_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<typed_array_tag>;
58
+ static auto make(const environment& env, napi_typedarray_type type, local_of<array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<typed_array_tag>;
59
+ static auto make(const environment& env, napi_typedarray_type type, local_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<typed_array_tag>;
62
60
  };
63
61
 
64
- class bound_value_for_typed_array : public bound_value_next<typed_array_tag> {
62
+ class value_for_typed_array : public value_next<typed_array_tag> {
65
63
  public:
66
- using bound_value_next<typed_array_tag>::bound_value_next;
67
- using any_bound_typed_array = std::variant<
68
- bound_value<typed_array_tag_of<double>>,
69
- bound_value<typed_array_tag_of<float>>,
70
- bound_value<typed_array_tag_of<js::float16_t>>,
71
- bound_value<typed_array_tag_of<js::uint8_clamped_t>>,
72
- bound_value<typed_array_tag_of<std::int16_t>>,
73
- bound_value<typed_array_tag_of<std::int32_t>>,
74
- bound_value<typed_array_tag_of<std::int64_t>>,
75
- bound_value<typed_array_tag_of<std::int8_t>>,
76
- bound_value<typed_array_tag_of<std::uint16_t>>,
77
- bound_value<typed_array_tag_of<std::uint32_t>>,
78
- bound_value<typed_array_tag_of<std::uint64_t>>,
79
- bound_value<typed_array_tag_of<std::uint8_t>>>;
80
-
81
- static auto make_bound(const environment& env, value_of<typed_array_tag> typed_array) -> any_bound_typed_array;
64
+ using value_next<typed_array_tag>::value_next;
65
+ using any_value_typed_array = std::variant<
66
+ value_of<typed_array_tag_of<double>>,
67
+ value_of<typed_array_tag_of<float>>,
68
+ value_of<typed_array_tag_of<js::float16_t>>,
69
+ value_of<typed_array_tag_of<js::uint8_clamped_t>>,
70
+ value_of<typed_array_tag_of<std::int16_t>>,
71
+ value_of<typed_array_tag_of<std::int32_t>>,
72
+ value_of<typed_array_tag_of<std::int64_t>>,
73
+ value_of<typed_array_tag_of<std::int8_t>>,
74
+ value_of<typed_array_tag_of<std::uint16_t>>,
75
+ value_of<typed_array_tag_of<std::uint32_t>>,
76
+ value_of<typed_array_tag_of<std::uint64_t>>,
77
+ value_of<typed_array_tag_of<std::uint8_t>>>;
78
+
79
+ static auto make_bound(const environment& env, local_of<typed_array_tag> typed_array) -> any_value_typed_array;
82
80
  };
83
81
 
84
82
  template <class Type>
85
- class value_for_typed_array_of : public value_next<typed_array_tag_of<Type>> {
83
+ class local_for_typed_array_of : public local_next<typed_array_tag_of<Type>> {
86
84
  public:
87
- using value_next<typed_array_tag_of<Type>>::value_next;
85
+ using local_next<typed_array_tag_of<Type>>::local_next;
88
86
 
89
- static auto make(const environment& env, value_of<data_block_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<typed_array_tag_of<Type>> {
87
+ static auto make(const environment& env, local_of<data_block_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<typed_array_tag_of<Type>> {
90
88
  if (napi::invoke(napi_is_arraybuffer, napi_env{env}, buffer)) {
91
- return make(env, value_of<array_buffer_tag>::from(buffer), byte_offset, length);
89
+ return make(env, local_of<array_buffer_tag>::from(buffer), byte_offset, length);
92
90
  } else {
93
- return make(env, value_of<shared_array_buffer_tag>::from(buffer), byte_offset, length);
91
+ return make(env, local_of<shared_array_buffer_tag>::from(buffer), byte_offset, length);
94
92
  }
95
93
  }
96
94
 
97
- static auto make(const environment& env, value_of<array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<typed_array_tag_of<Type>> {
95
+ static auto make(const environment& env, local_of<array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<typed_array_tag_of<Type>> {
98
96
  constexpr auto type_tag = util::overloaded{
99
97
  [](std::type_identity<double>) -> napi_typedarray_type { return napi_float64_array; },
100
98
  [](std::type_identity<float>) -> napi_typedarray_type { return napi_float32_array; },
@@ -109,34 +107,34 @@ class value_for_typed_array_of : public value_next<typed_array_tag_of<Type>> {
109
107
  [](std::type_identity<std::uint64_t>) -> napi_typedarray_type { return napi_biguint64_array; },
110
108
  [](std::type_identity<std::uint8_t>) -> napi_typedarray_type { return napi_uint8_array; },
111
109
  }(type<Type>);
112
- return value_of<typed_array_tag_of<Type>>::from(value_for_typed_array::make(env, type_tag, buffer, byte_offset, length));
110
+ return local_of<typed_array_tag_of<Type>>::from(local_for_typed_array::make(env, type_tag, buffer, byte_offset, length));
113
111
  }
114
112
 
115
113
  // napi doesn't provide a way to make a typed array view on a shared array buffer
116
- static auto make(const environment& /*env*/, value_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<typed_array_tag_of<Type>> {
114
+ static auto make(const environment& /*env*/, local_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<typed_array_tag_of<Type>> {
117
115
  return make_sab_typed_array_of<Type>(buffer, byte_offset, length);
118
116
  }
119
117
  };
120
118
 
121
119
  template <class Type>
122
- class bound_value_for_typed_array_of : public bound_value_next<typed_array_tag_of<Type>> {
120
+ class value_for_typed_array_of : public value_next<typed_array_tag_of<Type>> {
123
121
  public:
124
- using bound_value_next<typed_array_tag_of<Type>>::bound_value_next;
122
+ using value_next<typed_array_tag_of<Type>>::value_next;
125
123
  };
126
124
 
127
125
  // `DataView`
128
- class value_for_data_view : public value_next<data_view_tag> {
126
+ class local_for_data_view : public local_next<data_view_tag> {
129
127
  public:
130
- using value_next<data_view_tag>::value_next;
128
+ using local_next<data_view_tag>::local_next;
131
129
 
132
- static auto make(const environment& env, value_of<data_block_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<data_view_tag>;
133
- static auto make(const environment& env, value_of<array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<data_view_tag>;
134
- static auto make(const environment& env, value_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> value_of<data_view_tag>;
130
+ static auto make(const environment& env, local_of<data_block_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<data_view_tag>;
131
+ static auto make(const environment& env, local_of<array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<data_view_tag>;
132
+ static auto make(const environment& env, local_of<shared_array_buffer_tag> buffer, std::size_t byte_offset, std::size_t length) -> local_of<data_view_tag>;
135
133
  };
136
134
 
137
- class bound_value_for_data_view : public bound_value_next<data_view_tag> {
135
+ class value_for_data_view : public value_next<data_view_tag> {
138
136
  public:
139
- bound_value_for_data_view(napi_env env, value_of<data_view_tag> data_view);
137
+ value_for_data_view(napi_env env, local_of<data_view_tag> data_view);
140
138
  };
141
139
 
142
140
  } // namespace js::napi
package/value/class.cc CHANGED
@@ -8,7 +8,7 @@ namespace js::napi {
8
8
 
9
9
  template <class Type>
10
10
  template <class... Args>
11
- auto value_for_class_of<Type>::construct(auto& env, Args&&... args) const -> value_of<object_tag>
11
+ auto local_for_class_of<Type>::construct(auto& env, Args&&... args) const -> local_of<object_tag>
12
12
  requires std::constructible_from<Type, Args...> {
13
13
  // NOLINTNEXTLINE(readability-simplify-boolean-expr)
14
14
  if (false) {
@@ -21,21 +21,20 @@ auto value_for_class_of<Type>::construct(auto& env, Args&&... args) const -> val
21
21
 
22
22
  template <class Type>
23
23
  template <class... HostArgs, class... RuntimeArgs>
24
- auto value_for_class_of<Type>::runtime_construct(
24
+ auto local_for_class_of<Type>::runtime_construct(
25
25
  auto& env,
26
26
  std::tuple<HostArgs...> host_args,
27
27
  std::tuple<RuntimeArgs...> runtime_args
28
- ) const -> value_of<object_tag>
28
+ ) const -> local_of<object_tag>
29
29
  requires std::constructible_from<Type, HostArgs...> {
30
30
  const auto [... indices ] = util::sequence<sizeof...(HostArgs)>;
31
- // NOLINTNEXTLINE(bugprone-use-after-move)
32
31
  auto instance = std::make_unique<Type>(std::get<indices>(std::move(host_args))...);
33
32
  return transfer_construct(env, std::move(instance), std::move(runtime_args));
34
33
  }
35
34
 
36
35
  template <class Type>
37
36
  template <class... Args>
38
- auto value_for_class_of<Type>::transfer_construct(auto& env, auto instance, std::tuple<Args...> runtime_args) const -> value_of<object_tag> {
37
+ auto local_for_class_of<Type>::transfer_construct(auto& env, auto instance, std::tuple<Args...> runtime_args) const -> local_of<object_tag> {
39
38
  using element_type = decltype(instance)::element_type;
40
39
  auto construct = [ & ](napi_value this_arg) -> napi_value {
41
40
  // Tag `this_arg`
@@ -51,16 +50,16 @@ auto value_for_class_of<Type>::transfer_construct(auto& env, auto instance, std:
51
50
  // Now an external (of `internal_constructor`) gets passed to JavaScript for a moment and
52
51
  // hopefully it jumps into `construct`
53
52
  auto construct_ref = internal_constructor{construct};
54
- auto* construct_external = napi_value{value_of<external_tag>::make(env, &construct_ref)};
53
+ auto* construct_external = napi_value{local_of<external_tag>::make(env, &construct_ref)};
55
54
  auto [... runtime_arg_values ] = js::transfer_in_strict<std::array<napi_value, sizeof...(Args)>>(std::move(runtime_args), env);
56
55
  auto arg_vector = std::array{construct_external, runtime_arg_values...};
57
56
  auto* this_arg = napi::invoke(napi_new_instance, napi_env{env}, napi_value{*this}, arg_vector.size(), arg_vector.data());
58
- return value_of<object_tag>::from(this_arg);
57
+ return local_of<object_tag>::from(this_arg);
59
58
  }
60
59
 
61
60
  template <class Type>
62
61
  template <class Environment>
63
- auto value_for_class_of<Type>::make(Environment& env, const auto& class_template) -> value_of<class_tag_of<Type>> {
62
+ auto local_for_class_of<Type>::make(Environment& env, const auto& class_template) -> local_of<class_tag_of<Type>> {
64
63
  // Make constructor callback
65
64
  auto [ construct_ptr, constructor_data ] =
66
65
  make_callback_storage(env, make_constructor_function<Environment, Type>(class_template.constructor.function));
@@ -132,7 +131,7 @@ auto value_for_class_of<Type>::make(Environment& env, const auto& class_template
132
131
  property_descriptors.size(),
133
132
  property_descriptors.data()
134
133
  );
135
- return js::napi::value_of<class_tag_of<Type>>::from(result);
134
+ return js::napi::local_of<class_tag_of<Type>>::from(result);
136
135
  }
137
136
 
138
137
  } // namespace js::napi
package/value/class.h.cc CHANGED
@@ -5,23 +5,23 @@ import std;
5
5
  namespace js::napi {
6
6
 
7
7
  template <class Type>
8
- class value_for_class_of : public value_next<class_tag_of<Type>> {
8
+ class local_for_class_of : public local_next<class_tag_of<Type>> {
9
9
  public:
10
10
  // Construct a new C++ instance & JavaScript value
11
11
  template <class... Args>
12
- auto construct(auto& env, Args&&... args) const -> value_of<object_tag>
12
+ auto construct(auto& env, Args&&... args) const -> local_of<object_tag>
13
13
  requires std::constructible_from<Type, Args...>;
14
14
 
15
15
  template <class... HostArgs, class... RuntimeArgs>
16
- auto runtime_construct(auto& env, std::tuple<HostArgs...> host_args, std::tuple<RuntimeArgs...> runtime_args) const -> value_of<object_tag>
16
+ auto runtime_construct(auto& env, std::tuple<HostArgs...> host_args, std::tuple<RuntimeArgs...> runtime_args) const -> local_of<object_tag>
17
17
  requires std::constructible_from<Type, HostArgs...>;
18
18
 
19
19
  // Create a JavaScript value from an already-created instance smart pointer
20
20
  template <class... Args>
21
- auto transfer_construct(auto& env, auto instance, std::tuple<Args...> runtime_args) const -> value_of<object_tag>;
21
+ auto transfer_construct(auto& env, auto instance, std::tuple<Args...> runtime_args) const -> local_of<object_tag>;
22
22
 
23
23
  template <class Environment>
24
- static auto make(Environment& env, const auto& class_template) -> value_of<class_tag_of<Type>>;
24
+ static auto make(Environment& env, const auto& class_template) -> local_of<class_tag_of<Type>>;
25
25
  };
26
26
 
27
27
  } // namespace js::napi
package/value/external.cc CHANGED
@@ -1,24 +1,22 @@
1
1
  export module napi_js:external;
2
- import :api;
3
- import :bound_value;
4
2
  import :object;
5
3
  import std;
6
4
 
7
5
  namespace js::napi {
8
6
 
9
- class value_for_external : public value_next<external_tag> {
7
+ class local_for_external : public local_next<external_tag> {
10
8
  public:
11
9
  // untagged
12
- static auto make(auto& env, void* pointer) -> value_of<external_tag>;
10
+ static auto make(auto& env, void* pointer) -> local_of<external_tag>;
13
11
 
14
12
  // tagged
15
13
  template <class Type>
16
- static auto make(auto& env, Type* pointer) -> value_of<external_tag>;
14
+ static auto make(auto& env, Type* pointer) -> local_of<external_tag>;
17
15
  };
18
16
 
19
- class bound_value_for_external : public bound_value_next<external_tag> {
17
+ class value_for_external : public value_next<external_tag> {
20
18
  public:
21
- using bound_value_next<external_tag>::bound_value_next;
19
+ using value_next<external_tag>::value_next;
22
20
 
23
21
  template <class Type>
24
22
  [[nodiscard]] auto try_cast(std::type_identity<Type> /*type*/) const -> Type*;
@@ -26,20 +24,20 @@ class bound_value_for_external : public bound_value_next<external_tag> {
26
24
 
27
25
  // ---
28
26
 
29
- auto value_for_external::make(auto& env, void* pointer) -> value_of<external_tag> {
27
+ auto local_for_external::make(auto& env, void* pointer) -> local_of<external_tag> {
30
28
  auto* external = napi::invoke(napi_create_external, napi_env{env}, pointer, nullptr, nullptr);
31
- return value_of<external_tag>::from(external);
29
+ return local_of<external_tag>::from(external);
32
30
  }
33
31
 
34
32
  template <class Type>
35
- auto value_for_external::make(auto& env, Type* pointer) -> value_of<external_tag> {
33
+ auto local_for_external::make(auto& env, Type* pointer) -> local_of<external_tag> {
36
34
  auto external = make(env, static_cast<void*>(pointer));
37
35
  napi::invoke0(napi_type_tag_object, napi_env{env}, external, &type_tag_for<Type>);
38
36
  return external;
39
37
  };
40
38
 
41
39
  template <class Type>
42
- auto bound_value_for_external::try_cast(std::type_identity<Type> /*type*/) const -> Type* {
40
+ auto value_for_external::try_cast(std::type_identity<Type> /*type*/) const -> Type* {
43
41
  if (napi::invoke(napi_check_object_type_tag, env(), napi_value{*this}, &type_tag_for<Type>)) {
44
42
  return static_cast<Type*>(napi::invoke(napi_get_value_external, env(), napi_value{*this}));
45
43
  } else {
package/value/function.cc CHANGED
@@ -5,34 +5,34 @@ import std;
5
5
  namespace js::napi {
6
6
 
7
7
  template <class Result>
8
- auto value_for_function::apply(auto_environment auto& env, auto&& args) -> Result {
8
+ auto local_for_function::apply(auto_environment auto& env, auto&& args) -> Result {
9
9
  auto argv = js::transfer_in_strict<std::vector<napi_value>>(std::forward<decltype(args)>(args), env);
10
10
  return invoke<Result>(env, std::span{argv});
11
11
  }
12
12
 
13
13
  template <class Result>
14
- auto value_for_function::call(auto_environment auto& env, auto&&... args) -> Result {
14
+ auto local_for_function::call(auto_environment auto& env, auto&&... args) -> Result {
15
15
  auto argv = js::transfer_in_strict<std::array<napi_value, sizeof...(args)>>(std::forward_as_tuple(args...), env);
16
16
  return invoke<Result>(env, std::span{argv});
17
17
  }
18
18
 
19
19
  template <class Result>
20
- auto value_for_function::invoke(auto_environment auto& env, std::span<napi_value> args) -> Result {
20
+ auto local_for_function::invoke(auto_environment auto& env, std::span<napi_value> args) -> Result {
21
21
  auto undefined = js::transfer_in_strict<napi_value>(std::monostate{}, env);
22
22
  auto* result = napi::invoke(napi_call_function, napi_env{env}, undefined, napi_value{*this}, args.size(), args.data());
23
23
  return js::transfer_out<Result>(result, env);
24
24
  }
25
25
 
26
26
  template <auto_environment Environment>
27
- auto value_for_function::make(Environment& env, auto function) -> value_of<function_tag> {
27
+ auto local_for_function::make(Environment& env, auto function) -> local_of<function_tag> {
28
28
  auto [ callback, data ] = make_callback_storage(env, make_free_function<Environment>(std::move(function).callback));
29
- auto make = [ & ](void* data) -> value_of<function_tag> {
30
- return value_of<function_tag>::from(napi::invoke(napi_create_function, napi_env{env}, function.name.data(), function.name.length(), callback, data));
29
+ auto make = [ & ](void* data) -> local_of<function_tag> {
30
+ return local_of<function_tag>::from(napi::invoke(napi_create_function, napi_env{env}, function.name.data(), function.name.length(), callback, data));
31
31
  };
32
32
  if constexpr (requires { typename decltype(data)::element_type; }) {
33
33
  // Function requires finalizer
34
34
  auto function = make(data.get());
35
- return apply_finalizer(std::move(data), [ & ](auto* data, napi_finalize finalize, void* hint) -> value_of<function_tag> {
35
+ return apply_finalizer(std::move(data), [ & ](auto* data, napi_finalize finalize, void* hint) -> local_of<function_tag> {
36
36
  napi::invoke0(napi_add_finalizer, napi_env{env}, function, data, finalize, hint, nullptr);
37
37
  return function;
38
38
  });
@@ -4,7 +4,7 @@ import std;
4
4
 
5
5
  namespace js::napi {
6
6
 
7
- class value_for_function : public value_next<function_tag> {
7
+ class local_for_function : public local_next<function_tag> {
8
8
  public:
9
9
  template <class Result = std::monostate>
10
10
  auto apply(auto_environment auto& env, auto&& args) -> Result;
@@ -13,7 +13,7 @@ class value_for_function : public value_next<function_tag> {
13
13
  auto call(auto_environment auto& env, auto&&... args) -> Result;
14
14
 
15
15
  template <auto_environment Environment>
16
- static auto make(Environment& env, auto function) -> value_of<function_tag>;
16
+ static auto make(Environment& env, auto function) -> local_of<function_tag>;
17
17
 
18
18
  private:
19
19
  template <class Result>
package/value/object.cc CHANGED
@@ -1,25 +1,22 @@
1
1
  module napi_js;
2
- import :api;
3
- import :bound_value;
4
- import :value_handle;
5
2
 
6
3
  namespace js::napi {
7
4
 
8
5
  // object
9
- auto bound_value_for_object::get(napi_value key) const -> value_of<value_tag> {
10
- return value_of<value_tag>::from(napi::invoke(napi_get_property, env(), napi_value{*this}, key));
6
+ auto value_for_object::get(napi_value key) const -> local_of<value_tag> {
7
+ return local_of<value_tag>::from(napi::invoke(napi_get_property, env(), napi_value{*this}, key));
11
8
  }
12
9
 
13
- auto bound_value_for_object::has(napi_value key) const -> bool {
10
+ auto value_for_object::has(napi_value key) const -> bool {
14
11
  return napi::invoke(napi_has_own_property, env(), napi_value{*this}, key);
15
12
  }
16
13
 
17
- auto bound_value_for_object::set(napi_value key, napi_value value) -> void {
14
+ auto value_for_object::set(napi_value key, napi_value value) -> void {
18
15
  napi::invoke0(napi_set_property, env(), napi_value{*this}, key, value);
19
16
  }
20
17
 
21
18
  // date
22
- bound_value_for_date::operator js_clock::time_point() const {
19
+ value_for_date::operator js_clock::time_point() const {
23
20
  return js_clock::time_point{js_clock::duration{napi::invoke(napi_get_date_value, env(), napi_value{*this})}};
24
21
  }
25
22
 
package/value/object.h.cc CHANGED
@@ -1,42 +1,39 @@
1
1
  export module napi_js:object;
2
- import :api;
3
- import :bound_value;
4
- import :environment_fwd;
5
2
  import :primitive;
6
3
  import std;
7
4
 
8
5
  namespace js::napi {
9
6
 
10
7
  // object
11
- class value_for_object : public value_next<object_tag> {
8
+ class local_for_object : public local_next<object_tag> {
12
9
  public:
13
- auto assign(this value_of<object_tag> self, auto_environment auto& env, auto source) -> void;
10
+ auto assign(auto_environment auto& env, auto source) const -> void;
14
11
  };
15
12
 
16
- class bound_value_for_object : public bound_value_next<object_tag> {
13
+ class value_for_object : public value_next<object_tag> {
17
14
  public:
18
- using bound_value_next<object_tag>::bound_value_next;
15
+ using value_next<object_tag>::value_next;
19
16
 
20
17
  template <class Type>
21
18
  [[nodiscard]] auto try_cast(std::type_identity<Type> /*type*/) const -> Type*;
22
19
 
23
- [[nodiscard]] auto get(napi_value key) const -> value_of<value_tag>;
20
+ [[nodiscard]] auto get(napi_value key) const -> local_of<value_tag>;
24
21
  [[nodiscard]] auto has(napi_value key) const -> bool;
25
22
 
26
23
  auto set(napi_value key, napi_value value) -> void;
27
24
  };
28
25
 
29
26
  // date
30
- class bound_value_for_date : public bound_value_next<date_tag> {
27
+ class value_for_date : public value_next<date_tag> {
31
28
  public:
32
- using bound_value_next<date_tag>::bound_value_next;
29
+ using value_next<date_tag>::value_next;
33
30
  [[nodiscard]] explicit operator js_clock::time_point() const;
34
31
  };
35
32
 
36
33
  // ---
37
34
 
38
35
  template <class Type>
39
- auto bound_value_for_object::try_cast(std::type_identity<Type> /*type*/) const -> Type* {
36
+ auto value_for_object::try_cast(std::type_identity<Type> /*type*/) const -> Type* {
40
37
  if (napi::invoke(napi_check_object_type_tag, env(), napi_value{*this}, &type_tag_for<Type>)) {
41
38
  return static_cast<Type*>(napi::invoke(napi_unwrap, env(), napi_value{*this}));
42
39
  } else {
@@ -44,8 +41,4 @@ auto bound_value_for_object::try_cast(std::type_identity<Type> /*type*/) const -
44
41
  }
45
42
  }
46
43
 
47
- // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125144
48
- template class bound_value_next<data_block_tag>;
49
- template class bound_value_next<array_buffer_view_tag>;
50
-
51
44
  } // namespace js::napi
@@ -1,27 +1,24 @@
1
1
  module napi_js;
2
- import :api;
3
- import :bound_value;
4
- import :value_handle;
5
2
  import std;
6
3
 
7
4
  namespace js::napi {
8
5
 
9
6
  // boolean
10
- bound_value_for_boolean::operator bool() const {
7
+ value_for_boolean::operator bool() const {
11
8
  return napi::invoke(napi_get_value_bool, env(), napi_value{*this});
12
9
  }
13
10
 
14
11
  // number
15
- bound_value_for_number::operator double() const {
12
+ value_for_number::operator double() const {
16
13
  return napi::invoke(napi_get_value_double, env(), napi_value{*this});
17
14
  }
18
15
 
19
- bound_value_for_number::operator std::int32_t() const {
16
+ value_for_number::operator std::int32_t() const {
20
17
  return napi::invoke(napi_get_value_int32, env(), napi_value{*this});
21
18
  }
22
19
 
23
20
  // bigint
24
- bound_value_for_bigint::operator bigint() const {
21
+ value_for_bigint::operator bigint() const {
25
22
  js::bigint value;
26
23
  auto one_word = std::uint64_t{};
27
24
  auto length = std::size_t{1};
@@ -38,7 +35,7 @@ bound_value_for_bigint::operator bigint() const {
38
35
  return value;
39
36
  }
40
37
 
41
- bound_value_for_bigint::operator std::int64_t() const {
38
+ value_for_bigint::operator std::int64_t() const {
42
39
  // NOLINTNEXTLINE(cppcoreguidelines-init-variables)
43
40
  std::int64_t value;
44
41
  // nb: `lossless` error not checked for consistency with `napi_get_value_int32`,
@@ -48,7 +45,7 @@ bound_value_for_bigint::operator std::int64_t() const {
48
45
  }
49
46
 
50
47
  // string
51
- bound_value_for_string::operator std::string() const {
48
+ value_for_string::operator std::string() const {
52
49
  std::string string;
53
50
  auto length = napi::invoke(napi_get_value_string_latin1, env(), napi_value{*this}, nullptr, 0);
54
51
  if (length > 0) {
@@ -60,7 +57,7 @@ bound_value_for_string::operator std::string() const {
60
57
  return string;
61
58
  }
62
59
 
63
- bound_value_for_string::operator std::u16string() const {
60
+ value_for_string::operator std::u16string() const {
64
61
  // nb: napi requires that the returned string is null-terminated for some reason.
65
62
  std::u16string string;
66
63
  auto length = napi::invoke(napi_get_value_string_utf16, env(), napi_value{*this}, nullptr, 0);
@@ -1,51 +1,51 @@
1
1
  export module napi_js:primitive;
2
2
  import :api;
3
- import :bound_value;
4
- import :environment_fwd;
5
- import :value_handle;
3
+ import :environment;
4
+ import :handle.local_of;
5
+ import :handle.value_of;
6
6
  import std;
7
7
 
8
8
  namespace js::napi {
9
9
 
10
10
  // boolean
11
- class bound_value_for_boolean : public bound_value_next<boolean_tag> {
11
+ class value_for_boolean : public value_next<boolean_tag> {
12
12
  public:
13
- using bound_value_next<boolean_tag>::bound_value_next;
13
+ using value_next<boolean_tag>::value_next;
14
14
  [[nodiscard]] explicit operator bool() const;
15
15
  };
16
16
 
17
- class bound_value_for_false : public bound_value_next<false_tag> {
17
+ class value_for_false : public value_next<false_tag> {
18
18
  public:
19
- using bound_value_next<false_tag>::bound_value_next;
19
+ using value_next<false_tag>::value_next;
20
20
  [[nodiscard]] constexpr explicit operator bool() const { return false; }
21
21
  };
22
22
 
23
- class bound_value_for_true : public bound_value_next<true_tag> {
23
+ class value_for_true : public value_next<true_tag> {
24
24
  public:
25
- using bound_value_next<true_tag>::bound_value_next;
25
+ using value_next<true_tag>::value_next;
26
26
  [[nodiscard]] constexpr explicit operator bool() const { return true; }
27
27
  };
28
28
 
29
29
  // number
30
- class bound_value_for_number : public bound_value_next<number_tag> {
30
+ class value_for_number : public value_next<number_tag> {
31
31
  public:
32
- using bound_value_next<number_tag>::bound_value_next;
32
+ using value_next<number_tag>::value_next;
33
33
  [[nodiscard]] explicit operator double() const;
34
34
  [[nodiscard]] explicit operator std::int32_t() const;
35
35
  };
36
36
 
37
37
  // bigint
38
- class bound_value_for_bigint : public bound_value_next<bigint_tag> {
38
+ class value_for_bigint : public value_next<bigint_tag> {
39
39
  public:
40
- using bound_value_next<bigint_tag>::bound_value_next;
40
+ using value_next<bigint_tag>::value_next;
41
41
  [[nodiscard]] explicit operator bigint() const;
42
42
  [[nodiscard]] explicit operator std::int64_t() const;
43
43
  };
44
44
 
45
45
  // string
46
- class bound_value_for_string : public bound_value_next<string_tag> {
46
+ class value_for_string : public value_next<string_tag> {
47
47
  public:
48
- using bound_value_next<string_tag>::bound_value_next;
48
+ using value_next<string_tag>::value_next;
49
49
  [[nodiscard]] explicit operator std::string() const;
50
50
  [[nodiscard]] explicit operator std::u16string() const;
51
51
  };