@auto_js/napi 0.0.1 → 0.0.4
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 +10 -4
- package/README.md +30 -3
- package/_module.cc +12 -10
- package/api/api.cc +8 -7
- package/api/callback_info.cc +1 -7
- package/api/finalizer.cc +1 -4
- package/api/invoke.cc +4 -9
- package/api/uv_dlib.cc +27 -0
- package/api/uv_dlib.h.cc +21 -0
- package/api/uv_handle.cc +9 -9
- package/api/uv_scheduler.cc +11 -17
- package/api/uv_scheduler.h.cc +3 -6
- package/handle/bound_value.cc +4 -7
- package/handle/reference.cc +9 -5
- package/handle/remote.cc +11 -17
- package/handle/types.cc +61 -46
- package/handle/value.cc +12 -14
- package/package.json +7 -6
- package/support/callback.cc +7 -19
- package/support/callback_storage.cc +4 -9
- package/support/class_template_storage.cc +4 -6
- package/support/container.cc +9 -10
- package/support/environment.cc +32 -20
- package/support/environment.h.cc +8 -18
- package/support/environment_fwd.cc +1 -2
- package/support/error_scope.cc +0 -2
- package/support/initialize.h.cc +2 -5
- package/support/promise.cc +3 -10
- package/support/string_table.cc +3 -5
- package/support/utility.cc +54 -28
- package/transfer/accept.cc +131 -327
- package/transfer/accept.h.cc +390 -0
- package/transfer/visit.cc +201 -132
- package/value/array.cc +1 -3
- package/value/array.h.cc +5 -11
- package/value/array_buffer.cc +109 -0
- package/value/array_buffer.h.cc +150 -0
- package/value/class.cc +12 -21
- package/value/class.h.cc +5 -10
- package/value/external.cc +6 -10
- package/value/function.cc +5 -12
- package/value/function.h.cc +2 -9
- package/value/object.cc +2 -6
- package/value/object.h.cc +7 -15
- package/value/primitive.cc +12 -81
- package/value/primitive.h.cc +6 -64
- package/value/record.cc +38 -0
- package/value/record.h.cc +39 -0
- package/value/value.cc +8 -8
- package/value/dictionary.cc +0 -33
- package/value/dictionary.h.cc +0 -56
package/value/primitive.h.cc
CHANGED
|
@@ -1,96 +1,38 @@
|
|
|
1
|
-
module;
|
|
2
|
-
#include <cstddef>
|
|
3
|
-
#include <cstdint>
|
|
4
|
-
#include <string>
|
|
5
|
-
#include <string_view>
|
|
6
|
-
#include <variant>
|
|
7
1
|
export module napi_js:primitive;
|
|
8
2
|
import :api;
|
|
9
3
|
import :bound_value;
|
|
10
4
|
import :environment_fwd;
|
|
11
5
|
import :value_handle;
|
|
6
|
+
import std;
|
|
12
7
|
|
|
13
8
|
namespace js::napi {
|
|
14
9
|
|
|
15
|
-
// undefined
|
|
16
|
-
class value_for_undefined : public value_next<undefined_tag> {
|
|
17
|
-
public:
|
|
18
|
-
using value_next<undefined_tag>::value_next;
|
|
19
|
-
static auto make(const environment& env) -> value<undefined_tag>;
|
|
20
|
-
static auto make(const environment& env, std::monostate /*undefined*/) -> value<undefined_tag> { return make(env); }
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// null
|
|
24
|
-
class value_for_null : public value_next<null_tag> {
|
|
25
|
-
public:
|
|
26
|
-
using value_next<null_tag>::value_next;
|
|
27
|
-
static auto make(const environment& env) -> value<null_tag>;
|
|
28
|
-
static auto make(const environment& env, std::nullptr_t /*null*/) -> value<null_tag> { return make(env); }
|
|
29
|
-
};
|
|
30
|
-
|
|
31
10
|
// boolean
|
|
32
|
-
class value_for_boolean : public value_next<boolean_tag> {
|
|
33
|
-
public:
|
|
34
|
-
using value_next<boolean_tag>::value_next;
|
|
35
|
-
static auto make(const environment& env, bool boolean) -> value<boolean_tag>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
11
|
class bound_value_for_boolean : public bound_value_next<boolean_tag> {
|
|
39
12
|
public:
|
|
40
13
|
using bound_value_next<boolean_tag>::bound_value_next;
|
|
41
14
|
[[nodiscard]] explicit operator bool() const;
|
|
42
15
|
};
|
|
43
|
-
|
|
44
16
|
// number
|
|
45
|
-
class value_for_number : public value_next<number_tag> {
|
|
46
|
-
public:
|
|
47
|
-
using value_next<number_tag>::value_next;
|
|
48
|
-
static auto make(const environment& env, double number) -> value<number_tag>;
|
|
49
|
-
static auto make(const environment& env, int32_t number) -> value<number_tag>;
|
|
50
|
-
static auto make(const environment& env, int64_t number) -> value<number_tag>;
|
|
51
|
-
static auto make(const environment& env, uint32_t number) -> value<number_tag>;
|
|
52
|
-
|
|
53
|
-
static auto make_property_name(const environment& env, int32_t number) -> value<number_tag> { return make(env, number); }
|
|
54
|
-
};
|
|
55
|
-
|
|
56
17
|
class bound_value_for_number : public bound_value_next<number_tag> {
|
|
57
18
|
public:
|
|
58
19
|
using bound_value_next<number_tag>::bound_value_next;
|
|
59
20
|
[[nodiscard]] explicit operator double() const;
|
|
60
|
-
[[nodiscard]] explicit operator int32_t() const;
|
|
61
|
-
[[nodiscard]] explicit operator int64_t() const;
|
|
62
|
-
[[nodiscard]] explicit operator uint32_t() const;
|
|
21
|
+
[[nodiscard]] explicit operator std::int32_t() const;
|
|
22
|
+
[[nodiscard]] explicit operator std::int64_t() const;
|
|
23
|
+
[[nodiscard]] explicit operator std::uint32_t() const;
|
|
63
24
|
};
|
|
64
25
|
|
|
65
26
|
// bigint
|
|
66
|
-
class value_for_bigint : public value_next<bigint_tag> {
|
|
67
|
-
public:
|
|
68
|
-
using value_next<bigint_tag>::value_next;
|
|
69
|
-
static auto make(const environment& env, const bigint& number) -> value<bigint_tag>;
|
|
70
|
-
static auto make(const environment& env, int64_t number) -> value<bigint_tag>;
|
|
71
|
-
static auto make(const environment& env, uint64_t number) -> value<bigint_tag>;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
27
|
class bound_value_for_bigint : public bound_value_next<bigint_tag> {
|
|
75
28
|
public:
|
|
76
29
|
using bound_value_next<bigint_tag>::bound_value_next;
|
|
77
30
|
[[nodiscard]] explicit operator bigint() const;
|
|
78
|
-
[[nodiscard]] explicit operator int64_t() const;
|
|
79
|
-
[[nodiscard]] explicit operator uint64_t() const;
|
|
31
|
+
[[nodiscard]] explicit operator std::int64_t() const;
|
|
32
|
+
[[nodiscard]] explicit operator std::uint64_t() const;
|
|
80
33
|
};
|
|
81
34
|
|
|
82
35
|
// string
|
|
83
|
-
class value_for_string : public value_next<string_tag> {
|
|
84
|
-
public:
|
|
85
|
-
using value_next<string_tag>::value_next;
|
|
86
|
-
static auto make(const environment& env, std::string_view string) -> value<string_tag>;
|
|
87
|
-
static auto make(const environment& env, std::u8string_view string) -> value<string_tag>;
|
|
88
|
-
static auto make(const environment& env, std::u16string_view string) -> value<string_tag>;
|
|
89
|
-
static auto make_property_name(const environment& env, std::string_view string) -> value<string_tag>;
|
|
90
|
-
static auto make_property_name(const environment& env, std::u8string_view string) -> value<string_tag>;
|
|
91
|
-
static auto make_property_name(const environment& env, std::u16string_view string) -> value<string_tag>;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
36
|
class bound_value_for_string : public bound_value_next<string_tag> {
|
|
95
37
|
public:
|
|
96
38
|
using bound_value_next<string_tag>::bound_value_next;
|
package/value/record.cc
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module napi_js;
|
|
2
|
+
import :api;
|
|
3
|
+
import :array;
|
|
4
|
+
import std;
|
|
5
|
+
|
|
6
|
+
namespace js::napi {
|
|
7
|
+
|
|
8
|
+
auto bound_value_for_record::into_range() const -> range_type {
|
|
9
|
+
return keys() | std::views::transform(iterator_transform{*this});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
auto bound_value_for_record::size() const -> std::size_t {
|
|
13
|
+
return keys().size();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
auto bound_value_for_record::keys() const -> const keys_type& {
|
|
17
|
+
if (napi_value{keys_} == nullptr) {
|
|
18
|
+
auto* property_names = napi::invoke(
|
|
19
|
+
napi_get_all_property_names,
|
|
20
|
+
env(),
|
|
21
|
+
*this,
|
|
22
|
+
napi_key_own_only,
|
|
23
|
+
static_cast<napi_key_filter>(napi_key_enumerable | napi_key_skip_symbols),
|
|
24
|
+
napi_key_keep_numbers
|
|
25
|
+
);
|
|
26
|
+
keys_ = keys_type{env(), js::napi::value_of<vector_tag>::from(property_names)};
|
|
27
|
+
}
|
|
28
|
+
return keys_;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
bound_value_for_record::iterator_transform::iterator_transform(const bound_value_for_record& subject) :
|
|
32
|
+
subject_{&subject} {}
|
|
33
|
+
|
|
34
|
+
auto bound_value_for_record::iterator_transform::operator()(value_of<value_tag> key) const -> value_type {
|
|
35
|
+
return std::pair{key_type::from(key), subject_->get(key)};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
} // namespace js::napi
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export module napi_js:record;
|
|
2
|
+
import :array;
|
|
3
|
+
import auto_js;
|
|
4
|
+
import std;
|
|
5
|
+
|
|
6
|
+
namespace js::napi {
|
|
7
|
+
|
|
8
|
+
class bound_value_for_record : public bound_value_next<record_tag> {
|
|
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>;
|
|
14
|
+
using value_type = std::pair<key_type, mapped_type>;
|
|
15
|
+
|
|
16
|
+
private:
|
|
17
|
+
class iterator_transform {
|
|
18
|
+
public:
|
|
19
|
+
explicit iterator_transform(const bound_value_for_record& subject_);
|
|
20
|
+
auto operator()(value_of<value_tag> key) const -> value_type;
|
|
21
|
+
|
|
22
|
+
private:
|
|
23
|
+
const bound_value_for_record* subject_;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
using range_type = std::ranges::transform_view<std::views::all_t<const keys_type&>, iterator_transform>;
|
|
28
|
+
using iterator = std::ranges::iterator_t<range_type>;
|
|
29
|
+
|
|
30
|
+
[[nodiscard]] auto into_range() const -> range_type;
|
|
31
|
+
[[nodiscard]] auto size() const -> std::size_t;
|
|
32
|
+
|
|
33
|
+
private:
|
|
34
|
+
[[nodiscard]] auto keys() const -> const keys_type&;
|
|
35
|
+
|
|
36
|
+
mutable keys_type keys_;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
} // namespace js::napi
|
package/value/value.cc
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export module napi_js:value;
|
|
2
|
+
export import :array_buffer;
|
|
3
|
+
export import :array;
|
|
4
|
+
export import :class_;
|
|
5
|
+
export import :external;
|
|
6
|
+
export import :function;
|
|
7
|
+
export import :object;
|
|
8
|
+
export import :primitive;
|
|
9
|
+
export import :record;
|
|
2
10
|
export import :value_handle;
|
|
3
|
-
import :array;
|
|
4
|
-
import :bound_value;
|
|
5
|
-
import :class_;
|
|
6
|
-
import :dictionary;
|
|
7
|
-
import :external;
|
|
8
|
-
import :function;
|
|
9
|
-
import :object;
|
|
10
|
-
import :primitive;
|
package/value/dictionary.cc
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module;
|
|
2
|
-
#include <ranges>
|
|
3
|
-
#include <utility>
|
|
4
|
-
module napi_js;
|
|
5
|
-
import :api;
|
|
6
|
-
import :array;
|
|
7
|
-
|
|
8
|
-
namespace js::napi {
|
|
9
|
-
|
|
10
|
-
auto dictionary_like::into_range() const -> range_type {
|
|
11
|
-
return keys() | std::views::transform(iterator_transform{*this});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
auto dictionary_like::size() const -> std::size_t {
|
|
15
|
-
return keys().size();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
auto dictionary_like::keys() const -> const keys_type& {
|
|
19
|
-
if (napi_value{keys_} == nullptr) {
|
|
20
|
-
auto* property_names = napi::invoke(napi_get_property_names, env(), *this);
|
|
21
|
-
keys_ = keys_type{env(), js::napi::value<vector_tag>::from(property_names)};
|
|
22
|
-
}
|
|
23
|
-
return keys_;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
dictionary_like::iterator_transform::iterator_transform(const dictionary_like& subject) :
|
|
27
|
-
subject_{&subject} {}
|
|
28
|
-
|
|
29
|
-
auto dictionary_like::iterator_transform::operator()(value<value_tag> key) const -> value_type {
|
|
30
|
-
return std::pair{key_type::from(key), subject_->get(key)};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
} // namespace js::napi
|
package/value/dictionary.h.cc
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
module;
|
|
2
|
-
#include <ranges>
|
|
3
|
-
export module napi_js:dictionary;
|
|
4
|
-
import :array;
|
|
5
|
-
import :bound_value;
|
|
6
|
-
import :object;
|
|
7
|
-
import :value_handle;
|
|
8
|
-
import auto_js;
|
|
9
|
-
|
|
10
|
-
namespace js::napi {
|
|
11
|
-
|
|
12
|
-
// Weird naming here because an object `{}` is a typeof "object", but lots of other things are
|
|
13
|
-
// objects. Also, the object iterator is implemented as transformation on a property names vector
|
|
14
|
-
// (which is also an object). So this needs to be its own class or it is a circular inheritance.
|
|
15
|
-
class dictionary_like : public bound_value<object_tag> {
|
|
16
|
-
public:
|
|
17
|
-
using bound_value<object_tag>::bound_value;
|
|
18
|
-
using keys_type = bound_value<vector_tag>;
|
|
19
|
-
using key_type = value<primitive_tag>;
|
|
20
|
-
using mapped_type = value<value_tag>;
|
|
21
|
-
using value_type = std::pair<key_type, mapped_type>;
|
|
22
|
-
|
|
23
|
-
private:
|
|
24
|
-
class iterator_transform {
|
|
25
|
-
public:
|
|
26
|
-
explicit iterator_transform(const dictionary_like& subject_);
|
|
27
|
-
auto operator()(value<value_tag> key) const -> value_type;
|
|
28
|
-
|
|
29
|
-
private:
|
|
30
|
-
const dictionary_like* subject_;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
public:
|
|
34
|
-
using range_type = std::ranges::transform_view<std::views::all_t<const keys_type&>, iterator_transform>;
|
|
35
|
-
using iterator = std::ranges::iterator_t<range_type>;
|
|
36
|
-
|
|
37
|
-
[[nodiscard]] auto into_range() const -> range_type;
|
|
38
|
-
[[nodiscard]] auto size() const -> std::size_t;
|
|
39
|
-
|
|
40
|
-
private:
|
|
41
|
-
[[nodiscard]] auto keys() const -> const keys_type&;
|
|
42
|
-
|
|
43
|
-
mutable keys_type keys_;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
class bound_value_for_list : public dictionary_like {
|
|
47
|
-
public:
|
|
48
|
-
using dictionary_like::dictionary_like;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
class bound_value_for_dictionary : public dictionary_like {
|
|
52
|
-
public:
|
|
53
|
-
using dictionary_like::dictionary_like;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
} // namespace js::napi
|