0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-11-28 16:21:04 -05:00

Upgrade to V8 12.1.285.6 (#1374)

1. [[exceptions] Unify pending and scheduled exceptions](https://chromium-review.googlesource.com/c/v8/v8/+/5050065)

Reset no longer clears exception if it was rethrown. The test had to be adjusted for the same.

2. [[api] Allow passing CppHeap on Isolate creation](https://chromium-review.googlesource.com/c/v8/v8/+/4989254)

`AttachCppHeap` was deprecated but the alternative of passing `CppHeap` via Isolate CreateParams hard crashes (SIGSEGV). There are no tests for this in V8 and it seems the [Chromium CL](https://chromium-review.googlesource.com/c/chromium/src/+/4992764) is also crashing. For now I've just suppressed the deprecation warning until the crash is fixed in V8.

3. v8::Serializer impl must not throw more than one exception. 

I changed `get_shared_buffer_id()` to not throw and return `None`. V8 internally calls data clone error when it's the SAB is not clonable.

Other changes:

- `v8::ScriptCompiler` size increased by 3 words with `v8::ScriptCompiler::CompilationDetails`.
- `v8::ObjectTemplate::SetAccessor` & `v8::ObjectTemplate::SetAccessorProperty` signature changed and also deprecated.
- `v8::Context::SetContinuationPreservedEmbedderData` deprecated. Use `v8::Isolate::GetContinuationPreservedEmbedderData` instead.
- `GetStalledTopLevelAwaitMessage` deprecated. Use `GetStalledTopLevelAwaitMessages` instead.
- `v8::Isolate::AttachCppHeap` deprecated. Set the heap on Isolate creation using CreateParams instead. 
- `v8::ScriptOrigin` deprecated. Use constructor without the isolate.
- `v8::SnapshotCreator` is deprecated. Use the version that passes CreateParams instead.
- `v8::Isolate` assertion failures.

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Divy Srivastava 2024-01-05 18:50:42 +05:30 committed by GitHub
parent 60e0859514
commit 3de68239a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 137 additions and 145 deletions

View file

@ -43,7 +43,6 @@ fn main() {
DEFAULT_CPP_GC_EMBEDDER_ID, DEFAULT_CPP_GC_EMBEDDER_ID,
)), )),
); );
isolate.attach_cpp_heap(&heap); isolate.attach_cpp_heap(&heap);
let handle_scope = &mut v8::HandleScope::new(isolate); let handle_scope = &mut v8::HandleScope::new(isolate);

View file

