@auto_js/v8 0.0.6 → 0.0.7
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/handle/collected_handle.cc +12 -1
- package/package.json +3 -3
- package/support/callback_storage.cc +18 -3
- package/transfer/visit.cc +1 -1
- package/value/fixed_array.cc +6 -0
- package/value/function.cc +2 -2
- package/value/primitive.cc +9 -2
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
module;
|
|
2
|
+
#include <v8/version.h>
|
|
1
3
|
export module v8_js:collected_handle;
|
|
2
4
|
import :lock;
|
|
3
5
|
import std;
|
|
@@ -64,7 +66,7 @@ auto collected_handle<Value, Type>::reset(const collected_handle_lock& lock, uni
|
|
|
64
66
|
[](const v8::WeakCallbackInfo<collected_handle>& data) -> auto {
|
|
65
67
|
auto* ptr = data.GetParameter();
|
|
66
68
|
auto unique = ptr->pool_.get().reacquire(ptr);
|
|
67
|
-
unique->global_.ClearWeak();
|
|
69
|
+
unique->global_.template ClearWeak<void>();
|
|
68
70
|
},
|
|
69
71
|
v8::WeakCallbackType::kParameter
|
|
70
72
|
);
|
|
@@ -74,7 +76,11 @@ auto collected_handle<Value, Type>::reset(const collected_handle_lock& lock, uni
|
|
|
74
76
|
export template <class Type>
|
|
75
77
|
auto make_collected_external(const collected_handle_lock& lock, auto&&... args) -> v8::Local<v8::External> {
|
|
76
78
|
auto unique = collected_external_of<Type>::make(lock, std::forward<decltype(args)>(args)...);
|
|
79
|
+
#if V8_HAS_TAGGED_EXTERNAL
|
|
80
|
+
auto value = v8::External::New(lock.isolate(), unique.get(), 0);
|
|
81
|
+
#else
|
|
77
82
|
auto value = v8::External::New(lock.isolate(), unique.get());
|
|
83
|
+
#endif
|
|
78
84
|
collected_handle<v8::External, Type>::reset(lock, std::move(unique), value);
|
|
79
85
|
return value;
|
|
80
86
|
}
|
|
@@ -82,7 +88,12 @@ auto make_collected_external(const collected_handle_lock& lock, auto&&... args)
|
|
|
82
88
|
export template <class Type>
|
|
83
89
|
auto unwrap_collected_external(v8::Local<v8::External> external) -> Type& {
|
|
84
90
|
using handle_type = collected_external_of<Type>;
|
|
91
|
+
#if V8_HAS_TAGGED_EXTERNAL
|
|
92
|
+
// TODO: Use this feature
|
|
93
|
+
return **static_cast<handle_type*>(external->Value(0));
|
|
94
|
+
#else
|
|
85
95
|
return **static_cast<handle_type*>(external->Value());
|
|
96
|
+
#endif
|
|
86
97
|
}
|
|
87
98
|
|
|
88
99
|
} // namespace js::iv8
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auto_js/v8",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"author": "https://github.com/laverdet/",
|
|
5
5
|
"homepage": "https://github.com/laverdet/isolated-vm/tree/experimental/packages/auto_js/v8",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@auto_js/js": "^0.0.
|
|
9
|
-
"@auto_js/v8_exports": "^0.0.
|
|
8
|
+
"@auto_js/js": "^0.0.7",
|
|
9
|
+
"@auto_js/v8_exports": "^0.0.5"
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
module;
|
|
2
|
+
#include <v8/version.h>
|
|
1
3
|
export module v8_js:callback_storage;
|
|
2
4
|
import :collected_handle;
|
|
3
5
|
import :unmaybe;
|
|
@@ -71,7 +73,7 @@ auto make_callback_storage(const auto& lock, auto function) {
|
|
|
71
73
|
static_assert(std::is_trivially_destructible_v<bound_type>);
|
|
72
74
|
if constexpr (std::is_empty_v<bound_type>) {
|
|
73
75
|
// Constant expression function of 0 size. No data needed at all!
|
|
74
|
-
auto data = v8::Local<v8::
|
|
76
|
+
auto data = v8::Local<v8::Value>{};
|
|
75
77
|
const auto callback = v8::FunctionCallback{[](const v8::FunctionCallbackInfo<v8::Value>& info) -> void {
|
|
76
78
|
auto invoke = bound_type{};
|
|
77
79
|
invoke(info);
|
|
@@ -79,9 +81,22 @@ auto make_callback_storage(const auto& lock, auto function) {
|
|
|
79
81
|
return std::tuple{callback, data};
|
|
80
82
|
} else if constexpr (sizeof(bound_type) == sizeof(void*)) {
|
|
81
83
|
// Trivial function of pointer type. Data() is the function data.
|
|
82
|
-
auto data =
|
|
84
|
+
auto data = [ & ]() -> auto {
|
|
85
|
+
#if V8_HAS_TAGGED_EXTERNAL
|
|
86
|
+
return v8::External::New(lock.isolate(), std::bit_cast<void*>(bound), 0);
|
|
87
|
+
#else
|
|
88
|
+
return v8::External::New(lock.isolate(), std::bit_cast<void*>(bound));
|
|
89
|
+
#endif
|
|
90
|
+
}();
|
|
83
91
|
const auto callback = v8::FunctionCallback{[](const v8::FunctionCallbackInfo<v8::Value>& info) -> void {
|
|
84
|
-
auto invoke =
|
|
92
|
+
auto invoke = [ & ]() -> auto {
|
|
93
|
+
#if V8_HAS_TAGGED_EXTERNAL
|
|
94
|
+
// TODO: Use this feature
|
|
95
|
+
return std::bit_cast<bound_type>(info.Data().As<v8::External>()->Value(0));
|
|
96
|
+
#else
|
|
97
|
+
return std::bit_cast<bound_type>(info.Data().As<v8::External>()->Value());
|
|
98
|
+
#endif
|
|
99
|
+
}();
|
|
85
100
|
invoke(info);
|
|
86
101
|
}};
|
|
87
102
|
return std::tuple{callback, data};
|
package/transfer/visit.cc
CHANGED
|
@@ -486,7 +486,7 @@ struct visit<Meta, v8::FunctionCallbackInfo<v8::Value>> : visit<Meta, v8::Local<
|
|
|
486
486
|
using visit_type::operator();
|
|
487
487
|
|
|
488
488
|
template <class Accept>
|
|
489
|
-
auto operator()(v8::FunctionCallbackInfo<v8::Value
|
|
489
|
+
auto operator()(const v8::FunctionCallbackInfo<v8::Value>& info, const Accept& accept) -> accept_target_t<Accept> {
|
|
490
490
|
return accept(vector_tag{}, *this, iv8::callback_info{info});
|
|
491
491
|
}
|
|
492
492
|
};
|
package/value/fixed_array.cc
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
module;
|
|
2
|
+
#include <v8/version.h>
|
|
1
3
|
module v8_js;
|
|
2
4
|
import v8;
|
|
3
5
|
|
|
@@ -25,7 +27,11 @@ fixed_array::iterator::iterator(v8::Local<v8::FixedArray> array, v8::Local<v8::C
|
|
|
25
27
|
index_{index} {}
|
|
26
28
|
|
|
27
29
|
auto fixed_array::iterator::operator*() const -> value_type {
|
|
30
|
+
#if V8_HAS_CONTEXT_FREE_FIXED_ARRAY
|
|
31
|
+
return array_->Get(index_);
|
|
32
|
+
#else
|
|
28
33
|
return array_->Get(context_, index_);
|
|
34
|
+
#endif
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
auto fixed_array::iterator::operator+=(difference_type offset) -> iterator& {
|
package/value/function.cc
CHANGED
|
@@ -8,7 +8,7 @@ import v8;
|
|
|
8
8
|
|
|
9
9
|
namespace js::iv8 {
|
|
10
10
|
|
|
11
|
-
template <class Result
|
|
11
|
+
template <class Result>
|
|
12
12
|
auto Function::apply(context_lock_witness lock, auto&& args) -> Result {
|
|
13
13
|
auto result = [ & ]() {
|
|
14
14
|
using args_type = std::vector<v8::Local<v8::Value>>;
|
|
@@ -21,7 +21,7 @@ auto Function::apply(context_lock_witness lock, auto&& args) -> Result {
|
|
|
21
21
|
return js::transfer_out<Result>(result, lock);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
template <class Result
|
|
24
|
+
template <class Result>
|
|
25
25
|
auto Function::call(context_lock_witness lock, auto&&... args) -> Result {
|
|
26
26
|
auto result = [ & ]() {
|
|
27
27
|
using args_type = std::array<v8::Local<v8::Value>, sizeof...(args) + 1>;
|
package/value/primitive.cc
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
module;
|
|
2
|
+
#include <v8/version.h>
|
|
1
3
|
module v8_js;
|
|
2
4
|
import :primitive;
|
|
3
5
|
import std;
|
|
@@ -42,7 +44,7 @@ value_for_string::operator std::string() const {
|
|
|
42
44
|
string.resize_and_overwrite((*this)->Length(), [ this ](char* data, std::size_t length) -> std::size_t {
|
|
43
45
|
if (length > 0) {
|
|
44
46
|
auto* data_uint8 = reinterpret_cast<std::uint8_t*>(data);
|
|
45
|
-
(*this)->WriteOneByteV2(isolate(), 0, length, data_uint8, v8::String::
|
|
47
|
+
(*this)->WriteOneByteV2(isolate(), 0, length, data_uint8, v8::String::WriteFlags::kNone);
|
|
46
48
|
}
|
|
47
49
|
return length;
|
|
48
50
|
});
|
|
@@ -54,7 +56,7 @@ value_for_string::operator std::u16string() const {
|
|
|
54
56
|
string.resize_and_overwrite((*this)->Length(), [ this ](char16_t* data, std::size_t length) -> std::size_t {
|
|
55
57
|
if (length > 0) {
|
|
56
58
|
auto* data_uint16 = reinterpret_cast<std::uint16_t*>(data);
|
|
57
|
-
(*this)->WriteV2(isolate(), 0, length, data_uint16, v8::String::
|
|
59
|
+
(*this)->WriteV2(isolate(), 0, length, data_uint16, v8::String::WriteFlags::kNone);
|
|
58
60
|
}
|
|
59
61
|
return length;
|
|
60
62
|
});
|
|
@@ -68,7 +70,12 @@ value_for_date::operator js_clock::time_point() const {
|
|
|
68
70
|
|
|
69
71
|
// `value_for_external`
|
|
70
72
|
value_for_external::operator void*() const {
|
|
73
|
+
#if V8_HAS_TAGGED_EXTERNAL
|
|
74
|
+
// TODO: Use this feature
|
|
75
|
+
return (*this)->Value(0);
|
|
76
|
+
#else
|
|
71
77
|
return (*this)->Value();
|
|
78
|
+
#endif
|
|
72
79
|
}
|
|
73
80
|
|
|
74
81
|
} // namespace js::iv8
|