@isolated-vm/experimental 0.0.9 → 0.0.11
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/addon/CMakeLists.txt +1 -1
- package/addon/handle/local_of.cc +149 -0
- package/addon/handle/types.cc +8 -137
- package/addon/handle/value_of.cc +82 -27
- package/addon/support/callback_info.cc +5 -5
- package/addon/support/callback_storage.cc +2 -2
- package/addon/support/free_function.cc +3 -3
- package/addon/support/initialize.cc +5 -5
- package/addon/transfer/accept.cc +104 -72
- package/addon/transfer/visit.cc +97 -54
- package/addon/value/array.cc +6 -6
- package/addon/value/array_buffer.cc +27 -18
- package/addon/value/function.cc +5 -5
- package/addon/value/function.h.cc +5 -5
- package/addon/value/object.cc +3 -3
- package/addon/value/primitive.cc +36 -36
- package/addon/value/prototype.cc +7 -7
- package/addon/value/record.cc +20 -20
- package/addon/value/value.cc +1 -1
- package/addon/value/vector.cc +9 -9
- package/backend/backend.d.cts +9 -9
- package/dist/frontend/agent.d.ts +1 -0
- package/dist/frontend/agent.d.ts.map +1 -1
- package/dist/frontend/agent.js.map +1 -1
- package/dist/frontend/module.d.ts +1 -1
- package/dist/frontend/module.d.ts.map +1 -1
- package/dist/frontend/module.js.map +1 -1
- package/dist/frontend/realm.d.ts +1 -1
- package/dist/frontend/realm.d.ts.map +1 -1
- package/dist/frontend/reference.d.ts +3 -3
- package/dist/frontend/reference.d.ts.map +1 -1
- package/dist/test/00.agent/00.prerequisites.d.ts +2 -0
- package/dist/test/00.agent/00.prerequisites.d.ts.map +1 -0
- package/dist/test/00.agent/00.prerequisites.js +25 -0
- package/dist/test/00.agent/00.prerequisites.js.map +1 -0
- package/dist/test/00.agent/10.clock.d.ts +2 -0
- package/dist/test/00.agent/10.clock.d.ts.map +1 -0
- package/dist/test/{00.datetime.js → 00.agent/10.clock.js} +8 -8
- package/dist/test/00.agent/10.clock.js.map +1 -0
- package/dist/test/00.agent/10.random.d.ts +2 -0
- package/dist/test/00.agent/10.random.d.ts.map +1 -0
- package/dist/test/{00.random.js → 00.agent/10.random.js} +4 -4
- package/dist/test/00.agent/10.random.js.map +1 -0
- package/dist/test/10.transfer/00.primitives.d.ts +2 -0
- package/dist/test/10.transfer/00.primitives.d.ts.map +1 -0
- package/dist/test/10.transfer/00.primitives.js +54 -0
- package/dist/test/10.transfer/00.primitives.js.map +1 -0
- package/dist/test/10.transfer/10.array_buffer.d.ts +2 -0
- package/dist/test/10.transfer/10.array_buffer.d.ts.map +1 -0
- package/dist/test/{20.array_buffer.js → 10.transfer/10.array_buffer.js} +69 -64
- package/dist/test/10.transfer/10.array_buffer.js.map +1 -0
- package/dist/test/10.transfer/90.regressions.d.ts +2 -0
- package/dist/test/10.transfer/90.regressions.d.ts.map +1 -0
- package/dist/test/10.transfer/90.regressions.js +72 -0
- package/dist/test/10.transfer/90.regressions.js.map +1 -0
- package/dist/test/20.intrinsics/00.script.d.ts +2 -0
- package/dist/test/20.intrinsics/00.script.d.ts.map +1 -0
- package/dist/test/{10.script.js → 20.intrinsics/00.script.js} +32 -7
- package/dist/test/20.intrinsics/00.script.js.map +1 -0
- package/dist/test/20.intrinsics/05.global.d.ts.map +1 -0
- package/dist/test/{05.global.js → 20.intrinsics/05.global.js} +5 -5
- package/dist/test/20.intrinsics/05.global.js.map +1 -0
- package/dist/test/20.intrinsics/10.reference.d.ts.map +1 -0
- package/dist/test/{10.reference.js → 20.intrinsics/10.reference.js} +73 -27
- package/dist/test/20.intrinsics/10.reference.js.map +1 -0
- package/dist/test/20.intrinsics/20.module.d.ts +2 -0
- package/dist/test/20.intrinsics/20.module.d.ts.map +1 -0
- package/dist/test/{10.module.js → 20.intrinsics/20.module.js} +70 -39
- package/dist/test/20.intrinsics/20.module.js.map +1 -0
- package/dist/test/50.features/50.timers.d.ts.map +1 -0
- package/dist/test/{50.timers.js → 50.features/50.timers.js} +8 -8
- package/dist/test/50.features/50.timers.js.map +1 -0
- package/dist/test/50.features/90.i18n.d.ts +2 -0
- package/dist/test/50.features/90.i18n.d.ts.map +1 -0
- package/dist/test/{99.i18n.js → 50.features/90.i18n.js} +6 -6
- package/dist/test/50.features/90.i18n.js.map +1 -0
- package/dist/test/90.isolation/00.dispose.d.ts +1 -1
- package/dist/test/90.isolation/00.dispose.d.ts.map +1 -1
- package/dist/test/90.isolation/00.dispose.js +23 -5
- package/dist/test/90.isolation/00.dispose.js.map +1 -1
- package/dist/test/90.isolation/10.memory.d.ts +2 -0
- package/dist/test/90.isolation/10.memory.d.ts.map +1 -0
- package/dist/test/90.isolation/10.memory.js +51 -0
- package/dist/test/90.isolation/10.memory.js.map +1 -0
- package/dist/test/fixtures.js +2 -2
- package/dist/test/fixtures.js.map +1 -1
- package/dist/test/glob.d.ts +2 -0
- package/dist/test/glob.d.ts.map +1 -0
- package/dist/test/glob.js +11 -0
- package/dist/test/glob.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utility/completion.d.ts +2 -1
- package/dist/utility/completion.d.ts.map +1 -1
- package/dist/utility/completion.js +4 -0
- package/dist/utility/completion.js.map +1 -1
- package/frontend/agent.ts +1 -0
- package/frontend/module.ts +1 -1
- package/frontend/realm.ts +4 -1
- package/frontend/reference.ts +3 -3
- package/package.json +13 -13
- package/test/00.agent/00.prerequisites.ts +12 -0
- package/test/{00.datetime.ts → 00.agent/10.clock.ts} +7 -7
- package/test/{00.random.ts → 00.agent/10.random.ts} +3 -3
- package/test/10.transfer/00.primitives.ts +47 -0
- package/test/{20.array_buffer.ts → 10.transfer/10.array_buffer.ts} +40 -35
- package/test/10.transfer/90.regressions.ts +38 -0
- package/test/{10.script.ts → 20.intrinsics/00.script.ts} +21 -6
- package/test/{05.global.ts → 20.intrinsics/05.global.ts} +5 -5
- package/test/20.intrinsics/10.reference.ts +111 -0
- package/test/{10.module.ts → 20.intrinsics/20.module.ts} +39 -17
- package/test/{50.timers.ts → 50.features/50.timers.ts} +8 -8
- package/test/{99.i18n.ts → 50.features/90.i18n.ts} +5 -5
- package/test/90.isolation/00.dispose.ts +12 -5
- package/test/90.isolation/10.memory.ts +28 -0
- package/test/fixtures.ts +4 -4
- package/test/glob.ts +11 -0
- package/utility/completion.ts +6 -1
- package/addon/handle/bound_value.cc +0 -45
- package/dist/test/00.datetime.d.ts +0 -2
- package/dist/test/00.datetime.d.ts.map +0 -1
- package/dist/test/00.datetime.js.map +0 -1
- package/dist/test/00.random.d.ts +0 -2
- package/dist/test/00.random.d.ts.map +0 -1
- package/dist/test/00.random.js.map +0 -1
- package/dist/test/00.transfer.d.ts +0 -2
- package/dist/test/00.transfer.d.ts.map +0 -1
- package/dist/test/00.transfer.js +0 -168
- package/dist/test/00.transfer.js.map +0 -1
- package/dist/test/05.global.d.ts.map +0 -1
- package/dist/test/05.global.js.map +0 -1
- package/dist/test/10.module.d.ts +0 -2
- package/dist/test/10.module.d.ts.map +0 -1
- package/dist/test/10.module.js.map +0 -1
- package/dist/test/10.reference.d.ts.map +0 -1
- package/dist/test/10.reference.js.map +0 -1
- package/dist/test/10.script.d.ts +0 -2
- package/dist/test/10.script.d.ts.map +0 -1
- package/dist/test/10.script.js.map +0 -1
- package/dist/test/20.array_buffer.d.ts +0 -2
- package/dist/test/20.array_buffer.d.ts.map +0 -1
- package/dist/test/20.array_buffer.js.map +0 -1
- package/dist/test/50.timers.d.ts.map +0 -1
- package/dist/test/50.timers.js.map +0 -1
- package/dist/test/99.i18n.d.ts +0 -2
- package/dist/test/99.i18n.d.ts.map +0 -1
- package/dist/test/99.i18n.js.map +0 -1
- package/test/00.transfer.ts +0 -134
- package/test/10.reference.ts +0 -82
- /package/dist/test/{05.global.d.ts → 20.intrinsics/05.global.d.ts} +0 -0
- /package/dist/test/{10.reference.d.ts → 20.intrinsics/10.reference.d.ts} +0 -0
- /package/dist/test/{50.timers.d.ts → 50.features/50.timers.d.ts} +0 -0
package/addon/CMakeLists.txt
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export module isolated_vm:handle.local_of;
|
|
2
|
+
export import :handle.types;
|
|
3
|
+
import auto_js;
|
|
4
|
+
import std;
|
|
5
|
+
import util;
|
|
6
|
+
|
|
7
|
+
namespace isolated_vm {
|
|
8
|
+
using namespace js;
|
|
9
|
+
|
|
10
|
+
// Map of `local_of<Tag>` to its concrete implementation class
|
|
11
|
+
template <class Tag>
|
|
12
|
+
struct local_specialization;
|
|
13
|
+
|
|
14
|
+
// Tagged isolated_vm value. Each `local_of<T>` inherits from the tag before it.
|
|
15
|
+
export template <class Tag>
|
|
16
|
+
class local_of : public local_of<typename Tag::tag_type> {
|
|
17
|
+
private:
|
|
18
|
+
using local_type = local_specialization<Tag>::type;
|
|
19
|
+
|
|
20
|
+
public:
|
|
21
|
+
local_of() = default;
|
|
22
|
+
using tag_type = Tag;
|
|
23
|
+
|
|
24
|
+
// Constructor from tagged `runtime_handle` flavors
|
|
25
|
+
explicit local_of(local_type value)
|
|
26
|
+
requires(type<local_type> != type<runtime_handle>) :
|
|
27
|
+
local_of{runtime_handle{value}} {}
|
|
28
|
+
|
|
29
|
+
// "Downcast" to a more specific tag. Potentially unsafe.
|
|
30
|
+
template <std::convertible_to<Tag> To>
|
|
31
|
+
auto cast(To /*tag*/) const -> local_of<To> { return local_of<To>::from(*this); }
|
|
32
|
+
|
|
33
|
+
// Construct from any `value_handle`. Potentially unsafe.
|
|
34
|
+
static auto from(runtime_handle value_) -> local_of<Tag> { return std::bit_cast<local_of<Tag>>(value_); }
|
|
35
|
+
|
|
36
|
+
// Forward `make` to specialization
|
|
37
|
+
static auto make(auto&&... args) -> local_of<Tag> { return local_type::make(std::forward<decltype(args)>(args)...); }
|
|
38
|
+
|
|
39
|
+
// Dereference operators
|
|
40
|
+
auto operator*() const -> local_type { return std::bit_cast<local_type>(runtime_handle{*this}); }
|
|
41
|
+
auto operator->() const -> auto { return util::pointer_delegate{**this}; }
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Sentinel instantiation
|
|
45
|
+
template <>
|
|
46
|
+
class local_of<void> : public runtime_handle {
|
|
47
|
+
public:
|
|
48
|
+
using runtime_handle::runtime_handle;
|
|
49
|
+
explicit local_of(runtime_handle value) : runtime_handle{value} {}
|
|
50
|
+
local_of() = default;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// Deduction guide
|
|
54
|
+
template <class Type>
|
|
55
|
+
local_of(Type value) -> local_of<typename Type::tag_type>;
|
|
56
|
+
|
|
57
|
+
// Details applied to each level of the `local_of<T>` hierarchy.
|
|
58
|
+
template <class Tag>
|
|
59
|
+
struct local_next : local_specialization<typename Tag::tag_type>::type {
|
|
60
|
+
using local_specialization<typename Tag::tag_type>::type::type;
|
|
61
|
+
using tag_type = Tag;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// `local_of<Tag>` implementation specializations. The default specialization selects the nearest
|
|
65
|
+
// specialization, or simply `runtime_handle` as the base class.
|
|
66
|
+
template <class Tag>
|
|
67
|
+
struct local_specialization
|
|
68
|
+
: local_specialization<typename Tag::tag_type> {};
|
|
69
|
+
|
|
70
|
+
template <>
|
|
71
|
+
struct local_specialization<void>
|
|
72
|
+
: std::type_identity<runtime_handle> {};
|
|
73
|
+
|
|
74
|
+
template <>
|
|
75
|
+
struct local_specialization<value_tag>
|
|
76
|
+
: std::type_identity<class local_for_value> {};
|
|
77
|
+
|
|
78
|
+
template <>
|
|
79
|
+
struct local_specialization<primitive_tag>
|
|
80
|
+
: std::type_identity<class local_for_primitive> {};
|
|
81
|
+
|
|
82
|
+
template <>
|
|
83
|
+
struct local_specialization<undefined_tag>
|
|
84
|
+
: std::type_identity<class local_for_undefined> {};
|
|
85
|
+
|
|
86
|
+
template <>
|
|
87
|
+
struct local_specialization<null_tag>
|
|
88
|
+
: std::type_identity<class local_for_null> {};
|
|
89
|
+
|
|
90
|
+
template <>
|
|
91
|
+
struct local_specialization<boolean_tag>
|
|
92
|
+
: std::type_identity<class local_for_boolean> {};
|
|
93
|
+
|
|
94
|
+
template <>
|
|
95
|
+
struct local_specialization<number_tag>
|
|
96
|
+
: std::type_identity<class local_for_number> {};
|
|
97
|
+
|
|
98
|
+
template <>
|
|
99
|
+
struct local_specialization<name_tag>
|
|
100
|
+
: std::type_identity<class local_for_name> {};
|
|
101
|
+
|
|
102
|
+
template <>
|
|
103
|
+
struct local_specialization<string_tag>
|
|
104
|
+
: std::type_identity<class local_for_string> {};
|
|
105
|
+
|
|
106
|
+
template <>
|
|
107
|
+
struct local_specialization<bigint_tag>
|
|
108
|
+
: std::type_identity<class local_for_bigint> {};
|
|
109
|
+
|
|
110
|
+
template <>
|
|
111
|
+
struct local_specialization<function_tag>
|
|
112
|
+
: std::type_identity<class local_for_function> {};
|
|
113
|
+
|
|
114
|
+
template <>
|
|
115
|
+
struct local_specialization<object_tag>
|
|
116
|
+
: std::type_identity<class local_for_object> {};
|
|
117
|
+
|
|
118
|
+
template <>
|
|
119
|
+
struct local_specialization<record_tag>
|
|
120
|
+
: std::type_identity<class local_for_record> {};
|
|
121
|
+
|
|
122
|
+
template <>
|
|
123
|
+
struct local_specialization<list_tag>
|
|
124
|
+
: std::type_identity<class local_for_array> {};
|
|
125
|
+
|
|
126
|
+
template <>
|
|
127
|
+
struct local_specialization<data_block_tag>
|
|
128
|
+
: std::type_identity<class local_for_data_block> {};
|
|
129
|
+
|
|
130
|
+
template <>
|
|
131
|
+
struct local_specialization<array_buffer_tag>
|
|
132
|
+
: std::type_identity<class local_for_array_buffer> {};
|
|
133
|
+
|
|
134
|
+
template <>
|
|
135
|
+
struct local_specialization<array_buffer_view_tag>
|
|
136
|
+
: std::type_identity<class local_for_array_buffer_view> {};
|
|
137
|
+
|
|
138
|
+
template <>
|
|
139
|
+
struct local_specialization<prototype_tag>
|
|
140
|
+
: std::type_identity<class local_for_prototype> {};
|
|
141
|
+
|
|
142
|
+
} // namespace isolated_vm
|
|
143
|
+
|
|
144
|
+
// Specialize for `js::forward`. Makes `js::forward{local_of<Tag>}` infer
|
|
145
|
+
// `js::forward<Tag, ...>`.
|
|
146
|
+
namespace js {
|
|
147
|
+
template <class Tag>
|
|
148
|
+
struct forward_tag_for<isolated_vm::local_of<Tag>> : std::type_identity<Tag> {};
|
|
149
|
+
} // namespace js
|
package/addon/handle/types.cc
CHANGED
|
@@ -4,13 +4,11 @@ import auto_js;
|
|
|
4
4
|
namespace isolated_vm {
|
|
5
5
|
using namespace js;
|
|
6
6
|
|
|
7
|
-
// `
|
|
8
|
-
class
|
|
9
|
-
protected:
|
|
10
|
-
explicit value_handle(void* value) : value_{value} {}
|
|
11
|
-
|
|
7
|
+
// `runtime_handle` is the base class of `local_of<T>` and `value_of<T>` member types.
|
|
8
|
+
class runtime_handle {
|
|
12
9
|
public:
|
|
13
|
-
|
|
10
|
+
explicit runtime_handle(void* value) : value_{value} {}
|
|
11
|
+
runtime_handle() = default;
|
|
14
12
|
|
|
15
13
|
// Check empty value
|
|
16
14
|
explicit operator bool() const { return value_ != nullptr; }
|
|
@@ -19,138 +17,11 @@ class value_handle {
|
|
|
19
17
|
void* value_{};
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
//
|
|
20
|
+
// Forward declarations for handle types which declare template deduction guides on each other.
|
|
23
21
|
export template <class Tag = value_tag>
|
|
24
|
-
class
|
|
25
|
-
|
|
26
|
-
template <class Tag>
|
|
27
|
-
class value_next;
|
|
28
|
-
|
|
29
|
-
// `bound_value` forward declarations
|
|
30
|
-
export template <class Tag>
|
|
31
|
-
class bound_value;
|
|
32
|
-
|
|
33
|
-
template <class Tag>
|
|
34
|
-
class bound_value_next;
|
|
35
|
-
|
|
36
|
-
template <class Type>
|
|
37
|
-
class bound_value_for_typed_array_of;
|
|
38
|
-
|
|
39
|
-
// Map of `value_of<Tag>` / `bound_value<Tag>` to concrete implementation classes.
|
|
40
|
-
template <class Tag>
|
|
41
|
-
struct value_defaults {
|
|
42
|
-
using bound_type = bound_value_next<Tag>;
|
|
43
|
-
using value_type = value_next<Tag>;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
template <class Tag>
|
|
47
|
-
struct value_specialization : value_defaults<Tag> {};
|
|
48
|
-
|
|
49
|
-
// Typed specializations
|
|
50
|
-
template <>
|
|
51
|
-
struct value_specialization<value_tag> : value_defaults<value_tag> {
|
|
52
|
-
using value_type = class value_for_value;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
template <>
|
|
56
|
-
struct value_specialization<primitive_tag> : value_defaults<primitive_tag> {
|
|
57
|
-
using value_type = class value_for_primitive;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
template <>
|
|
61
|
-
struct value_specialization<undefined_tag> : value_defaults<undefined_tag> {
|
|
62
|
-
using value_type = class value_for_undefined;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
template <>
|
|
66
|
-
struct value_specialization<null_tag> : value_defaults<null_tag> {
|
|
67
|
-
using value_type = class value_for_null;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
template <>
|
|
71
|
-
struct value_specialization<boolean_tag> : value_defaults<boolean_tag> {
|
|
72
|
-
using bound_type = class bound_value_for_boolean;
|
|
73
|
-
using value_type = class value_for_boolean;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
template <>
|
|
77
|
-
struct value_specialization<number_tag> : value_defaults<number_tag> {
|
|
78
|
-
using bound_type = class bound_value_for_number;
|
|
79
|
-
using value_type = class value_for_number;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
template <>
|
|
83
|
-
struct value_specialization<name_tag> : value_defaults<name_tag> {
|
|
84
|
-
using value_type = class value_for_name;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
template <>
|
|
88
|
-
struct value_specialization<string_tag> : value_defaults<string_tag> {
|
|
89
|
-
using bound_type = class bound_value_for_string;
|
|
90
|
-
using value_type = class value_for_string;
|
|
91
|
-
};
|
|
22
|
+
class local_of;
|
|
92
23
|
|
|
93
|
-
template
|
|
94
|
-
|
|
95
|
-
using bound_type = class bound_value_for_bigint;
|
|
96
|
-
using value_type = class value_for_bigint;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
template <>
|
|
100
|
-
struct value_specialization<function_tag> : value_defaults<function_tag> {
|
|
101
|
-
using value_type = class value_for_function;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
template <>
|
|
105
|
-
struct value_specialization<object_tag> : value_defaults<object_tag> {
|
|
106
|
-
using value_type = class value_for_object;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
template <>
|
|
110
|
-
struct value_specialization<record_tag> : value_defaults<record_tag> {
|
|
111
|
-
using bound_type = class bound_value_for_record;
|
|
112
|
-
using value_type = class value_for_record;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
template <>
|
|
116
|
-
struct value_specialization<list_tag> : value_defaults<list_tag> {
|
|
117
|
-
using value_type = class value_for_array;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
template <>
|
|
121
|
-
struct value_specialization<vector_tag> : value_defaults<vector_tag> {
|
|
122
|
-
using bound_type = class bound_value_for_vector;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
template <>
|
|
126
|
-
struct value_specialization<data_block_tag> : value_defaults<data_block_tag> {
|
|
127
|
-
using bound_type = class bound_value_for_data_block;
|
|
128
|
-
using value_type = class value_for_data_block;
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
template <>
|
|
132
|
-
struct value_specialization<array_buffer_tag> : value_defaults<array_buffer_tag> {
|
|
133
|
-
using value_type = class value_for_array_buffer;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
template <>
|
|
137
|
-
struct value_specialization<array_buffer_view_tag> : value_defaults<array_buffer_view_tag> {
|
|
138
|
-
using value_type = class value_for_array_buffer_view;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
template <>
|
|
142
|
-
struct value_specialization<data_view_tag> : value_defaults<data_view_tag> {
|
|
143
|
-
using bound_type = bound_value_for_typed_array_of<void>;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
template <class Type>
|
|
147
|
-
struct value_specialization<typed_array_tag_of<Type>> : value_defaults<typed_array_tag_of<Type>> {
|
|
148
|
-
using bound_type = bound_value_for_typed_array_of<Type>;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
template <>
|
|
152
|
-
struct value_specialization<prototype_tag> : value_defaults<prototype_tag> {
|
|
153
|
-
using value_type = class value_for_prototype;
|
|
154
|
-
};
|
|
24
|
+
export template <class Tag = value_tag>
|
|
25
|
+
class value_of;
|
|
155
26
|
|
|
156
27
|
} // namespace isolated_vm
|
package/addon/handle/value_of.cc
CHANGED
|
@@ -1,47 +1,102 @@
|
|
|
1
1
|
export module isolated_vm:handle.value_of;
|
|
2
|
-
|
|
2
|
+
import :handle.types;
|
|
3
|
+
import :support.lock_fwd;
|
|
3
4
|
import auto_js;
|
|
4
5
|
import std;
|
|
5
6
|
|
|
6
7
|
namespace isolated_vm {
|
|
7
8
|
using namespace js;
|
|
8
9
|
|
|
9
|
-
//
|
|
10
|
+
// Map of `value_of<Tag>` to concrete implementation classes.
|
|
10
11
|
template <class Tag>
|
|
11
|
-
|
|
12
|
+
struct value_specialization;
|
|
13
|
+
|
|
14
|
+
// Member & method implementation for stateful objects. Used internally in visitors.
|
|
15
|
+
template <class Tag>
|
|
16
|
+
class value_of : public value_specialization<Tag>::type {
|
|
12
17
|
public:
|
|
13
|
-
using
|
|
18
|
+
using value_type = value_specialization<Tag>::type;
|
|
19
|
+
using value_type::value_type;
|
|
20
|
+
};
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
// Sentinel instantiation
|
|
23
|
+
template <>
|
|
24
|
+
class value_of<void> : public runtime_handle {
|
|
25
|
+
protected:
|
|
26
|
+
value_of() = default;
|
|
27
|
+
value_of(const runtime_lock& lock, runtime_handle value) :
|
|
28
|
+
runtime_handle{value},
|
|
29
|
+
lock_{&lock} {}
|
|
18
30
|
|
|
19
|
-
|
|
20
|
-
static auto from(value_handle value_) -> value_of<Tag> { return std::bit_cast<value_of<Tag>>(value_); }
|
|
21
|
-
};
|
|
31
|
+
[[nodiscard]] auto lock() const -> const runtime_lock& { return *lock_; }
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class value_of : public value_specialization<Tag>::value_type {
|
|
26
|
-
public:
|
|
27
|
-
using value_specialization<Tag>::value_type::value_type;
|
|
33
|
+
private:
|
|
34
|
+
const runtime_lock* lock_{};
|
|
28
35
|
};
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
// Deduction guide
|
|
38
|
+
template <class Tag>
|
|
39
|
+
value_of(auto, local_of<Tag>) -> value_of<Tag>;
|
|
32
40
|
|
|
33
|
-
//
|
|
34
|
-
template
|
|
35
|
-
class
|
|
41
|
+
// Details applied to each level of the `value_of<T>` hierarchy.
|
|
42
|
+
template <class Tag>
|
|
43
|
+
class value_next : public value_of<typename Tag::tag_type> {
|
|
36
44
|
public:
|
|
37
|
-
using
|
|
45
|
+
using tag_type = Tag;
|
|
46
|
+
|
|
47
|
+
value_next() = default;
|
|
48
|
+
value_next(auto&& lock, local_of<Tag> value, auto&&... rest) :
|
|
49
|
+
value_of<typename Tag::tag_type>{std::forward<decltype(lock)>(lock), value, std::forward<decltype(rest)>(rest)...} {}
|
|
50
|
+
|
|
51
|
+
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
52
|
+
operator local_of<Tag>() const { return local_of<Tag>::from(runtime_handle{*this}); }
|
|
38
53
|
};
|
|
39
54
|
|
|
40
|
-
|
|
55
|
+
// `value_of<Tag>` specializations.
|
|
56
|
+
template <class Type> class value_for_typed_array_of;
|
|
41
57
|
|
|
42
|
-
// Specialize for `js::forward`. Makes `js::forward{value_of<Tag>}` infer
|
|
43
|
-
// `js::forward<Tag, ...>`.
|
|
44
|
-
namespace js {
|
|
45
58
|
template <class Tag>
|
|
46
|
-
struct
|
|
47
|
-
|
|
59
|
+
struct value_specialization
|
|
60
|
+
: std::type_identity<value_next<Tag>> {};
|
|
61
|
+
|
|
62
|
+
template <>
|
|
63
|
+
struct value_specialization<void>
|
|
64
|
+
: std::type_identity<value_of<void>> {};
|
|
65
|
+
|
|
66
|
+
template <>
|
|
67
|
+
struct value_specialization<boolean_tag>
|
|
68
|
+
: std::type_identity<class value_for_boolean> {};
|
|
69
|
+
|
|
70
|
+
template <>
|
|
71
|
+
struct value_specialization<number_tag>
|
|
72
|
+
: std::type_identity<class value_for_number> {};
|
|
73
|
+
|
|
74
|
+
template <>
|
|
75
|
+
struct value_specialization<string_tag>
|
|
76
|
+
: std::type_identity<class value_for_string> {};
|
|
77
|
+
|
|
78
|
+
template <>
|
|
79
|
+
struct value_specialization<bigint_tag>
|
|
80
|
+
: std::type_identity<class value_for_bigint> {};
|
|
81
|
+
|
|
82
|
+
template <>
|
|
83
|
+
struct value_specialization<record_tag>
|
|
84
|
+
: std::type_identity<class value_for_record> {};
|
|
85
|
+
|
|
86
|
+
template <>
|
|
87
|
+
struct value_specialization<vector_tag>
|
|
88
|
+
: std::type_identity<class value_for_vector> {};
|
|
89
|
+
|
|
90
|
+
template <>
|
|
91
|
+
struct value_specialization<data_block_tag>
|
|
92
|
+
: std::type_identity<class value_for_data_block> {};
|
|
93
|
+
|
|
94
|
+
template <class Type>
|
|
95
|
+
struct value_specialization<typed_array_tag_of<Type>>
|
|
96
|
+
: std::type_identity<value_for_typed_array_of<Type>> {};
|
|
97
|
+
|
|
98
|
+
template <>
|
|
99
|
+
struct value_specialization<data_view_tag>
|
|
100
|
+
: std::type_identity<class value_for_data_view> {};
|
|
101
|
+
|
|
102
|
+
} // namespace isolated_vm
|
|
@@ -2,7 +2,7 @@ module;
|
|
|
2
2
|
#include "auto_js/export_tag.h"
|
|
3
3
|
#include <cassert>
|
|
4
4
|
export module isolated_vm:support.callback_info_fwd;
|
|
5
|
-
import :handle.
|
|
5
|
+
import :handle.local_of;
|
|
6
6
|
import :value.primitive;
|
|
7
7
|
import auto_js;
|
|
8
8
|
import std;
|
|
@@ -16,7 +16,7 @@ class EXPORT callback_info {
|
|
|
16
16
|
|
|
17
17
|
public:
|
|
18
18
|
class iterator;
|
|
19
|
-
using value_type =
|
|
19
|
+
using value_type = local_of<>;
|
|
20
20
|
|
|
21
21
|
[[nodiscard]] constexpr auto begin() const -> iterator;
|
|
22
22
|
[[nodiscard]] constexpr auto end() const -> iterator;
|
|
@@ -73,11 +73,11 @@ using namespace isolated_vm;
|
|
|
73
73
|
|
|
74
74
|
// `arguments` visitor
|
|
75
75
|
template <>
|
|
76
|
-
struct visit_subject_for<callback_info> : visit_subject_for<
|
|
76
|
+
struct visit_subject_for<callback_info> : visit_subject_for<local_of<>> {};
|
|
77
77
|
|
|
78
78
|
template <class Meta>
|
|
79
|
-
struct visit<Meta, callback_info> : visit<Meta,
|
|
80
|
-
using visit_type = visit<Meta,
|
|
79
|
+
struct visit<Meta, callback_info> : visit<Meta, local_of<>> {
|
|
80
|
+
using visit_type = visit<Meta, local_of<>>;
|
|
81
81
|
using visit_type::visit_type;
|
|
82
82
|
|
|
83
83
|
using visit_type::operator();
|
|
@@ -10,7 +10,7 @@ import util;
|
|
|
10
10
|
namespace isolated_vm {
|
|
11
11
|
using namespace js;
|
|
12
12
|
|
|
13
|
-
using runtime_callback_type = auto (*)(const runtime_lock&, callback_info, const void*) ->
|
|
13
|
+
using runtime_callback_type = auto (*)(const runtime_lock&, callback_info, const void*) -> local_of<>;
|
|
14
14
|
using runtime_callback_finalizer_type = auto (*)(void*) -> void;
|
|
15
15
|
|
|
16
16
|
using runtime_callback_data_span_type = std::span<std::byte>;
|
|
@@ -42,7 +42,7 @@ const auto max_callback_storage_size = sizeof(runtime_callback_function_storage<
|
|
|
42
42
|
auto make_callback_storage(std::invocable<const runtime_lock&, callback_info> auto function) {
|
|
43
43
|
using function_type = decltype(function);
|
|
44
44
|
using data_type = runtime_callback_function_storage<function_type>;
|
|
45
|
-
constexpr auto callback = runtime_callback_type{[](const runtime_lock& lock, callback_info info, const void* data) ->
|
|
45
|
+
constexpr auto callback = runtime_callback_type{[](const runtime_lock& lock, callback_info info, const void* data) -> local_of<> {
|
|
46
46
|
const auto& storage = *static_cast<const data_type*>(data);
|
|
47
47
|
return storage.function(lock, info);
|
|
48
48
|
}};
|
|
@@ -15,8 +15,8 @@ constexpr auto make_free_function(auto function) {
|
|
|
15
15
|
) -> auto {
|
|
16
16
|
using callback_type = decltype(callback);
|
|
17
17
|
auto bound_function = util::bind{
|
|
18
|
-
[](const callback_type& callback, Lock lock, callback_info info) noexcept(Nx) ->
|
|
19
|
-
auto run = util::regular_return{[ & ]
|
|
18
|
+
[](const callback_type& callback, Lock lock, callback_info info) noexcept(Nx) -> local_of<> {
|
|
19
|
+
auto run = util::regular_return{[ & ] -> decltype(auto) {
|
|
20
20
|
return std::apply(
|
|
21
21
|
callback,
|
|
22
22
|
std::tuple_cat(
|
|
@@ -25,7 +25,7 @@ constexpr auto make_free_function(auto function) {
|
|
|
25
25
|
)
|
|
26
26
|
);
|
|
27
27
|
}};
|
|
28
|
-
return js::transfer_in_strict<
|
|
28
|
+
return js::transfer_in_strict<local_of<>>(run().value_or(std::monostate{}), lock);
|
|
29
29
|
},
|
|
30
30
|
std::move(callback),
|
|
31
31
|
};
|
|
@@ -9,7 +9,7 @@ import util;
|
|
|
9
9
|
namespace isolated_vm {
|
|
10
10
|
export namespace detail {
|
|
11
11
|
using make_addon_names = auto() -> std::vector<std::u16string>;
|
|
12
|
-
using accept_addon_values = auto(std::span<
|
|
12
|
+
using accept_addon_values = auto(std::span<local_of<prototype_tag>>) -> void;
|
|
13
13
|
using initialize_addon = auto(const basic_lock&, util::function_ref<accept_addon_values>) -> void;
|
|
14
14
|
} // namespace detail
|
|
15
15
|
|
|
@@ -30,7 +30,7 @@ template <std::size_t Index>
|
|
|
30
30
|
consteval auto get_descriptors(std::integral_constant<std::size_t, Index> /*index*/, auto ns) {
|
|
31
31
|
return util::overloaded{
|
|
32
32
|
[]<class... Types>(std::tuple<std::in_place_t, Types...> ns) {
|
|
33
|
-
auto [... ii ] = util::sequence<sizeof...(Types)>;
|
|
33
|
+
constexpr auto [... ii ] = util::sequence<sizeof...(Types)>;
|
|
34
34
|
auto [... entries ] = std::make_tuple(std::get<ii + 1>(ns)...);
|
|
35
35
|
return std::make_tuple(std::get<Index>(entries)...);
|
|
36
36
|
},
|
|
@@ -46,10 +46,10 @@ addon::addon(std::type_identity<Type> /*environment*/, auto callback) {
|
|
|
46
46
|
using callback_type = decltype(callback);
|
|
47
47
|
static_assert(std::is_empty_v<callback_type>);
|
|
48
48
|
|
|
49
|
-
constexpr auto make_names = []
|
|
49
|
+
constexpr auto make_names = [] -> std::vector<std::u16string> {
|
|
50
50
|
constexpr auto names = get_descriptors(std::integral_constant<std::size_t, 0>{}, callback_type{}());
|
|
51
51
|
// Check for duplicates (only at compile time)
|
|
52
|
-
static_assert([ names ]
|
|
52
|
+
static_assert([ names ] {
|
|
53
53
|
auto [... names_cw ] = names;
|
|
54
54
|
auto names_vector = std::vector{js::transfer_strict<std::u16string>(names_cw)...};
|
|
55
55
|
for (auto ii = names_vector.begin(); ii != names_vector.end(); ++ii) {
|
|
@@ -67,7 +67,7 @@ addon::addon(std::type_identity<Type> /*environment*/, auto callback) {
|
|
|
67
67
|
constexpr auto make_exports = [](const basic_lock& lock, util::function_ref<detail::accept_addon_values> make) -> void {
|
|
68
68
|
constexpr auto values = get_descriptors(std::integral_constant<std::size_t, 1>{}, callback_type{}());
|
|
69
69
|
constexpr auto size = std::tuple_size_v<decltype(values)>;
|
|
70
|
-
auto vm_values = js::transfer_in_strict<std::array<
|
|
70
|
+
auto vm_values = js::transfer_in_strict<std::array<local_of<prototype_tag>, size>>(values, lock);
|
|
71
71
|
make(std::span{vm_values});
|
|
72
72
|
};
|
|
73
73
|
register_addon(make_names, make_exports);
|