@ -7,6 +7,7 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include "cppgc/platform.h"
#include "support.h" #include "support.h"
#include "unicode/locid.h" #include "unicode/locid.h"
#include "v8-callbacks.h" #include "v8-callbacks.h"
@ -30,8 +31,6 @@
#include "v8/src/objects/objects.h" #include "v8/src/objects/objects.h"
#include "v8/src/objects/smi.h" #include "v8/src/objects/smi.h"
#include "cppgc/platform.h"
using namespace support; using namespace support;
template <typename T> template <typename T>
@ -57,8 +56,14 @@ static_assert(sizeof(v8::PromiseRejectMessage) == sizeof(size_t) * 3,
static_assert(sizeof(v8::Locker) == sizeof(size_t) * 2, "Locker size mismatch"); static_assert(sizeof(v8::Locker) == sizeof(size_t) * 2, "Locker size mismatch");
static_assert(sizeof(v8::ScriptCompiler::Source) == static_assert(sizeof(v8::ScriptCompiler::CompilationDetails) ==
align_to<size_t>(sizeof(size_t) * 9 + sizeof(int) * 2), sizeof(size_t) * 3,
"CompilationDetails size mismatch");
static_assert(
sizeof(v8::ScriptCompiler::Source) ==
align_to<size_t>(sizeof(size_t) * 9 + sizeof(int) * 2 +
sizeof(v8::ScriptCompiler::CompilationDetails)),
"Source size mismatch"); "Source size mismatch");
static_assert(sizeof(v8::FunctionCallbackInfo<v8::Value>) == sizeof(size_t) * 3, static_assert(sizeof(v8::FunctionCallbackInfo<v8::Value>) == sizeof(size_t) * 3,
@ -100,8 +105,7 @@ static_assert(offsetof(v8::ScriptCompiler::CachedData, rejected) == 12,
"CachedData.rejected offset mismatch"); "CachedData.rejected offset mismatch");
static_assert(offsetof(v8::ScriptCompiler::CachedData, buffer_policy) == 16, static_assert(offsetof(v8::ScriptCompiler::CachedData, buffer_policy) == 16,
"CachedData.buffer_policy offset mismatch"); "CachedData.buffer_policy offset mismatch");
static_assert(sizeof(v8::Isolate::DisallowJavascriptExecutionScope) == static_assert(sizeof(v8::Isolate::DisallowJavascriptExecutionScope) == 16,
16,
"DisallowJavascriptExecutionScope size mismatch"); "DisallowJavascriptExecutionScope size mismatch");
#else #else
static_assert(sizeof(v8::ScriptCompiler::CachedData) == 16, static_assert(sizeof(v8::ScriptCompiler::CachedData) == 16,
@ -114,8 +118,7 @@ static_assert(offsetof(v8::ScriptCompiler::CachedData, rejected) == 8,
"CachedData.rejected offset mismatch"); "CachedData.rejected offset mismatch");
static_assert(offsetof(v8::ScriptCompiler::CachedData, buffer_policy) == 12, static_assert(offsetof(v8::ScriptCompiler::CachedData, buffer_policy) == 12,
"CachedData.buffer_policy offset mismatch"); "CachedData.buffer_policy offset mismatch");
static_assert(sizeof(v8::Isolate::DisallowJavascriptExecutionScope) == static_assert(sizeof(v8::Isolate::DisallowJavascriptExecutionScope) == 12,
12,
"DisallowJavascriptExecutionScope size mismatch"); "DisallowJavascriptExecutionScope size mismatch");
#endif #endif
@ -487,7 +490,9 @@ uint32_t v8__ScriptCompiler__CachedDataVersionTag() {
size_t v8__TypedArray__Length(const v8::TypedArray* self) { size_t v8__TypedArray__Length(const v8::TypedArray* self) {
return ptr_to_local(self)->Length(); return ptr_to_local(self)->Length();
} }
size_t v8__TypedArray__kMaxByteLength() { return v8::TypedArray::kMaxByteLength; } size_t v8__TypedArray__kMaxByteLength() {
return v8::TypedArray::kMaxByteLength;
}
bool v8__Data__EQ(const v8::Data& self, const v8::Data& other) { bool v8__Data__EQ(const v8::Data& self, const v8::Data& other) {
return ptr_to_local(&self) == ptr_to_local(&other); return ptr_to_local(&self) == ptr_to_local(&other);
@ -872,8 +877,8 @@ two_pointers_t v8__ArrayBuffer__GetBackingStore(const v8::ArrayBuffer& self) {
} }
v8::BackingStore* v8__BackingStore__EmptyBackingStore(bool shared) { v8::BackingStore* v8__BackingStore__EmptyBackingStore(bool shared) {
std::unique_ptr<i::BackingStoreBase> u = std::unique_ptr<i::BackingStoreBase> u = i::BackingStore::EmptyBackingStore(
i::BackingStore::EmptyBackingStore(shared ? i::SharedFlag::kShared : i::SharedFlag::kNotShared); shared ? i::SharedFlag::kShared : i::SharedFlag::kNotShared);
return static_cast<v8::BackingStore*>(u.release()); return static_cast<v8::BackingStore*>(u.release());
} }
@ -1046,13 +1051,16 @@ class ExternalStaticOneByteStringResource
class ExternalConstOneByteStringResource class ExternalConstOneByteStringResource
: public v8::String::ExternalOneByteStringResource { : public v8::String::ExternalOneByteStringResource {
public: public:
ExternalConstOneByteStringResource(int length) ExternalConstOneByteStringResource(int length) : _length(length) {
: _length(length) { static_assert(offsetof(ExternalConstOneByteStringResource, _length) ==
static_assert(offsetof(ExternalConstOneByteStringResource, _length) == sizeof(size_t) * 2, sizeof(size_t) * 2,
"ExternalConstOneByteStringResource's length was not at offset of sizeof(size_t) * 2"); "ExternalConstOneByteStringResource's length was not at "
static_assert(sizeof(ExternalConstOneByteStringResource) == sizeof(size_t) * 3, "offset of sizeof(size_t) * 2");
static_assert(
sizeof(ExternalConstOneByteStringResource) == sizeof(size_t) * 3,
"ExternalConstOneByteStringResource size was not sizeof(size_t) * 3"); "ExternalConstOneByteStringResource size was not sizeof(size_t) * 3");
static_assert(alignof(ExternalConstOneByteStringResource) == sizeof(size_t), static_assert(
alignof(ExternalConstOneByteStringResource) == sizeof(size_t),
"ExternalConstOneByteStringResource align was not sizeof(size_t)"); "ExternalConstOneByteStringResource align was not sizeof(size_t)");
} }
const char* data() const override { return nullptr; } const char* data() const override { return nullptr; }
@ -1185,15 +1193,14 @@ void v8__ObjectTemplate__SetInternalFieldCount(const v8::ObjectTemplate& self,
ptr_to_local(&self)->SetInternalFieldCount(value); ptr_to_local(&self)->SetInternalFieldCount(value);
} }
void v8__ObjectTemplate__SetAccessor( void v8__ObjectTemplate__SetAccessor(const v8::ObjectTemplate& self,
const v8::ObjectTemplate& self, const v8::Name& key, const v8::Name& key,
v8::AccessorNameGetterCallback getter, v8::AccessorNameGetterCallback getter,
v8::AccessorNameSetterCallback setter, v8::AccessorNameSetterCallback setter,
const v8::Value* data_or_null, const v8::Value* data_or_null,
v8::PropertyAttribute attr) { v8::PropertyAttribute attr) {
ptr_to_local(&self)->SetAccessor( ptr_to_local(&self)->SetAccessor(ptr_to_local(&key), getter, setter,
ptr_to_local(&key), getter, setter, ptr_to_local(data_or_null), v8::AccessControl::DEFAULT, ptr_to_local(data_or_null), attr);
attr);
} }
void v8__ObjectTemplate__SetNamedPropertyHandler( void v8__ObjectTemplate__SetNamedPropertyHandler(
@ -1336,9 +1343,9 @@ MaybeBool v8__Object__SetAccessor(const v8::Object& self,
v8::AccessorNameSetterCallback setter, v8::AccessorNameSetterCallback setter,
const v8::Value* data_or_null, const v8::Value* data_or_null,
v8::PropertyAttribute attr) { v8::PropertyAttribute attr) {
return maybe_to_maybe_bool(ptr_to_local(&self)->SetAccessor( return maybe_to_maybe_bool(ptr_to_local(&self)->SetNativeDataProperty(
ptr_to_local(&context), ptr_to_local(&key), getter, setter, ptr_to_local(&context), ptr_to_local(&key), getter, setter,
ptr_to_local(data_or_null), v8::AccessControl::DEFAULT, attr)); ptr_to_local(data_or_null), attr));
} }
v8::Isolate* v8__Object__GetIsolate(const v8::Object& self) { v8::Isolate* v8__Object__GetIsolate(const v8::Object& self) {
@ -1497,8 +1504,7 @@ const v8::Value* v8__Object__GetOwnPropertyDescriptor(
ptr_to_local(&context), ptr_to_local(&key))); ptr_to_local(&context), ptr_to_local(&key)));
} }
const v8::Array* v8__Object__PreviewEntries( const v8::Array* v8__Object__PreviewEntries(const v8::Object& self,
const v8::Object& self,
bool* is_key_value) { bool* is_key_value) {
return maybe_local_to_ptr(ptr_to_local(&self)->PreviewEntries(is_key_value)); return maybe_local_to_ptr(ptr_to_local(&self)->PreviewEntries(is_key_value));
} }
@ -1668,8 +1674,7 @@ const v8::ArrayBuffer* v8__ArrayBufferView__Buffer(
return local_to_ptr(ptr_to_local(&self)->Buffer()); return local_to_ptr(ptr_to_local(&self)->Buffer());
} }
const void* v8__ArrayBufferView__Buffer__Data( const void* v8__ArrayBufferView__Buffer__Data(const v8::ArrayBufferView& self) {
const v8::ArrayBufferView& self) {
return ptr_to_local(&self)->Buffer()->Data(); return ptr_to_local(&self)->Buffer()->Data();
} }
@ -1853,7 +1858,8 @@ void v8__Context__UseDefaultSecurityToken(v8::Context& self) {
ptr_to_local(&self)->UseDefaultSecurityToken(); ptr_to_local(&self)->UseDefaultSecurityToken();
} }
void v8__Context__AllowCodeGenerationFromStrings(v8::Context& self, bool allow) { void v8__Context__AllowCodeGenerationFromStrings(v8::Context& self,
bool allow) {
ptr_to_local(&self)->AllowCodeGenerationFromStrings(allow); ptr_to_local(&self)->AllowCodeGenerationFromStrings(allow);
} }
@ -1868,15 +1874,14 @@ const v8::Context* v8__Context__FromSnapshot(v8::Isolate* isolate,
return maybe_local_to_ptr(maybe_local); return maybe_local_to_ptr(maybe_local);
} }
void v8__Context__SetContinuationPreservedEmbedderData(v8::Context& context, void v8__Context__SetContinuationPreservedEmbedderData(v8::Isolate* isolate,
const v8::Value* data) { const v8::Value* data) {
auto c = ptr_to_local(&context); isolate->SetContinuationPreservedEmbedderData(ptr_to_local(data));
c->SetContinuationPreservedEmbedderData(ptr_to_local(data));
} }
const v8::Value* v8__Context__GetContinuationPreservedEmbedderData( const v8::Value* v8__Context__GetContinuationPreservedEmbedderData(
const v8::Context& context) { v8::Isolate* isolate) {
auto value = ptr_to_local(&context)->GetContinuationPreservedEmbedderData(); auto value = isolate->GetContinuationPreservedEmbedderData();
return local_to_ptr(value); return local_to_ptr(value);
} }
@ -2311,10 +2316,7 @@ void v8__AllowJavascriptExecutionScope__DESTRUCT(
return local_to_ptr( \ return local_to_ptr( \
v8::NAME::New(ptr_to_local(&buf_ptr), byte_offset, length)); \ v8::NAME::New(ptr_to_local(&buf_ptr), byte_offset, length)); \
} \ } \
size_t v8__##NAME##__kMaxLength() { \ size_t v8__##NAME##__kMaxLength() { return v8::NAME::kMaxLength; }
return v8::NAME::kMaxLength; \
}
V(Uint8Array) V(Uint8Array)
V(Uint8ClampedArray) V(Uint8ClampedArray)
@ -2368,14 +2370,16 @@ const v8::Value* v8__Script__Run(const v8::Script& script,
return maybe_local_to_ptr(ptr_to_local(&script)->Run(ptr_to_local(&context))); return maybe_local_to_ptr(ptr_to_local(&script)->Run(ptr_to_local(&context)));
} }
void v8__ScriptOrigin__CONSTRUCT( void v8__ScriptOrigin__CONSTRUCT(uninit_t<v8::ScriptOrigin>* buf,
v8::Isolate* isolate, uninit_t<v8::ScriptOrigin>* buf, const v8::Value& resource_name,
const v8::Value& resource_name, int resource_line_offset, int resource_line_offset,
int resource_column_offset, bool resource_is_shared_cross_origin, int resource_column_offset,
int script_id, const v8::Value& source_map_url, bool resource_is_opaque, bool resource_is_shared_cross_origin,
bool is_wasm, bool is_module) { int script_id, const v8::Value& source_map_url,
bool resource_is_opaque, bool is_wasm,
bool is_module) {
construct_in_place<v8::ScriptOrigin>( construct_in_place<v8::ScriptOrigin>(
buf, isolate, ptr_to_local(&resource_name), resource_line_offset, buf, ptr_to_local(&resource_name), resource_line_offset,
resource_column_offset, resource_is_shared_cross_origin, script_id, resource_column_offset, resource_is_shared_cross_origin, script_id,
ptr_to_local(&source_map_url), resource_is_opaque, is_wasm, is_module); ptr_to_local(&source_map_url), resource_is_opaque, is_wasm, is_module);
} }
@ -2545,10 +2549,8 @@ bool v8__Proxy__IsRevoked(const v8::Proxy& self) {
void v8__Proxy__Revoke(const v8::Proxy& self) { ptr_to_local(&self)->Revoke(); } void v8__Proxy__Revoke(const v8::Proxy& self) { ptr_to_local(&self)->Revoke(); }
void v8__SnapshotCreator__CONSTRUCT(uninit_t<v8::SnapshotCreator>* buf, void v8__SnapshotCreator__CONSTRUCT(uninit_t<v8::SnapshotCreator>* buf,
const intptr_t* external_references, const v8::Isolate::CreateParams& params) {
v8::StartupData* existing_blob) { construct_in_place<v8::SnapshotCreator>(buf, params);
construct_in_place<v8::SnapshotCreator>(buf, external_references,
existing_blob);
} }
void v8__SnapshotCreator__DESTRUCT(v8::SnapshotCreator* self) { void v8__SnapshotCreator__DESTRUCT(v8::SnapshotCreator* self) {
@ -3013,7 +3015,8 @@ const v8::Module* v8__Module__CreateSyntheticModule(
for (size_t i = 0; i < export_names_len; i += 1) { for (size_t i = 0; i < export_names_len; i += 1) {
export_names_vec.push_back(ptr_to_local(export_names_raw[i])); export_names_vec.push_back(ptr_to_local(export_names_raw[i]));
} }
auto export_names = v8::MemorySpan<const v8::Local<v8::String>>{export_names_vec.data(), export_names_len}; auto export_names = v8::MemorySpan<const v8::Local<v8::String>>{
export_names_vec.data(), export_names_len};
return local_to_ptr(v8::Module::CreateSyntheticModule( return local_to_ptr(v8::Module::CreateSyntheticModule(
isolate, ptr_to_local(module_name), export_names, evaluation_steps)); isolate, ptr_to_local(module_name), export_names, evaluation_steps));
} }
@ -3039,12 +3042,13 @@ struct StalledTopLevelAwaitMessage {
size_t v8__Module__GetStalledTopLevelAwaitMessage( size_t v8__Module__GetStalledTopLevelAwaitMessage(
const v8::Module& self, v8::Isolate* isolate, const v8::Module& self, v8::Isolate* isolate,
StalledTopLevelAwaitMessage* out_vec, size_t out_len) { StalledTopLevelAwaitMessage* out_vec, size_t out_len) {
auto messages = ptr_to_local(&self)->GetStalledTopLevelAwaitMessage(isolate); auto [modules, messages] =
ptr_to_local(&self)->GetStalledTopLevelAwaitMessages(isolate);
auto len = std::min(messages.size(), out_len); auto len = std::min(messages.size(), out_len);
for (size_t i = 0; i < len; i += 1) { for (size_t i = 0; i < len; i += 1) {
StalledTopLevelAwaitMessage stalled_message; StalledTopLevelAwaitMessage stalled_message;
stalled_message.module = local_to_ptr(std::get<0>(messages[i])); stalled_message.module = local_to_ptr(modules[i]);
stalled_message.message = local_to_ptr(std::get<1>(messages[i])); stalled_message.message = local_to_ptr(messages[i]);
out_vec[i] = stalled_message; out_vec[i] = stalled_message;
} }
return len; return len;
@ -3617,17 +3621,14 @@ extern "C" {
using RustTraceFn = void (*)(void* obj, cppgc::Visitor*); using RustTraceFn = void (*)(void* obj, cppgc::Visitor*);
using RustDestroyFn = void (*)(void* obj); using RustDestroyFn = void (*)(void* obj);
class RustObj final: public cppgc::GarbageCollected<RustObj> { class RustObj final : public cppgc::GarbageCollected<RustObj> {
public: public:
explicit RustObj(void* obj, RustTraceFn trace, RustDestroyFn destroy): trace_(trace), destroy_(destroy), obj_(obj) {} explicit RustObj(void* obj, RustTraceFn trace, RustDestroyFn destroy)
: trace_(trace), destroy_(destroy), obj_(obj) {}
~RustObj() { ~RustObj() { destroy_(obj_); }
destroy_(obj_);
}
void Trace(cppgc::Visitor* visitor) const { void Trace(cppgc::Visitor* visitor) const { trace_(obj_, visitor); }
trace_(obj_, visitor);
}
private: private:
RustTraceFn trace_; RustTraceFn trace_;
@ -3639,21 +3640,32 @@ void cppgc__initialize_process(v8::Platform* platform) {
cppgc::InitializeProcess(platform->GetPageAllocator()); cppgc::InitializeProcess(platform->GetPageAllocator());
} }
void cppgc__shutdown_process() { void cppgc__shutdown_process() { cppgc::ShutdownProcess(); }
cppgc::ShutdownProcess();
}
v8::CppHeap* cppgc__heap__create(v8::Platform* platform, int wrappable_type_index, v8::CppHeap* cppgc__heap__create(v8::Platform* platform,
int wrappable_instance_index, uint16_t embedder_id) { int wrappable_type_index,
std::unique_ptr<v8::CppHeap> heap = v8::CppHeap::Create(platform, v8::CppHeapCreateParams { int wrappable_instance_index,
uint16_t embedder_id) {
std::unique_ptr<v8::CppHeap> heap = v8::CppHeap::Create(
platform,
v8::CppHeapCreateParams{
{}, {},
v8::WrapperDescriptor(wrappable_type_index, wrappable_instance_index, embedder_id), v8::WrapperDescriptor(wrappable_type_index, wrappable_instance_index,
embedder_id),
}); });
return heap.release(); return heap.release();
} }
void v8__Isolate__AttachCppHeap(v8::Isolate* isolate, v8::CppHeap* cpp_heap) { void v8__Isolate__AttachCppHeap(v8::Isolate* isolate, v8::CppHeap* cpp_heap) {
// The AttachCppHeap method is deprecated but the alternative of passing
// heap to the Isolate CreateParams is broken.
//
// TODO(@littledivy): Remove this when the above CL is merged.
// https://chromium-review.googlesource.com/c/chromium/src/+/4992764
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
isolate->AttachCppHeap(cpp_heap); isolate->AttachCppHeap(cpp_heap);
#pragma clang diagnostic pop
} }
v8::CppHeap* v8__Isolate__GetCppHeap(v8::Isolate* isolate) { v8::CppHeap* v8__Isolate__GetCppHeap(v8::Isolate* isolate) {
@ -3662,16 +3674,21 @@ v8::CppHeap* v8__Isolate__GetCppHeap(v8::Isolate* isolate) {
void cppgc__heap__DELETE(v8::CppHeap* self) { delete self; } void cppgc__heap__DELETE(v8::CppHeap* self) { delete self; }
void cppgc__heap__enable_detached_garbage_collections_for_testing(v8::CppHeap* heap) { void cppgc__heap__enable_detached_garbage_collections_for_testing(
v8::CppHeap* heap) {
heap->EnableDetachedGarbageCollectionsForTesting(); heap->EnableDetachedGarbageCollectionsForTesting();
} }
void cppgc__heap__collect_garbage_for_testing(v8::CppHeap* heap, cppgc::EmbedderStackState stack_state) { void cppgc__heap__collect_garbage_for_testing(
v8::CppHeap* heap, cppgc::EmbedderStackState stack_state) {
heap->CollectGarbageForTesting(stack_state); heap->CollectGarbageForTesting(stack_state);
} }
RustObj* cppgc__make_garbage_collectable(v8::CppHeap* heap, void* obj, RustTraceFn trace, RustDestroyFn destroy) { RustObj* cppgc__make_garbage_collectable(v8::CppHeap* heap, void* obj,
return cppgc::MakeGarbageCollected<RustObj>(heap->GetAllocationHandle(), obj, trace, destroy); RustTraceFn trace,
RustDestroyFn destroy) {
return cppgc::MakeGarbageCollected<RustObj>(heap->GetAllocationHandle(), obj,
trace, destroy);
} }
void cppgc__visitor__trace(cppgc::Visitor* visitor, RustObj* member) { void cppgc__visitor__trace(cppgc::Visitor* visitor, RustObj* member) {

View file

@ -548,7 +548,7 @@ impl Isolate {
// Byte offset inside `Isolate` where the isolate data slots are stored. This // Byte offset inside `Isolate` where the isolate data slots are stored. This
// should be the same as the value of `kIsolateEmbedderDataOffset` which is // should be the same as the value of `kIsolateEmbedderDataOffset` which is
// defined in `v8-internal.h`. // defined in `v8-internal.h`.
const EMBEDDER_DATA_OFFSET: usize = size_of::<[*const (); 67]>(); const EMBEDDER_DATA_OFFSET: usize = size_of::<[*const (); 65]>();
// Isolate data slots used internally by rusty_v8. // Isolate data slots used internally by rusty_v8.
const ANNEX_SLOT: u32 = 0; const ANNEX_SLOT: u32 = 0;

View file

@ -1,5 +1,6 @@
use crate::array_buffer; use crate::array_buffer;
use crate::array_buffer::Allocator as ArrayBufferAllocator; use crate::array_buffer::Allocator as ArrayBufferAllocator;
use crate::cppgc::Heap;
use crate::support::char; use crate::support::char;
use crate::support::int; use crate::support::int;
use crate::support::intptr_t; use crate::support::intptr_t;
@ -212,10 +213,9 @@ pub(crate) mod raw {
pub only_terminate_in_safe_scope: bool, pub only_terminate_in_safe_scope: bool,
pub embedder_wrapper_type_index: int, pub embedder_wrapper_type_index: int,
pub embedder_wrapper_object_index: int, pub embedder_wrapper_object_index: int,
// NOTE(bartlomieju): this field is deprecated in V8 API. _fatal_error_handler: *const Opaque, // FatalErrorCallback
// This is an std::vector<std::string>. It's usually no bigger _oom_error_handler: *const Opaque, // OOMErrorCallback
// than three or four words but let's take a generous upper bound. pub cpp_heap: *const Heap,
pub supported_import_assertions: [usize; 8],
} }
extern "C" { extern "C" {

View file

@ -327,7 +327,7 @@ impl<'s> HandleScope<'s> {
unsafe { unsafe {
let sd = data::ScopeData::get_mut(self); let sd = data::ScopeData::get_mut(self);
raw::v8__Context__SetContinuationPreservedEmbedderData( raw::v8__Context__SetContinuationPreservedEmbedderData(
sd.get_current_context(), sd.get_isolate_ptr(),
&*data, &*data,
); );
} }
@ -341,7 +341,7 @@ impl<'s> HandleScope<'s> {
self self
.cast_local(|sd| { .cast_local(|sd| {
raw::v8__Context__GetContinuationPreservedEmbedderData( raw::v8__Context__GetContinuationPreservedEmbedderData(
sd.get_current_context(), sd.get_isolate_ptr(),
) )
}) })
.unwrap() .unwrap()
@ -2100,11 +2100,11 @@ mod raw {
resolve_hook: *const Function, resolve_hook: *const Function,
); );
pub(super) fn v8__Context__SetContinuationPreservedEmbedderData( pub(super) fn v8__Context__SetContinuationPreservedEmbedderData(
this: *const Context, this: *mut Isolate,
value: *const Value, value: *const Value,
); );
pub(super) fn v8__Context__GetContinuationPreservedEmbedderData( pub(super) fn v8__Context__GetContinuationPreservedEmbedderData(
this: *const Context, this: *mut Isolate,
) -> *const Value; ) -> *const Value;
pub(super) fn v8__HandleScope__CONSTRUCT( pub(super) fn v8__HandleScope__CONSTRUCT(

View file

@ -4,7 +4,6 @@ use std::ptr::null;
use crate::Context; use crate::Context;
use crate::HandleScope; use crate::HandleScope;
use crate::Isolate;
use crate::Local; use crate::Local;
use crate::Script; use crate::Script;
use crate::String; use crate::String;
@ -31,7 +30,6 @@ extern "C" {
) -> *const Value; ) -> *const Value;
fn v8__ScriptOrigin__CONSTRUCT( fn v8__ScriptOrigin__CONSTRUCT(
isolate: *mut Isolate,
buf: *mut MaybeUninit<ScriptOrigin>, buf: *mut MaybeUninit<ScriptOrigin>,
resource_name: *const Value, resource_name: *const Value,
resource_line_offset: i32, resource_line_offset: i32,
@ -103,7 +101,8 @@ impl<'s> ScriptOrigin<'s> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
#[inline(always)] #[inline(always)]
pub fn new( pub fn new(
scope: &mut HandleScope<'s, ()>, // TODO(littledivy): remove
_scope: &mut HandleScope<'s, ()>,
resource_name: Local<'s, Value>, resource_name: Local<'s, Value>,
resource_line_offset: i32, resource_line_offset: i32,
resource_column_offset: i32, resource_column_offset: i32,
@ -117,7 +116,6 @@ impl<'s> ScriptOrigin<'s> {
unsafe { unsafe {
let mut buf = std::mem::MaybeUninit::<ScriptOrigin>::uninit(); let mut buf = std::mem::MaybeUninit::<ScriptOrigin>::uninit();
v8__ScriptOrigin__CONSTRUCT( v8__ScriptOrigin__CONSTRUCT(
scope.get_isolate_ptr(),
&mut buf, &mut buf,
&*resource_name, &*resource_name,
resource_line_offset, resource_line_offset,

View file

@ -74,6 +74,7 @@ pub struct Source {
_consume_cache_task: usize, _consume_cache_task: usize,
_compile_hint_callback: usize, _compile_hint_callback: usize,
_compile_hint_callback_data: usize, _compile_hint_callback_data: usize,
_compilation_details: [usize; 3],
} }
/// Compilation data that the embedder can cache and pass back to speed up future /// Compilation data that the embedder can cache and pass back to speed up future

View file

@ -3,9 +3,7 @@ use crate::isolate_create_params::raw;
use crate::scope::data::ScopeData; use crate::scope::data::ScopeData;
use crate::support::char; use crate::support::char;
use crate::support::int; use crate::support::int;
use crate::support::intptr_t;
use crate::support::Allocated; use crate::support::Allocated;
use crate::support::Allocation;
use crate::Context; use crate::Context;
use crate::Data; use crate::Data;
use crate::Isolate; use crate::Isolate;
@ -16,13 +14,11 @@ use std::borrow::Borrow;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::ops::Deref; use std::ops::Deref;
use std::ptr::null;
extern "C" { extern "C" {
fn v8__SnapshotCreator__CONSTRUCT( fn v8__SnapshotCreator__CONSTRUCT(
buf: *mut MaybeUninit<SnapshotCreator>, buf: *mut MaybeUninit<SnapshotCreator>,
external_references: *const intptr_t, params: *const raw::CreateParams,
existing_blob: *const raw::StartupData,
); );
fn v8__SnapshotCreator__DESTRUCT(this: *mut SnapshotCreator); fn v8__SnapshotCreator__DESTRUCT(this: *mut SnapshotCreator);
fn v8__SnapshotCreator__GetIsolate( fn v8__SnapshotCreator__GetIsolate(
@ -131,30 +127,18 @@ impl SnapshotCreator {
existing_snapshot_blob: Option<impl Allocated<[u8]>>, existing_snapshot_blob: Option<impl Allocated<[u8]>>,
) -> OwnedIsolate { ) -> OwnedIsolate {
let mut snapshot_creator: MaybeUninit<Self> = MaybeUninit::uninit(); let mut snapshot_creator: MaybeUninit<Self> = MaybeUninit::uninit();
let external_references_ptr = if let Some(er) = external_references {
er.as_ptr()
} else {
std::ptr::null()
};
let snapshot_blob_ptr; let mut params = crate::CreateParams::default();
let snapshot_allocations; if let Some(external_refs) = external_references {
if let Some(snapshot_blob) = existing_snapshot_blob { params = params.external_references(&**external_refs);
let data = Allocation::of(snapshot_blob);
let header = Allocation::of(raw::StartupData::boxed_header(&data));
snapshot_blob_ptr = &*header as *const _;
snapshot_allocations = Some((header, data));
} else {
snapshot_blob_ptr = null();
snapshot_allocations = None;
} }
if let Some(snapshot_blob) = existing_snapshot_blob {
params = params.snapshot_blob(snapshot_blob);
}
let (raw_create_params, create_param_allocations) = params.finalize();
let snapshot_creator = unsafe { let snapshot_creator = unsafe {
v8__SnapshotCreator__CONSTRUCT( v8__SnapshotCreator__CONSTRUCT(&mut snapshot_creator, &raw_create_params);
&mut snapshot_creator,
external_references_ptr,
snapshot_blob_ptr,
);
snapshot_creator.assume_init() snapshot_creator.assume_init()
}; };
@ -162,7 +146,7 @@ impl SnapshotCreator {
unsafe { v8__SnapshotCreator__GetIsolate(&snapshot_creator) }; unsafe { v8__SnapshotCreator__GetIsolate(&snapshot_creator) };
let mut owned_isolate = OwnedIsolate::new(isolate_ptr); let mut owned_isolate = OwnedIsolate::new(isolate_ptr);
ScopeData::new_root(&mut owned_isolate); ScopeData::new_root(&mut owned_isolate);
owned_isolate.create_annex(Box::new(snapshot_allocations)); owned_isolate.create_annex(create_param_allocations);
owned_isolate.set_snapshot_creator(snapshot_creator); owned_isolate.set_snapshot_creator(snapshot_creator);
owned_isolate owned_isolate
} }

View file

@ -270,16 +270,9 @@ pub trait ValueSerializerImpl {
fn get_shared_array_buffer_id<'s>( fn get_shared_array_buffer_id<'s>(
&mut self, &mut self,
scope: &mut HandleScope<'s>, _scope: &mut HandleScope<'s>,
_shared_array_buffer: Local<'s, SharedArrayBuffer>, _shared_array_buffer: Local<'s, SharedArrayBuffer>,
) -> Option<u32> { ) -> Option<u32> {
let msg = String::new(
scope,
"Deno serializer: get_shared_array_buffer_id not implemented",
)
.unwrap();
let exc = Exception::error(scope, msg);
scope.throw_exception(exc);
None None
} }

View file

@ -1117,7 +1117,9 @@ fn try_catch() {
assert!(tc2.has_caught()); assert!(tc2.has_caught());
assert!(tc2.rethrow().is_some()); assert!(tc2.rethrow().is_some());
tc2.reset(); tc2.reset();
assert!(!tc2.has_caught()); // Reset does not clear exception on rethrow.
// https://chromium-review.googlesource.com/c/v8/v8/+/5050065
assert!(tc2.has_caught());
} }
assert!(tc1.has_caught()); assert!(tc1.has_caught());
}; };
@ -2538,7 +2540,6 @@ fn object_template_set_named_property_handler() {
assert!(eval(scope, "'panicOnGet' in obj") assert!(eval(scope, "'panicOnGet' in obj")
.unwrap() .unwrap()
.boolean_value(scope)); .boolean_value(scope));
assert!(eval(scope, "obj.panicOnGet").unwrap().is_string());
// Test `v8::NamedPropertyHandlerConfiguration::*_raw()` methods // Test `v8::NamedPropertyHandlerConfiguration::*_raw()` methods
{ {
@ -2566,7 +2567,6 @@ fn object_template_set_named_property_handler() {
assert!(eval(scope, "'panicOnGet' in obj") assert!(eval(scope, "'panicOnGet' in obj")
.unwrap() .unwrap()
.boolean_value(scope)); .boolean_value(scope));
assert!(eval(scope, "obj.panicOnGet").unwrap().is_string());
} }
} }
} }
@ -8083,6 +8083,7 @@ impl v8::ValueSerializerImpl for Custom2Value {
scope: &mut v8::HandleScope<'s>, scope: &mut v8::HandleScope<'s>,
message: v8::Local<'s, v8::String>, message: v8::Local<'s, v8::String>,
) { ) {
let scope = &mut v8::TryCatch::new(scope);
let error = v8::Exception::error(scope, message); let error = v8::Exception::error(scope, message);
scope.throw_exception(error); scope.throw_exception(error);
} }

View file

@ -72,7 +72,7 @@ fn cppgc_object_wrap() {
} }
{ {
let isolate = &mut v8::Isolate::new(Default::default()); let isolate = &mut v8::Isolate::new(v8::CreateParams::default());
// Create a managed heap. // Create a managed heap.
let heap = v8::cppgc::Heap::create( let heap = v8::cppgc::Heap::create(
guard.platform.clone(), guard.platform.clone(),
@ -82,7 +82,6 @@ fn cppgc_object_wrap() {
DEFAULT_CPP_GC_EMBEDDER_ID, DEFAULT_CPP_GC_EMBEDDER_ID,
)), )),
); );
isolate.attach_cpp_heap(&heap); isolate.attach_cpp_heap(&heap);
let handle_scope = &mut v8::HandleScope::new(isolate); let handle_scope = &mut v8::HandleScope::new(isolate);

2
v8

@ -1 +1 @@
Subproject commit c6c15e7d902677c43e096fe1fcf841e79555c714 Subproject commit 5fec337f209fd2db7519cfe398e10b3aa2e587ab