@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.
- package/CMakeLists.txt +13 -2
- package/README.md +8 -8
- package/_module.cc +3 -3
- package/api/finalizer.cc +12 -14
- package/api/napi_scheduler.cc +3 -3
- package/api/napi_scheduler.h.cc +7 -6
- package/api/threadsafe_function.cc +12 -14
- package/api/uv_dlib.cc +4 -3
- package/handle/local.cc +112 -0
- package/handle/reference.cc +5 -5
- package/handle/remote.cc +11 -10
- package/handle/types.cc +9 -132
- package/handle/value.cc +122 -30
- package/package.json +4 -4
- package/support/callback.cc +3 -3
- package/support/callback_storage.cc +2 -2
- package/support/class_template_storage.cc +2 -2
- package/support/host.cc +197 -84
- package/support/host.h.cc +30 -14
- package/support/initialize.h.cc +2 -2
- package/support/promise.cc +10 -8
- package/support/win32_delay_load_hook.cc +12 -0
- package/transfer/accept.cc +34 -34
- package/transfer/accept.h.cc +81 -71
- package/transfer/visit.cc +182 -130
- package/value/array.cc +5 -7
- package/value/array.h.cc +7 -7
- package/value/array_buffer.cc +27 -32
- package/value/array_buffer.h.cc +50 -52
- package/value/class.cc +8 -9
- package/value/class.h.cc +5 -5
- package/value/external.cc +9 -11
- package/value/function.cc +7 -7
- package/value/function.h.cc +2 -2
- package/value/object.cc +5 -8
- package/value/object.h.cc +8 -15
- package/value/primitive.cc +7 -10
- package/value/primitive.h.cc +24 -11
- package/value/record.cc +6 -8
- package/value/record.h.cc +8 -8
- package/value/value.cc +3 -1
- package/handle/bound_value.cc +0 -47
- package/support/host_shim.cc +0 -42
package/transfer/accept.cc
CHANGED
|
@@ -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 ->
|
|
8
|
-
return
|
|
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 ->
|
|
12
|
-
return
|
|
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 ->
|
|
17
|
-
return
|
|
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 ->
|
|
22
|
-
return
|
|
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 ->
|
|
26
|
-
return
|
|
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 ->
|
|
30
|
-
return
|
|
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<
|
|
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{
|
|
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<
|
|
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{
|
|
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<
|
|
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{
|
|
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<
|
|
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{
|
|
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<
|
|
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{
|
|
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<
|
|
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{
|
|
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<
|
|
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<
|
|
80
|
-
auto value =
|
|
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<
|
|
87
|
-
auto* message = napi_value{js::transfer_in<
|
|
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{
|
|
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<
|
|
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 =
|
|
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<
|
|
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<
|
|
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
|
|
package/transfer/accept.h.cc
CHANGED
|
@@ -15,8 +15,8 @@ struct reaccept_napi_value {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
template <class Tag>
|
|
18
|
-
constexpr auto operator()(std::type_identity<
|
|
19
|
-
return
|
|
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 ->
|
|
33
|
-
auto operator()(undefined_tag tag, visit_holder visit, const auto& /*subject*/) const ->
|
|
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 ->
|
|
38
|
-
auto operator()(null_tag tag, visit_holder visit, const auto& /*subject*/) const ->
|
|
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 ->
|
|
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 ->
|
|
47
|
-
auto operator()(number_tag_of<std::int32_t> tag, visit_holder visit, std::int32_t subject) const ->
|
|
48
|
-
auto operator()(number_tag_of<std::uint32_t> tag, visit_holder visit, std::uint32_t subject) const ->
|
|
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 ->
|
|
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 ->
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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{
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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{
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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 =
|
|
137
|
-
return js::referenceable_value{
|
|
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 ->
|
|
165
|
-
return
|
|
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<
|
|
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
|
-
|
|
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
|
-
[](
|
|
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<
|
|
188
|
+
-> js::deferred_receiver<local_of<vector_tag>, decltype(self), decltype(visit), decltype(subject)> {
|
|
189
189
|
return {
|
|
190
|
-
|
|
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
|
-
[](
|
|
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<
|
|
206
|
+
-> js::deferred_receiver<local_of<list_tag>, decltype(self), decltype(visit), decltype(subject)> {
|
|
207
207
|
return {
|
|
208
|
-
|
|
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
|
-
[](
|
|
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<
|
|
217
|
+
-> js::deferred_receiver<local_of<dictionary_tag>, decltype(self), decltype(visit), decltype(subject)> {
|
|
218
218
|
return {
|
|
219
|
-
|
|
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
|
-
[](
|
|
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,
|
|
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,
|
|
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<
|
|
256
|
+
-> js::deferred_receiver<local_of<dictionary_tag>, decltype(self), decltype(visit), decltype(subject)> {
|
|
257
257
|
return {
|
|
258
|
-
|
|
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
|
-
[](
|
|
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,
|
|
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<
|
|
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(
|
|
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
|
-
|
|
323
|
+
local_of<object_tag> object_;
|
|
310
324
|
};
|
|
311
325
|
|
|
312
|
-
auto
|
|
313
|
-
js::transfer_in<object_assign_delegate>(std::move(source), env, object_assign_delegate{
|
|
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 `
|
|
344
|
+
// Tagged `local_of<T>` acceptor
|
|
331
345
|
template <>
|
|
332
|
-
struct accept_property_subject<napi::
|
|
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::
|
|
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
|
-
//
|
|
341
|
-
template <class Tag>
|
|
342
|
-
struct accept<
|
|
343
|
-
|
|
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
|