From b86c7fdf796034b0b5a40760e5a13ee23c967ae7 Mon Sep 17 00:00:00 2001 From: Meir Shpilraien Date: Thu, 28 Mar 2024 14:48:27 +0200 Subject: [PATCH] Update v8 version to 12.3.219.14 --- Cargo.toml | 2 +- build.rs | 2 +- .../v8include/cppgc/internal/api-constants.h | 2 +- v8_c_api/src/v8include/v8-array-buffer.h | 6 +++ v8_c_api/src/v8include/v8-callbacks.h | 18 +++---- v8_c_api/src/v8include/v8-context.h | 6 +-- v8_c_api/src/v8include/v8-forward.h | 1 + v8_c_api/src/v8include/v8-function-callback.h | 3 +- v8_c_api/src/v8include/v8-internal.h | 4 -- v8_c_api/src/v8include/v8-isolate.h | 15 ++---- v8_c_api/src/v8include/v8-local-handle.h | 3 ++ v8_c_api/src/v8include/v8-script.h | 13 +++-- v8_c_api/src/v8include/v8-snapshot.h | 7 ++- v8_c_api/src/v8include/v8-template.h | 51 ++++++++++++++++++- v8_c_api/src/v8include/v8-traced-handle.h | 29 ----------- v8_c_api/src/v8include/v8-util.h | 25 ++++----- v8_c_api/src/v8include/v8-version.h | 6 +-- 17 files changed, 110 insertions(+), 83 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b0c48b5..cccdf3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "v8_rs" -version = "0.2.8" +version = "0.2.9" edition = "2021" license = "Redis Source Available License 2.0 (RSALv2) or the Server Side Public License v1 (SSPLv1)" diff --git a/build.rs b/build.rs index bca36b1..b2dc067 100644 --- a/build.rs +++ b/build.rs @@ -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.2.281.21"; + static ref V8_DEFAULT_VERSION: &'static str = "12.3.219.14"; 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)); diff --git a/v8_c_api/src/v8include/cppgc/internal/api-constants.h b/v8_c_api/src/v8include/cppgc/internal/api-constants.h index 4e2a637..fed7005 100644 --- a/v8_c_api/src/v8include/cppgc/internal/api-constants.h +++ b/v8_c_api/src/v8include/cppgc/internal/api-constants.h @@ -32,7 +32,7 @@ static constexpr uint16_t kFullyConstructedBitMask = uint16_t{1}; static constexpr size_t kPageSize = size_t{1} << 17; -#if defined(V8_TARGET_ARCH_ARM64) && defined(V8_OS_DARWIN) +#if defined(V8_HOST_ARCH_ARM64) && defined(V8_OS_DARWIN) constexpr size_t kGuardPageSize = 0; #else constexpr size_t kGuardPageSize = 4096; diff --git a/v8_c_api/src/v8include/v8-array-buffer.h b/v8_c_api/src/v8include/v8-array-buffer.h index 804fc42..ea6f5b5 100644 --- a/v8_c_api/src/v8include/v8-array-buffer.h +++ b/v8_c_api/src/v8include/v8-array-buffer.h @@ -318,6 +318,12 @@ class V8_EXPORT ArrayBuffer : public Object { */ std::shared_ptr GetBackingStore(); + /** + * More efficient shortcut for + * GetBackingStore()->IsResizableByUserJavaScript(). + */ + bool IsResizableByUserJavaScript() const; + /** * More efficient shortcut for GetBackingStore()->Data(). The returned pointer * is valid as long as the ArrayBuffer is alive. diff --git a/v8_c_api/src/v8include/v8-callbacks.h b/v8_c_api/src/v8include/v8-callbacks.h index 2a25b9e..4f5e716 100644 --- a/v8_c_api/src/v8include/v8-callbacks.h +++ b/v8_c_api/src/v8include/v8-callbacks.h @@ -327,10 +327,6 @@ using WasmAsyncResolvePromiseCallback = void (*)( using WasmLoadSourceMapCallback = Local (*)(Isolate* isolate, const char* name); -// --- Callback for checking if WebAssembly GC is enabled --- -// If the callback returns true, it will also enable Wasm stringrefs. -using WasmGCEnabledCallback = bool (*)(Local context); - // --- Callback for checking if WebAssembly imported strings are enabled --- using WasmImportedStringsEnabledCallback = bool (*)(Local context); @@ -342,6 +338,9 @@ using SharedArrayBufferConstructorEnabledCallback = using JavaScriptCompileHintsMagicEnabledCallback = bool (*)(Local context); +// --- Callback for checking if WebAssembly JSPI is enabled --- +using WasmJSPIEnabledCallback = bool (*)(Local context); + /** * HostImportModuleDynamicallyCallback is called when we * require the embedder to load a module. This is used as part of the dynamic @@ -352,11 +351,11 @@ using JavaScriptCompileHintsMagicEnabledCallback = * * The specifier is the name of the module that should be imported. * - * The import_assertions are import assertions for this request in the form: + * The import_attributes are import attributes for this request in the form: * [key1, value1, key2, value2, ...] where the keys and values are of type * v8::String. Note, unlike the FixedArray passed to ResolveModuleCallback and * returned from ModuleRequest::GetImportAssertions(), this array does not - * contain the source Locations of the assertions. + * contain the source Locations of the attributes. * * The embedder must compile, instantiate, evaluate the Module, and * obtain its namespace object. @@ -368,15 +367,10 @@ using JavaScriptCompileHintsMagicEnabledCallback = * fails (e.g. due to stack overflow), the embedder must propagate * that exception by returning an empty MaybeLocal. */ -using HostImportModuleDynamicallyWithImportAssertionsCallback = - MaybeLocal (*)(Local context, - Local referrer, - Local specifier, - Local import_assertions); using HostImportModuleDynamicallyCallback = MaybeLocal (*)( Local context, Local host_defined_options, Local resource_name, Local specifier, - Local import_assertions); + Local import_attributes); /** * Callback for requesting a compile hint for a function from the embedder. The diff --git a/v8_c_api/src/v8include/v8-context.h b/v8_c_api/src/v8include/v8-context.h index 5552c7a..c81dc80 100644 --- a/v8_c_api/src/v8include/v8-context.h +++ b/v8_c_api/src/v8include/v8-context.h @@ -459,12 +459,12 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) { template MaybeLocal Context::GetDataFromSnapshotOnce(size_t index) { - auto slot = GetDataFromSnapshotOnce(index); - if (slot) { + if (auto slot = GetDataFromSnapshotOnce(index); slot) { internal::PerformCastCheck( internal::ValueHelper::SlotAsValue(slot)); + return Local::FromSlot(slot); } - return Local::FromSlot(slot); + return {}; } Context* Context::Cast(v8::Data* data) { diff --git a/v8_c_api/src/v8include/v8-forward.h b/v8_c_api/src/v8include/v8-forward.h index db3a201..435fe85 100644 --- a/v8_c_api/src/v8include/v8-forward.h +++ b/v8_c_api/src/v8include/v8-forward.h @@ -27,6 +27,7 @@ class Context; class DataView; class Data; class Date; +class DictionaryTemplate; class Extension; class External; class FixedArray; diff --git a/v8_c_api/src/v8include/v8-function-callback.h b/v8_c_api/src/v8include/v8-function-callback.h index a21d59d..22b5328 100644 --- a/v8_c_api/src/v8include/v8-function-callback.h +++ b/v8_c_api/src/v8include/v8-function-callback.h @@ -475,7 +475,8 @@ Local ReturnValue::Get() const { #endif // V8_STATIC_ROOTS_BOOL return Undefined(GetIsolate()); } - return Local::New(GetIsolate(), reinterpret_cast(value_)); + return Local::New(GetIsolate(), + internal::ValueHelper::SlotAsValue(value_)); } template diff --git a/v8_c_api/src/v8include/v8-internal.h b/v8_c_api/src/v8include/v8-internal.h index a10735d..48001c6 100644 --- a/v8_c_api/src/v8include/v8-internal.h +++ b/v8_c_api/src/v8include/v8-internal.h @@ -616,8 +616,6 @@ constexpr bool kAllCodeObjectsLiveInTrustedSpace = kRuntimeGeneratedCodeObjectsLiveInTrustedSpace && kBuiltinCodeObjectsLiveInTrustedSpace; -constexpr bool kInterpreterDataObjectsLiveInTrustedSpace = false; - // {obj} must be the raw tagged pointer representation of a HeapObject // that's guaranteed to never be in ReadOnlySpace. V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj); @@ -781,8 +779,6 @@ class Internals { static const int kNodeStateMask = 0x3; static const int kNodeStateIsWeakValue = 2; - static const int kTracedNodeClassIdOffset = kApiSystemPointerSize; - static const int kFirstNonstringType = 0x80; static const int kOddballType = 0x83; static const int kForeignType = 0xcc; diff --git a/v8_c_api/src/v8include/v8-isolate.h b/v8_c_api/src/v8include/v8-isolate.h index add965a..a3ceec0 100644 --- a/v8_c_api/src/v8include/v8-isolate.h +++ b/v8_c_api/src/v8include/v8-isolate.h @@ -1579,19 +1579,14 @@ class V8_EXPORT Isolate { void SetWasmLoadSourceMapCallback(WasmLoadSourceMapCallback callback); - /** - * Register callback to control whether Wasm GC is enabled. - * The callback overwrites the value of the flag. - * If the callback returns true, it will also enable Wasm stringrefs. - */ - void SetWasmGCEnabledCallback(WasmGCEnabledCallback callback); - void SetWasmImportedStringsEnabledCallback( WasmImportedStringsEnabledCallback callback); void SetSharedArrayBufferConstructorEnabledCallback( SharedArrayBufferConstructorEnabledCallback callback); + void SetWasmJSPIEnabledCallback(WasmJSPIEnabledCallback callback); + /** * Register callback to control whether compile hints magic comments are * enabled. @@ -1751,12 +1746,12 @@ uint32_t Isolate::GetNumberOfDataSlots() { template MaybeLocal Isolate::GetDataFromSnapshotOnce(size_t index) { - auto slot = GetDataFromSnapshotOnce(index); - if (slot) { + if (auto slot = GetDataFromSnapshotOnce(index); slot) { internal::PerformCastCheck( internal::ValueHelper::SlotAsValue(slot)); + return Local::FromSlot(slot); } - return Local::FromSlot(slot); + return {}; } } // namespace v8 diff --git a/v8_c_api/src/v8include/v8-local-handle.h b/v8_c_api/src/v8include/v8-local-handle.h index 37efafd..46f7308 100644 --- a/v8_c_api/src/v8include/v8-local-handle.h +++ b/v8_c_api/src/v8include/v8-local-handle.h @@ -62,6 +62,7 @@ class ReturnValue; class String; template class Traced; +class TypecheckWitness; class Utils; namespace debug { @@ -405,6 +406,8 @@ class V8_TRIVIAL_ABI Local : public LocalBase, } #ifdef V8_ENABLE_DIRECT_LOCAL + friend class TypecheckWitness; + V8_INLINE static Local FromAddress(internal::Address ptr) { return Local(LocalBase(ptr)); } diff --git a/v8_c_api/src/v8include/v8-script.h b/v8_c_api/src/v8include/v8-script.h index a2d0bca..db22de9 100644 --- a/v8_c_api/src/v8include/v8-script.h +++ b/v8_c_api/src/v8include/v8-script.h @@ -136,19 +136,24 @@ class V8_EXPORT ModuleRequest : public Data { int GetSourceOffset() const; /** - * Contains the import assertions for this request in the form: + * Contains the import attributes for this request in the form: * [key1, value1, source_offset1, key2, value2, source_offset2, ...]. * The keys and values are of type v8::String, and the source offsets are of * type Int32. Use Module::SourceOffsetToLocation to convert the source * offsets to Locations with line/column numbers. * - * All assertions present in the module request will be supplied in this + * All attributes present in the module request will be supplied in this * list, regardless of whether they are supported by the host. Per * https://tc39.es/proposal-import-attributes/#sec-hostgetsupportedimportattributes, - * hosts are expected to throw for assertions that they do not support (as + * hosts are expected to throw for attributes that they do not support (as * opposed to, for example, ignoring them). */ - Local GetImportAssertions() const; + Local GetImportAttributes() const; + + V8_DEPRECATE_SOON("Use GetImportAttributes instead") + Local GetImportAssertions() const { + return GetImportAttributes(); + } V8_INLINE static ModuleRequest* Cast(Data* data); diff --git a/v8_c_api/src/v8include/v8-snapshot.h b/v8_c_api/src/v8include/v8-snapshot.h index 70d2ca5..a1dc0c3 100644 --- a/v8_c_api/src/v8include/v8-snapshot.h +++ b/v8_c_api/src/v8include/v8-snapshot.h @@ -14,6 +14,10 @@ namespace v8 { class Object; +namespace internal { +class SnapshotCreatorImpl; +} // namespace internal + class V8_EXPORT StartupData { public: /** @@ -206,7 +210,8 @@ class V8_EXPORT SnapshotCreator { size_t AddData(Local context, internal::Address object); size_t AddData(internal::Address object); - void* data_; + internal::SnapshotCreatorImpl* impl_; + friend class internal::SnapshotCreatorImpl; }; template diff --git a/v8_c_api/src/v8include/v8-template.h b/v8_c_api/src/v8include/v8-template.h index c18baf9..674d420 100644 --- a/v8_c_api/src/v8include/v8-template.h +++ b/v8_c_api/src/v8include/v8-template.h @@ -5,6 +5,9 @@ #ifndef INCLUDE_V8_TEMPLATE_H_ #define INCLUDE_V8_TEMPLATE_H_ +#include +#include + #include "v8-data.h" // NOLINT(build/include_directory) #include "v8-function-callback.h" // NOLINT(build/include_directory) #include "v8-local-handle.h" // NOLINT(build/include_directory) @@ -778,7 +781,11 @@ class V8_EXPORT ObjectTemplate : public Template { Isolate* isolate, Local constructor = Local()); - /** Creates a new instance of this template.*/ + /** + * Creates a new instance of this template. + * + * \param context The context in which the instance is created. + */ V8_WARN_UNUSED_RESULT MaybeLocal NewInstance(Local context); /** @@ -950,6 +957,41 @@ class V8_EXPORT ObjectTemplate : public Template { friend class FunctionTemplate; }; +/** + * A template to create dictionary objects at runtime. + */ +class V8_EXPORT DictionaryTemplate final { + public: + /** Creates a new template. Also declares data properties that can be passed + * on instantiation of the template. Properties can only be declared on + * construction and are then immutable. The values are passed on creating the + * object via `NewInstance()`. + * + * \param names the keys that can be passed on instantiation. + */ + static Local New( + Isolate* isolate, MemorySpan names); + + /** + * Creates a new instance of this template. + * + * \param context The context used to create the dictionary object. + * \param property_values Values of properties that were declared using + * `DeclareDataProperties()`. The span only passes values and expectes the + * order to match the declaration. Non-existent properties are signaled via + * empty `MaybeLocal`s. + */ + V8_WARN_UNUSED_RESULT Local NewInstance( + Local context, MemorySpan> property_values); + + V8_INLINE static DictionaryTemplate* Cast(Data* data); + + private: + static void CheckCast(Data* that); + + DictionaryTemplate(); +}; + /** * A Signature specifies which receiver is valid for a function. * @@ -995,6 +1037,13 @@ ObjectTemplate* ObjectTemplate::Cast(Data* data) { return reinterpret_cast(data); } +DictionaryTemplate* DictionaryTemplate::Cast(Data* data) { +#ifdef V8_ENABLE_CHECKS + CheckCast(data); +#endif + return reinterpret_cast(data); +} + Signature* Signature::Cast(Data* data) { #ifdef V8_ENABLE_CHECKS CheckCast(data); diff --git a/v8_c_api/src/v8include/v8-traced-handle.h b/v8_c_api/src/v8include/v8-traced-handle.h index 7abe0b9..c9fd357 100644 --- a/v8_c_api/src/v8include/v8-traced-handle.h +++ b/v8_c_api/src/v8include/v8-traced-handle.h @@ -77,19 +77,6 @@ class TracedReferenceBase : public api_internal::IndirectHandleBase { return this->GetSlotThreadSafe() == nullptr; } - /** - * Assigns a wrapper class ID to the handle. - */ - V8_DEPRECATED("Embedders need to maintain state for references themselves.") - V8_INLINE void SetWrapperClassId(uint16_t class_id); - - /** - * Returns the class ID previously assigned to this handle or 0 if no class ID - * was previously assigned. - */ - V8_DEPRECATED("Embedders need to maintain state for references themselves.") - V8_INLINE uint16_t WrapperClassId() const; - protected: V8_INLINE TracedReferenceBase() = default; @@ -440,22 +427,6 @@ TracedReference& TracedReference::operator=(const TracedReference& rhs) { return *this; } -void TracedReferenceBase::SetWrapperClassId(uint16_t class_id) { - using I = internal::Internals; - if (IsEmpty()) return; - uint8_t* addr = - reinterpret_cast(slot()) + I::kTracedNodeClassIdOffset; - *reinterpret_cast(addr) = class_id; -} - -uint16_t TracedReferenceBase::WrapperClassId() const { - using I = internal::Internals; - if (IsEmpty()) return 0; - uint8_t* addr = - reinterpret_cast(slot()) + I::kTracedNodeClassIdOffset; - return *reinterpret_cast(addr); -} - } // namespace v8 #endif // INCLUDE_V8_TRACED_HANDLE_H_ diff --git a/v8_c_api/src/v8include/v8-util.h b/v8_c_api/src/v8include/v8-util.h index c845c99..db6d1a2 100644 --- a/v8_c_api/src/v8include/v8-util.h +++ b/v8_c_api/src/v8include/v8-util.h @@ -240,8 +240,9 @@ class PersistentValueMapBase { : value_(other.value_) { } Local NewLocal(Isolate* isolate) const { - return Local::New( - isolate, internal::ValueHelper::SlotAsValue(FromVal(value_))); + return Local::New(isolate, + internal::ValueHelper::SlotAsValue( + reinterpret_cast(value_))); } bool IsEmpty() const { return value_ == kPersistentContainerNotFound; @@ -298,7 +299,8 @@ class PersistentValueMapBase { typename Traits::Impl* impl() { return &impl_; } static V* FromVal(PersistentContainerValue v) { - return reinterpret_cast(v); + return internal::ValueHelper::SlotAsValue( + reinterpret_cast(v)); } static PersistentContainerValue ClearAndLeak(Global* persistent) { @@ -318,7 +320,7 @@ class PersistentValueMapBase { */ static Global Release(PersistentContainerValue v) { Global p; - p.slot() = reinterpret_cast(FromVal(v)); + p.slot() = reinterpret_cast(v); if (Traits::kCallbackType != kNotWeak && p.IsWeak()) { Traits::DisposeCallbackData( p.template ClearWeak()); @@ -328,8 +330,8 @@ class PersistentValueMapBase { void RemoveWeak(const K& key) { Global p; - p.slot() = reinterpret_cast( - FromVal(Traits::Remove(&impl_, key))); + p.slot() = + reinterpret_cast(Traits::Remove(&impl_, key)); p.Reset(); } @@ -345,8 +347,7 @@ class PersistentValueMapBase { PersistentContainerValue value) { bool hasValue = value != kPersistentContainerNotFound; if (hasValue) { - returnValue->SetInternal( - *reinterpret_cast(FromVal(value))); + returnValue->SetInternal(*reinterpret_cast(value)); } return hasValue; } @@ -620,7 +621,7 @@ class V8_DEPRECATE_SOON("Use std::vector>.") PersistentValueVector { */ Local Get(size_t index) const { return Local::New(isolate_, internal::ValueHelper::SlotAsValue( - FromVal(Traits::Get(&impl_, index)))); + Traits::Get(&impl_, index))); } /** @@ -630,8 +631,7 @@ class V8_DEPRECATE_SOON("Use std::vector>.") PersistentValueVector { size_t length = Traits::Size(&impl_); for (size_t i = 0; i < length; i++) { Global p; - p.slot() = - reinterpret_cast(FromVal(Traits::Get(&impl_, i))); + p.slot() = reinterpret_cast(Traits::Get(&impl_, i)); } Traits::Clear(&impl_); } @@ -652,7 +652,8 @@ class V8_DEPRECATE_SOON("Use std::vector>.") PersistentValueVector { } static V* FromVal(PersistentContainerValue v) { - return reinterpret_cast(v); + return internal::ValueHelper::SlotAsValue( + reinterpret_cast(v)); } Isolate* isolate_; diff --git a/v8_c_api/src/v8include/v8-version.h b/v8_c_api/src/v8include/v8-version.h index a5ae279..6ae0806 100644 --- a/v8_c_api/src/v8include/v8-version.h +++ b/v8_c_api/src/v8include/v8-version.h @@ -9,9 +9,9 @@ // NOTE these macros are used by some of the tool scripts and the build // system so their names cannot be changed without changing the scripts. #define V8_MAJOR_VERSION 12 -#define V8_MINOR_VERSION 2 -#define V8_BUILD_NUMBER 281 -#define V8_PATCH_LEVEL 21 +#define V8_MINOR_VERSION 3 +#define V8_BUILD_NUMBER 219 +#define V8_PATCH_LEVEL 14 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.)