-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cppgc): add get and unwrap utlities to SameObject
#1059
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,10 +182,12 @@ impl FunctionTemplateData { | |
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct SameObject<T: GarbageCollected + 'static> { | ||
cell: std::cell::OnceCell<v8::Global<v8::Object>>, | ||
_phantom_data: std::marker::PhantomData<T>, | ||
} | ||
|
||
impl<T: GarbageCollected + 'static> SameObject<T> { | ||
#[allow(clippy::new_without_default)] | ||
pub fn new() -> Self { | ||
|
@@ -212,4 +214,19 @@ impl<T: GarbageCollected + 'static> SameObject<T> { | |
}) | ||
.clone() | ||
} | ||
|
||
pub fn set( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when is this useful? sameobject should always just be set once and forget, any reason There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense |
||
&self, | ||
scope: &mut v8::HandleScope, | ||
value: T, | ||
) -> Result<(), v8::Global<v8::Object>> { | ||
let obj = make_cppgc_object(scope, value); | ||
self.cell.set(v8::Global::new(scope, obj)) | ||
} | ||
|
||
pub fn try_unwrap(&self, scope: &mut v8::HandleScope) -> Option<Ptr<T>> { | ||
let obj = self.cell.get()?; | ||
let val = v8::Local::new(scope, obj); | ||
try_unwrap_cppgc_object(scope, val.cast()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the debug output is probably quite useless; any specific need for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent is that this would allow
#[derive(Debug)]
to be added toDOMQuadInner
, but I don't have a particularly strong opinion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see, that makes sense!