Skip to content

Commit 0f1eb76

Browse files
bartlomiejudevsnek
authored andcommitted
some small progress
1 parent f78c9bf commit 0f1eb76

File tree

1 file changed

+59
-55
lines changed

1 file changed

+59
-55
lines changed

core/cppgc.rs

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub fn wrap_object3<
352352
}
353353

354354
pub struct UnsafePtr<T: GarbageCollected> {
355-
inner: v8::cppgc::Ptr<CppGcObject<T>>,
355+
inner: v8::cppgc::UnsafePtr<CppGcObject<T>>,
356356
root: Option<v8::cppgc::Persistent<CppGcObject<T>>>,
357357
}
358358

@@ -377,7 +377,7 @@ impl<T: GarbageCollected> UnsafePtr<T> {
377377
impl<T: GarbageCollected> std::ops::Deref for UnsafePtr<T> {
378378
type Target = T;
379379
fn deref(&self) -> &T {
380-
&self.inner.member
380+
&unsafe { self.inner.as_ref() }.member
381381
}
382382
}
383383

@@ -415,7 +415,7 @@ pub struct Ref<T: GarbageCollected> {
415415
impl<T: GarbageCollected> std::ops::Deref for Ref<T> {
416416
type Target = T;
417417
fn deref(&self) -> &T {
418-
&self.inner.borrow().unwrap().member
418+
&self.inner.get().unwrap().member
419419
}
420420
}
421421

@@ -449,7 +449,13 @@ impl<T: GarbageCollected> From<Ref<T>> for Member<T> {
449449
impl<T: GarbageCollected> std::ops::Deref for Member<T> {
450450
type Target = T;
451451
fn deref(&self) -> &T {
452-
&self.inner.borrow().unwrap().member
452+
&unsafe { self.inner.get().unwrap() }.member
453+
}
454+
}
455+
456+
impl<T: GarbageCollected> v8::cppgc::Traced for Member<T> {
457+
fn trace(&self, visitor: &mut v8::cppgc::Visitor) {
458+
visitor.trace(&self.inner);
453459
}
454460
}
455461

@@ -556,54 +562,52 @@ impl FunctionTemplateData {
556562
}
557563
}
558564

559-
#[derive(Debug)]
560-
pub struct SameObject<T: GarbageCollected + 'static> {
561-
cell: std::cell::OnceCell<v8::Global<v8::Object>>,
562-
_phantom_data: std::marker::PhantomData<T>,
563-
}
564-
565-
impl<T: GarbageCollected + 'static> SameObject<T> {
566-
#[allow(clippy::new_without_default)]
567-
pub fn new() -> Self {
568-
Self {
569-
cell: Default::default(),
570-
_phantom_data: Default::default(),
571-
}
572-
}
573-
574-
pub fn get<F>(
575-
&self,
576-
scope: &mut v8::HandleScope,
577-
f: F,
578-
) -> v8::Global<v8::Object>
579-
where
580-
F: FnOnce(&mut v8::HandleScope) -> T,
581-
{
582-
self
583-
.cell
584-
.get_or_init(|| {
585-
let v = f(scope);
586-
let obj = make_cppgc_object(scope, v);
587-
v8::Global::new(scope, obj)
588-
})
589-
.clone()
590-
}
591-
592-
pub fn set(
593-
&self,
594-
scope: &mut v8::HandleScope,
595-
value: T,
596-
) -> Result<(), v8::Global<v8::Object>> {
597-
let obj = make_cppgc_object(scope, value);
598-
self.cell.set(v8::Global::new(scope, obj))
599-
}
600-
601-
pub fn try_unwrap(
602-
&self,
603-
scope: &mut v8::HandleScope,
604-
) -> Option<UnsafePtr<T>> {
605-
let obj = self.cell.get()?;
606-
let val = v8::Local::new(scope, obj);
607-
try_unwrap_cppgc_object(scope, val.cast())
608-
}
609-
}
565+
// pub struct SameObject<T: GarbageCollected + 'static> {
566+
// cell: std::cell::OnceCell<GcCell<v8::Global<v8::Object>>>,
567+
// _phantom_data: std::marker::PhantomData<T>,
568+
// }
569+
570+
// impl<T: GarbageCollected + 'static> SameObject<T> {
571+
// #[allow(clippy::new_without_default)]
572+
// pub fn new() -> Self {
573+
// Self {
574+
// cell: Default::default(),
575+
// _phantom_data: Default::default(),
576+
// }
577+
// }
578+
579+
// pub fn get<F>(
580+
// &self,
581+
// scope: &mut v8::HandleScope,
582+
// f: F,
583+
// ) -> v8::Global<v8::Object>
584+
// where
585+
// F: FnOnce(&mut v8::HandleScope) -> T,
586+
// {
587+
// let cell = self.cell.get_or_init(|| {
588+
// let v = f(scope);
589+
// let obj = make_cppgc_object(scope, v);
590+
// GcCell::new(v8::Global::new(scope, obj))
591+
// });
592+
// cell.get(scope).clone()
593+
// }
594+
595+
// pub fn set(
596+
// &self,
597+
// scope: &mut v8::HandleScope,
598+
// value: T,
599+
// ) -> Result<(), v8::Global<v8::Object>> {
600+
// let obj = make_cppgc_object(scope, value);
601+
// let global = v8::Global::new(scope, obj);
602+
// self.cell.set(GcCell::new(global))
603+
// }
604+
605+
// pub fn try_unwrap(
606+
// &self,
607+
// scope: &mut v8::HandleScope,
608+
// ) -> Option<UnsafePtr<T>> {
609+
// let obj = self.cell.get()?;
610+
// let val = obj.get(scope);
611+
// try_unwrap_cppgc_object(scope, val.cast())
612+
// }
613+
// }

0 commit comments

Comments
 (0)