Skip to content

Commit

Permalink
Update v8 version to 12.1.285.27 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
MeirShpilraien authored Jan 29, 2024
1 parent 6994936 commit 73979d1
Show file tree
Hide file tree
Showing 25 changed files with 631 additions and 232 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ lazy_static::lazy_static! {

static ref PROFILE: String = env::var("PROFILE").expect("PROFILE env var was not given");

static ref V8_DEFAULT_VERSION: &'static str = "12.0.267.17";
static ref V8_DEFAULT_VERSION: &'static str = "12.1.285.27";
static ref V8_VERSION: String = env::var("V8_VERSION").map(|v| if v == "default" {V8_DEFAULT_VERSION.to_string()} else {v}).unwrap_or(V8_DEFAULT_VERSION.to_string());
static ref V8_HEADERS_PATH: String = env::var("V8_HEADERS_PATH").unwrap_or("v8_c_api/libv8.include.zip".into());
static ref V8_HEADERS_URL: String = env::var("V8_HEADERS_URL").unwrap_or(format!("http://redismodules.s3.amazonaws.com/redisgears/dependencies/libv8.{}.include.zip", *V8_VERSION));
Expand Down
18 changes: 18 additions & 0 deletions v8_c_api/src/v8include/v8-container.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <stddef.h>
#include <stdint.h>

#include <functional>

#include "v8-local-handle.h" // NOLINT(build/include_directory)
#include "v8-object.h" // NOLINT(build/include_directory)
#include "v8config.h" // NOLINT(build/include_directory)
Expand Down Expand Up @@ -43,6 +45,22 @@ class V8_EXPORT Array : public Object {
return static_cast<Array*>(value);
}

/**
* Creates a JavaScript array from a provided callback.
*
* \param context The v8::Context to create the array in.
* \param length The length of the array to be created.
* \param next_value_callback The callback that is invoked to retrieve
* elements for the array. The embedder can signal that the array
* initialization should be aborted by throwing an exception and returning
* an empty MaybeLocal.
* \returns The v8::Array if all elements were constructed successfully and an
* empty MaybeLocal otherwise.
*/
static MaybeLocal<Array> New(
Local<Context> context, size_t length,
std::function<MaybeLocal<v8::Value>()> next_value_callback);

enum class CallbackResult {
kException,
kBreak,
Expand Down
4 changes: 4 additions & 0 deletions v8_c_api/src/v8include/v8-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,16 @@ class V8_EXPORT Context : public Data {
* Returns the value that was set or restored by
* SetContinuationPreservedEmbedderData(), if any.
*/
V8_DEPRECATE_SOON(
"Use v8::Isolate::GetContinuationPreservedEmbedderData instead")
Local<Value> GetContinuationPreservedEmbedderData() const;

/**
* Sets a value that will be stored on continuations and reset while the
* continuation runs.
*/
V8_DEPRECATE_SOON(
"Use v8::Isolate::SetContinuationPreservedEmbedderData instead")
void SetContinuationPreservedEmbedderData(Local<Value> context);

/**
Expand Down
18 changes: 18 additions & 0 deletions v8_c_api/src/v8include/v8-embedder-heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "v8config.h" // NOLINT(build/include_directory)

namespace v8 {
namespace internal {
class TracedHandles;
} // namespace internal

class Isolate;
class Value;
Expand All @@ -18,8 +21,17 @@ class Value;
*/
class V8_EXPORT EmbedderRootsHandler {
public:
enum class RootHandling {
kQueryEmbedderForNonDroppableReferences,
kDontQueryEmbedderForAnyReference,
};

virtual ~EmbedderRootsHandler() = default;

EmbedderRootsHandler() = default;
explicit EmbedderRootsHandler(RootHandling default_traced_reference_handling)
: default_traced_reference_handling_(default_traced_reference_handling) {}

/**
* Returns true if the |TracedReference| handle should be considered as root
* for the currently running non-tracing garbage collection and false
Expand Down Expand Up @@ -59,6 +71,12 @@ class V8_EXPORT EmbedderRootsHandler {
ResetRoot(handle);
return true;
}

private:
const RootHandling default_traced_reference_handling_ =
RootHandling::kQueryEmbedderForNonDroppableReferences;

friend class internal::TracedHandles;
};

} // namespace v8
Expand Down
3 changes: 2 additions & 1 deletion v8_c_api/src/v8include/v8-embedder-state-scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

#include <memory>

#include "v8-context.h" // NOLINT(build/include_directory)
#include "v8-internal.h" // NOLINT(build/include_directory)
#include "v8-local-handle.h" // NOLINT(build/include_directory)

namespace v8 {

class Context;

namespace internal {
class EmbedderState;
} // namespace internal
Expand Down
1 change: 0 additions & 1 deletion v8_c_api/src/v8include/v8-exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class V8_EXPORT TryCatch {
bool can_continue_ : 1;
bool capture_message_ : 1;
bool rethrow_ : 1;
bool has_terminated_ : 1;

friend class internal::Isolate;
friend class internal::ThreadLocalTop;
Expand Down
58 changes: 33 additions & 25 deletions v8_c_api/src/v8include/v8-fast-api-calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ class CTypeInfo {
// migrated from v8::ApiObject to v8::Local<v8::Value>.
kAny, // This is added to enable untyped representation of fast
// call arguments for test purposes. It can represent any of
// the other types stored in the same memory as a union (see
// the AnyCType struct declared below). This allows for
// the other types stored in the same memory as a union
// (see AnyCType declared below). This allows for
// uniform passing of arguments w.r.t. their location
// (in a register or on the stack), independent of their
// actual type. It's currently used by the arm64 simulator
Expand Down Expand Up @@ -435,35 +435,43 @@ class V8_EXPORT CFunctionInfo {
struct FastApiCallbackOptions;

// Provided for testing.
struct AnyCType {
union V8_TRIVIAL_ABI AnyCType {
AnyCType() : int64_value(0) {}

union {
bool bool_value;
int32_t int32_value;
uint32_t uint32_value;
int64_t int64_value;
uint64_t uint64_value;
float float_value;
double double_value;
void* pointer_value;
Local<Object> object_value;
Local<Array> sequence_value;
const FastApiTypedArray<uint8_t>* uint8_ta_value;
const FastApiTypedArray<int32_t>* int32_ta_value;
const FastApiTypedArray<uint32_t>* uint32_ta_value;
const FastApiTypedArray<int64_t>* int64_ta_value;
const FastApiTypedArray<uint64_t>* uint64_ta_value;
const FastApiTypedArray<float>* float_ta_value;
const FastApiTypedArray<double>* double_ta_value;
const FastOneByteString* string_value;
FastApiCallbackOptions* options_value;
};
#if defined(V8_ENABLE_LOCAL_OFF_STACK_CHECK) && V8_HAS_ATTRIBUTE_TRIVIAL_ABI
// In this case, Local<T> is not trivially copyable and the implicit
// copy constructor and copy assignment for the union are deleted.
AnyCType(const AnyCType& other) : int64_value(other.int64_value) {}
AnyCType& operator=(const AnyCType& other) {
int64_value = other.int64_value;
return *this;
}
#endif

bool bool_value;
int32_t int32_value;
uint32_t uint32_value;
int64_t int64_value;
uint64_t uint64_value;
float float_value;
double double_value;
void* pointer_value;
Local<Object> object_value;
Local<Array> sequence_value;
const FastApiTypedArray<uint8_t>* uint8_ta_value;
const FastApiTypedArray<int32_t>* int32_ta_value;
const FastApiTypedArray<uint32_t>* uint32_ta_value;
const FastApiTypedArray<int64_t>* int64_ta_value;
const FastApiTypedArray<uint64_t>* uint64_ta_value;
const FastApiTypedArray<float>* float_ta_value;
const FastApiTypedArray<double>* double_ta_value;
const FastOneByteString* string_value;
FastApiCallbackOptions* options_value;
};

static_assert(
sizeof(AnyCType) == 8,
"The AnyCType struct should have size == 64 bits, as this is assumed "
"The union AnyCType should have size == 64 bits, as this is assumed "
"by EffectControlLinearizer.");

class V8_EXPORT CFunction {
Expand Down
50 changes: 50 additions & 0 deletions v8_c_api/src/v8include/v8-function-callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#ifndef INCLUDE_V8_FUNCTION_CALLBACK_H_
#define INCLUDE_V8_FUNCTION_CALLBACK_H_

#include <cstdint>
#include <limits>

#include "v8-local-handle.h" // NOLINT(build/include_directory)
#include "v8-primitive.h" // NOLINT(build/include_directory)
#include "v8config.h" // NOLINT(build/include_directory)
Expand Down Expand Up @@ -39,14 +42,21 @@ class ReturnValue {
template <typename S>
V8_INLINE void Set(const Global<S>& handle);
template <typename S>
V8_INLINE void SetNonEmpty(const Global<S>& handle);
template <typename S>
V8_INLINE void Set(const BasicTracedReference<S>& handle);
template <typename S>
V8_INLINE void SetNonEmpty(const BasicTracedReference<S>& handle);
template <typename S>
V8_INLINE void Set(const Local<S> handle);
template <typename S>
V8_INLINE void SetNonEmpty(const Local<S> handle);
// Fast primitive setters
V8_INLINE void Set(bool value);
V8_INLINE void Set(double i);
V8_INLINE void Set(int32_t i);
V8_INLINE void Set(uint32_t i);
V8_INLINE void Set(uint16_t);
// Fast JS primitive setters
V8_INLINE void SetNull();
V8_INLINE void SetUndefined();
Expand Down Expand Up @@ -287,6 +297,16 @@ void ReturnValue<T>::Set(const Global<S>& handle) {
}
}

template <typename T>
template <typename S>
void ReturnValue<T>::SetNonEmpty(const Global<S>& handle) {
static_assert(std::is_base_of<T, S>::value, "type check");
#ifdef V8_ENABLE_CHECKS
internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
#endif // V8_ENABLE_CHECKS
*value_ = handle.ptr();
}

template <typename T>
template <typename S>
void ReturnValue<T>::Set(const BasicTracedReference<S>& handle) {
Expand All @@ -298,6 +318,16 @@ void ReturnValue<T>::Set(const BasicTracedReference<S>& handle) {
}
}

template <typename T>
template <typename S>
void ReturnValue<T>::SetNonEmpty(const BasicTracedReference<S>& handle) {
static_assert(std::is_base_of<T, S>::value, "type check");
#ifdef V8_ENABLE_CHECKS
internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
#endif // V8_ENABLE_CHECKS
*value_ = handle.ptr();
}

template <typename T>
template <typename S>
void ReturnValue<T>::Set(const Local<S> handle) {
Expand All @@ -310,6 +340,17 @@ void ReturnValue<T>::Set(const Local<S> handle) {
}
}

template <typename T>
template <typename S>
void ReturnValue<T>::SetNonEmpty(const Local<S> handle) {
static_assert(std::is_void<T>::value || std::is_base_of<T, S>::value,
"type check");
#ifdef V8_ENABLE_CHECKS
internal::VerifyHandleIsNonEmpty(handle.IsEmpty());
#endif // V8_ENABLE_CHECKS
*value_ = handle.ptr();
}

template <typename T>
void ReturnValue<T>::Set(double i) {
static_assert(std::is_base_of<T, Number>::value, "type check");
Expand Down Expand Up @@ -339,6 +380,15 @@ void ReturnValue<T>::Set(uint32_t i) {
Set(Integer::NewFromUnsigned(GetIsolate(), i));
}

template <typename T>
void ReturnValue<T>::Set(uint16_t i) {
static_assert(std::is_base_of<T, Integer>::value, "type check");
using I = internal::Internals;
static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::min()));
static_assert(I::IsValidSmi(std::numeric_limits<uint16_t>::max()));
*value_ = I::IntToSmi(i);
}

template <typename T>
void ReturnValue<T>::Set(bool value) {
static_assert(std::is_base_of<T, Boolean>::value, "type check");
Expand Down
1 change: 1 addition & 0 deletions v8_c_api/src/v8include/v8-function.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stddef.h>
#include <stdint.h>

#include "v8-context.h" // NOLINT(build/include_directory)
#include "v8-function-callback.h" // NOLINT(build/include_directory)
#include "v8-local-handle.h" // NOLINT(build/include_directory)
#include "v8-message.h" // NOLINT(build/include_directory)
Expand Down
85 changes: 0 additions & 85 deletions v8_c_api/src/v8include/v8-handle-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,91 +9,6 @@

namespace v8 {

namespace internal {

// Helper functions about values contained in handles.
// A value is either an indirect pointer or a direct pointer, depending on
// whether direct local support is enabled.
class ValueHelper final {
public:
#ifdef V8_ENABLE_DIRECT_LOCAL
static constexpr Address kTaggedNullAddress = 1;
static constexpr Address kEmpty = kTaggedNullAddress;
#else
static constexpr Address kEmpty = kNullAddress;
#endif // V8_ENABLE_DIRECT_LOCAL

template <typename T>
V8_INLINE static bool IsEmpty(T* value) {
return reinterpret_cast<Address>(value) == kEmpty;
}

// Returns a handle's "value" for all kinds of abstract handles. For Local,
// it is equivalent to `*handle`. The variadic parameters support handle
// types with extra type parameters, like `Persistent<T, M>`.
template <template <typename T, typename... Ms> typename H, typename T,
typename... Ms>
V8_INLINE static T* HandleAsValue(const H<T, Ms...>& handle) {
return handle.template value<T>();
}

#ifdef V8_ENABLE_DIRECT_LOCAL

template <typename T>
V8_INLINE static Address ValueAsAddress(const T* value) {
return reinterpret_cast<Address>(value);
}

template <typename T, bool check_null = true, typename S>
V8_INLINE static T* SlotAsValue(S* slot) {
if (check_null && slot == nullptr) {
return reinterpret_cast<T*>(kTaggedNullAddress);
}
return *reinterpret_cast<T**>(slot);
}

#else // !V8_ENABLE_DIRECT_LOCAL

template <typename T>
V8_INLINE static Address ValueAsAddress(const T* value) {
return *reinterpret_cast<const Address*>(value);
}

template <typename T, bool check_null = true, typename S>
V8_INLINE static T* SlotAsValue(S* slot) {
return reinterpret_cast<T*>(slot);
}

#endif // V8_ENABLE_DIRECT_LOCAL
};

/**
* Helper functions about handles.
*/
class HandleHelper final {
public:
/**
* Checks whether two handles are equal.
* They are equal iff they are both empty or they are both non-empty and the
* objects to which they refer are physically equal.
*
* If both handles refer to JS objects, this is the same as strict equality.
* For primitives, such as numbers or strings, a `false` return value does not
* indicate that the values aren't equal in the JavaScript sense.
* Use `Value::StrictEquals()` to check primitives for equality.
*/
template <typename T1, typename T2>
V8_INLINE static bool EqualHandles(const T1& lhs, const T2& rhs) {
if (lhs.IsEmpty()) return rhs.IsEmpty();
if (rhs.IsEmpty()) return false;
return lhs.ptr() == rhs.ptr();
}

static V8_EXPORT void VerifyOnStack(const void* ptr);
};

} // namespace internal

/**
* A base class for abstract handles containing indirect pointers.
* These are useful regardless of whether direct local support is enabled.
Expand Down
Loading

0 comments on commit 73979d1

Please sign in to comment.