Skip to content

Commit 50b1ba6

Browse files
committed
some small progress
1 parent f78c9bf commit 50b1ba6

File tree

1 file changed

+53
-55
lines changed

1 file changed

+53
-55
lines changed

core/cppgc.rs

Lines changed: 53 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,7 @@ 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
453453
}
454454
}
455455

@@ -556,54 +556,52 @@ impl FunctionTemplateData {
556556
}
557557
}
558558

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

0 commit comments

Comments
 (0)