From 70a07c050b9b28cd58fb37699025b768c54fd251 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sat, 6 Jan 2024 23:35:15 +0530 Subject: [PATCH] `isolate->GetCppHeap()` can return nullptr if no heap is attached (#1385) Changes `v8::Isolate::get_cpp_heap` to return a `Option<&Heap>`. --- examples/cppgc-object.rs | 2 +- src/isolate.rs | 4 ++-- tests/test_cppgc.rs | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/cppgc-object.rs b/examples/cppgc-object.rs index 25b529a3..47ccf856 100644 --- a/examples/cppgc-object.rs +++ b/examples/cppgc-object.rs @@ -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, diff --git a/src/isolate.rs b/src/isolate.rs index a2ce0f54..7186e0fa 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -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)] diff --git a/tests/test_cppgc.rs b/tests/test_cppgc.rs index f453d51b..2ff7442c 100644 --- a/tests/test_cppgc.rs +++ b/tests/test_cppgc.rs @@ -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,