isolate->GetCppHeap() can return nullptr if no heap is attached (#1385)

Changes `v8::Isolate::get_cpp_heap` to return a `Option<&Heap>`.
This commit is contained in:
Divy Srivastava 2024-01-06 23:35:15 +05:30 committed by GitHub
parent e4cdf58665
commit 70a07c050b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -63,7 +63,7 @@ fn main() {
let obj = templ.new_instance(scope).unwrap();
let member = v8::cppgc::make_garbage_collected(
scope.get_cpp_heap(),
scope.get_cpp_heap().unwrap(),
Box::new(Wrappable {
trace_count: Cell::new(0),
id,

View File

@ -1100,8 +1100,8 @@ impl Isolate {
}
}
pub fn get_cpp_heap(&mut self) -> &Heap {
unsafe { &*v8__Isolate__GetCppHeap(self) }
pub fn get_cpp_heap(&mut self) -> Option<&Heap> {
unsafe { v8__Isolate__GetCppHeap(self).as_ref() }
}
#[inline(always)]

View File

@ -59,8 +59,10 @@ fn cppgc_object_wrap() {
let obj = templ.new_instance(scope).unwrap();
let member =
v8::cppgc::make_garbage_collected(scope.get_cpp_heap(), Box::new(Wrap));
let member = v8::cppgc::make_garbage_collected(
scope.get_cpp_heap().unwrap(),
Box::new(Wrap),
);
obj.set_aligned_pointer_in_internal_field(
0,