@auto_js/napi 0.0.7 → 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,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,38 +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
+
17
+ class value_for_false : public value_next<false_tag> {
18
+ public:
19
+ using value_next<false_tag>::value_next;
20
+ [[nodiscard]] constexpr explicit operator bool() const { return false; }
21
+ };
22
+
23
+ class value_for_true : public value_next<true_tag> {
24
+ public:
25
+ using value_next<true_tag>::value_next;
26
+ [[nodiscard]] constexpr explicit operator bool() const { return true; }
27
+ };
28
+
16
29
  // number
17
- class bound_value_for_number : public bound_value_next<number_tag> {
30
+ class value_for_number : public value_next<number_tag> {
18
31
  public:
19
- using bound_value_next<number_tag>::bound_value_next;
32
+ using value_next<number_tag>::value_next;
20
33
  [[nodiscard]] explicit operator double() const;
21
34
  [[nodiscard]] explicit operator std::int32_t() const;
22
35
  };
23
36
 
24
37
  // bigint
25
- class bound_value_for_bigint : public bound_value_next<bigint_tag> {
38
+ class value_for_bigint : public value_next<bigint_tag> {
26
39
  public:
27
- using bound_value_next<bigint_tag>::bound_value_next;
40
+ using value_next<bigint_tag>::value_next;
28
41
  [[nodiscard]] explicit operator bigint() const;
29
42
  [[nodiscard]] explicit operator std::int64_t() const;
30
43
  };
31
44
 
32
45
  // string
33
- class bound_value_for_string : public bound_value_next<string_tag> {
46
+ class value_for_string : public value_next<string_tag> {
34
47
  public:
35
- using bound_value_next<string_tag>::bound_value_next;
48
+ using value_next<string_tag>::value_next;
36
49
  [[nodiscard]] explicit operator std::string() const;
37
50
  [[nodiscard]] explicit operator std::u16string() const;
38
51
  };
package/value/record.cc CHANGED
@@ -1,19 +1,17 @@
1
1
  module napi_js;
2
- import :api;
3
- import :array;
4
2
  import std;
5
3
 
6
4
  namespace js::napi {
7
5
 
8
- auto bound_value_for_record::into_range() const -> range_type {
6
+ auto value_for_record::into_range() const -> range_type {
9
7
  return keys() | std::views::transform(iterator_transform{*this});
10
8
  }
11
9
 
12
- auto bound_value_for_record::size() const -> std::size_t {
10
+ auto value_for_record::size() const -> std::size_t {
13
11
  return keys().size();
14
12
  }
15
13
 
16
- auto bound_value_for_record::keys() const -> const keys_type& {
14
+ auto value_for_record::keys() const -> const keys_type& {
17
15
  if (napi_value{keys_} == nullptr) {
18
16
  auto* property_names = napi::invoke(
19
17
  napi_get_all_property_names,
@@ -23,15 +21,15 @@ auto bound_value_for_record::keys() const -> const keys_type& {
23
21
  static_cast<napi_key_filter>(napi_key_enumerable | napi_key_skip_symbols),
24
22
  napi_key_keep_numbers
25
23
  );
26
- keys_ = keys_type{env(), js::napi::value_of<vector_tag>::from(property_names)};
24
+ keys_ = keys_type{env(), js::napi::local_of<vector_tag>::from(property_names)};
27
25
  }
28
26
  return keys_;
29
27
  }
30
28
 
31
- bound_value_for_record::iterator_transform::iterator_transform(const bound_value_for_record& subject) :
29
+ value_for_record::iterator_transform::iterator_transform(const value_for_record& subject) :
32
30
  subject_{&subject} {}
33
31
 
34
- auto bound_value_for_record::iterator_transform::operator()(value_of<value_tag> key) const -> value_type {
32
+ auto value_for_record::iterator_transform::operator()(local_of<value_tag> key) const -> value_type {
35
33
  return std::pair{key_type::from(key), subject_->get(key)};
36
34
  }
37
35
 
package/value/record.h.cc CHANGED
@@ -5,22 +5,22 @@ import std;
5
5
 
6
6
  namespace js::napi {
7
7
 
8
- class bound_value_for_record : public bound_value_next<record_tag> {
8
+ class value_for_record : public value_next<record_tag> {
9
9
  public:
10
- using bound_value_next<record_tag>::bound_value_next;
11
- using keys_type = bound_value<vector_tag>;
12
- using key_type = value_of<primitive_tag>;
13
- using mapped_type = value_of<value_tag>;
10
+ using value_next<record_tag>::value_next;
11
+ using keys_type = value_of<vector_tag>;
12
+ using key_type = local_of<primitive_tag>;
13
+ using mapped_type = local_of<value_tag>;
14
14
  using value_type = std::pair<key_type, mapped_type>;
15
15
 
16
16
  private:
17
17
  class iterator_transform {
18
18
  public:
19
- explicit iterator_transform(const bound_value_for_record& subject_);
20
- auto operator()(value_of<value_tag> key) const -> value_type;
19
+ explicit iterator_transform(const value_for_record& subject_);
20
+ auto operator()(local_of<value_tag> key) const -> value_type;
21
21
 
22
22
  private:
23
- const bound_value_for_record* subject_;
23
+ const value_for_record* subject_;
24
24
  };
25
25
 
26
26
  public:
package/value/value.cc CHANGED
@@ -4,7 +4,9 @@ export import :array;
4
4
  export import :class_;
5
5
  export import :external;
6
6
  export import :function;
7
+ export import :handle.local_of;
8
+ export import :handle.types;
9
+ export import :handle.value_of;
7
10
  export import :object;
8
11
  export import :primitive;
9
12
  export import :record;
10
- export import :value_handle;
@@ -1,47 +0,0 @@
1
- export module napi_js:bound_value;
2
- import :handle.types;
3
- import nodejs;
4
-
5
- namespace js::napi {
6
-
7
- // Details applied to each level of the `bound_value<T>` hierarchy.
8
- template <class Tag>
9
- class bound_value_next : public bound_value<typename Tag::tag_type> {
10
- public:
11
- using tag_type = Tag;
12
- using bound_value<typename Tag::tag_type>::bound_value;
13
- bound_value_next() = default;
14
- bound_value_next(napi_env env, value_of<Tag> value) :
15
- bound_value<typename Tag::tag_type>{env, napi_value{value}} {}
16
-
17
- // NOLINTNEXTLINE(google-explicit-constructor)
18
- operator value_of<Tag>() const { return value_of<Tag>::from(napi_value{*this}); }
19
- };
20
-
21
- // Member & method implementation for stateful objects. Used internally in visitors. I think it
22
- // might make sense to have the environment specified by a template parameter. Then you would use
23
- // `bound_value<T>` or something instead of passing the environment to each `value_of<T>` method.
24
- template <class Tag>
25
- class bound_value : public value_specialization<Tag>::bound_type {
26
- public:
27
- using value_specialization<Tag>::bound_type::bound_type;
28
- };
29
-
30
- template <class Tag>
31
- bound_value(auto, value_of<Tag>) -> bound_value<Tag>;
32
-
33
- template <>
34
- class bound_value<void> : public value_handle {
35
- protected:
36
- bound_value() = default;
37
- bound_value(napi_env env, napi_value value) :
38
- value_handle{value},
39
- env_{env} {}
40
-
41
- [[nodiscard]] auto env() const -> napi_env { return env_; }
42
-
43
- private:
44
- napi_env env_{};
45
- };
46
-
47
- } // namespace js::napi
@@ -1,42 +0,0 @@
1
- import std;
2
-
3
- // NOLINTBEGIN(bugprone-macro-parentheses)
4
- #if _WIN64
5
- // I couldn't get this to work.
6
- // https://stackoverflow.com/questions/2290587/gcc-style-weak-linking-in-visual-studio
7
- #define SHIM(NAME)
8
- #else
9
- #define SHIM(NAME) \
10
- __attribute__((weak)) __attribute__((visibility("default"))) auto NAME = nullptr;
11
- #endif
12
- // NOLINTEND(bugprone-macro-parentheses)
13
-
14
- extern "C" {
15
- const void* shim_nullptr = nullptr;
16
- // NOLINTBEGIN(bugprone-reserved-identifier)
17
- SHIM(_ZN2v810Int16Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
18
- SHIM(_ZN2v810Int32Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
19
- SHIM(_ZN2v810Uint8Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
20
- SHIM(_ZN2v811Uint16Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
21
- SHIM(_ZN2v811Uint32Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
22
- SHIM(_ZN2v812BackingStoreD1Ev)
23
- SHIM(_ZN2v812Float16Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
24
- SHIM(_ZN2v812Float32Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
25
- SHIM(_ZN2v812Float64Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
26
- SHIM(_ZN2v813BigInt64Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
27
- SHIM(_ZN2v814BigUint64Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
28
- SHIM(_ZN2v817SharedArrayBuffer15GetBackingStoreEv)
29
- SHIM(_ZN2v817SharedArrayBuffer15NewBackingStoreEPvmPFvS1_mS1_ES1_)
30
- SHIM(_ZN2v817SharedArrayBuffer3NewEPNS_7IsolateENSt3__110shared_ptrINS_12BackingStoreEEE)
31
- SHIM(_ZN2v817Uint8ClampedArray3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
32
- SHIM(_ZN2v87Isolate10GetCurrentEv)
33
- SHIM(_ZN2v88DataView3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
34
- SHIM(_ZN2v89Int8Array3NewENS_5LocalINS_17SharedArrayBufferEEEmm)
35
- SHIM(_ZNK2v812BackingStore4DataEv)
36
- SHIM(_ZNK2v817SharedArrayBuffer10ByteLengthEv)
37
- SHIM(_ZNK2v85Value7IsInt32Ev)
38
- SHIM(_ZNK2v85Value8IsNumberEv)
39
- SHIM(_ZNK2v86String9IsOneByteEv)
40
- SHIM(node_api_is_sharedarraybuffer)
41
- // NOLINTEND(bugprone-reserved-identifier)
42
- }