@auto_js/v8 0.0.5 → 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/CMakeLists.txt CHANGED
@@ -1,25 +1,20 @@
1
+ # Locate dependencies
1
2
  find_package(Boost 1.83 REQUIRED)
2
- if(PACKAGE_NAME STREQUAL "@auto_js/v8")
3
- set(TARGET_NAME "v8_js")
4
- find_package_from_npm(@auto_js/v8_exports)
5
- elseif(PACKAGE_NAME STREQUAL "@isolated-vm/embedded_v8_js")
6
- set(TARGET_NAME "embedded_v8_js")
7
- find_package_from_npm(@auto_js/v8_exports @isolated-vm/embedded_v8)
8
- else()
9
- message(FATAL_ERROR "Missing or unknown @auto_js/v8 PACKAGE_NAME: '${PACKAGE_NAME}'")
10
- endif()
11
- find_package_from_npm(@auto_js/js)
3
+ find_package_from_npm(@auto_js/v8_exports AS @auto_js/${AUTO_JS_PREFIX}v8_exports PROPAGATE google_v8)
4
+ find_package_from_npm(@auto_js/js AS @auto_js/${AUTO_JS_PREFIX}js PROPAGATE auto_js)
12
5
 
13
- add_library("${TARGET_NAME}" OBJECT)
14
- target_link_libraries("${TARGET_NAME}" PUBLIC Boost::boost auto_js utility_js)
15
- if(TARGET_NAME STREQUAL "v8_js")
16
- target_link_libraries("${TARGET_NAME}" PUBLIC nodejs_v8)
17
- else()
18
- target_compile_definitions("${TARGET_NAME}" PRIVATE INCLUDE_ISOLATED_V8)
19
- target_link_libraries("${TARGET_NAME}" PUBLIC google_v8)
20
- endif()
6
+ # Initialize target [v8_js or v8_isolated_js]
7
+ set(v8_js ${AUTO_JS_PREFIX}v8_js)
8
+ add_library(${v8_js} STATIC)
9
+ set_npm_package_properties(@auto_js/v8 auto_js v8_js)
10
+ target_compile_features(${auto_js} PUBLIC cxx_std_23)
11
+
12
+ # Link dependencies
13
+ target_link_libraries(${v8_js} PRIVATE Boost::boost ${auto_js} utility_js)
14
+ target_link_libraries(${v8_js} PUBLIC ${google_v8})
21
15
 
22
- target_sources("${TARGET_NAME}"
16
+ # Common sources (nodejs + iv8::isolated)
17
+ target_sources(${v8_js}
23
18
  PRIVATE
24
19
  handle/remote.cc
25
20
  support/error.cc
@@ -58,8 +53,10 @@ target_sources("${TARGET_NAME}"
58
53
  value/value.cc
59
54
  )
60
55
 
61
- if(TARGET_NAME STREQUAL "embedded_v8_js")
62
- target_sources("${TARGET_NAME}"
56
+ # iv8::isolated sources
57
+ if(v8_js STREQUAL isolated_v8_js)
58
+ target_compile_definitions(${v8_js} PRIVATE INCLUDE_ISOLATED_V8)
59
+ target_sources(${v8_js}
63
60
  PRIVATE
64
61
  evaluation/module.cc
65
62
  evaluation/script.cc
@@ -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.5",
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.5",
9
- "@auto_js/v8_exports": "^0.0.3"
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::Data>{};
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 = v8::External::New(lock.isolate(), std::bit_cast<void*>(bound));
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 = std::bit_cast<bound_type>(info.Data().As<v8::External>()->Value());
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> info, const Accept& accept) -> accept_target_t<Accept> {
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
  };
@@ -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 = std::monostate>
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 = std::monostate>
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>;
@@ -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::WriteOptions::NO_NULL_TERMINATION);
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::WriteOptions::NO_NULL_TERMINATION);
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